Commit 2838f65
committed
feat(morph): support funnel / pyramid / gauge in cross-type morphs
Adds the three first-class chart-type aliases to the morph engine so any
chart can morph to/from a funnel, pyramid, or gauge in addition to the
existing bar / pie / donut / radialBar / polarArea pairs.
Engine
- MorphTypeChange: `funnel` + `pyramid` added to BAR_FAMILY, `gauge`
added to RADIAL_FAMILY. `_captureFromDOM` treats `fromType === 'gauge'`
as a radialBar-shaped source (same selector, same arc-to-segment
conversion).
- UpdateHelpers: `fromType` is now `w.config.chart.requestedType ||
w.config.chart.type` so a chart that *started* as an alias keeps its
user-facing identity for morph detection — without this, a chart
rendered as funnel would internally report `bar` and any subsequent
morph would be incorrectly classified as same-family.
- Radial.js: `morphFromFilled` check expanded to recognize funnel and
pyramid sources (they're Bar.js variants and render as fills, so the
donut-segment intermediate target is needed for radialBar destinations).
Update-path crash fix
- UpdateHelpers: `ch.config.normalizeAliasedChartType(options)` runs
before the config merge. On initial render this happens inside
`Config.init()`, but the update path constructs Config directly and
skips init() — without normalize, an `updateOptions({chart:
{type:'funnel'}})` would merge an unrecognized chart.type into
w.config and crash in `Core.plotChartType`'s switch fallthrough
(`line.draw` on a null `line` when `needsLine` was false).
Leaving-alias residue cleanup
- UpdateHelpers: when transitioning out of an alias state (the previous
render was funnel/pyramid/gauge and the new request is a non-alias
type), `options.chart.requestedType` is explicitly set to the new type
and `options.plotOptions.bar.isFunnel` is cleared (when leaving funnel
or pyramid). Without this, the second cross-type morph in/out of
funnel/pyramid failed because the previous alias's `requestedType` and
`isFunnel: true` lingered on w.config and would be preserved through
the merge.
Why this lives in UpdateHelpers and not Config.normalizeAliasedChartType:
normalize runs on initial chart creation too, where the legacy
contract `chart.type: 'bar' + plotOptions.bar.isFunnel: true` must
leave `requestedType` undefined and `isFunnel: true` preserved
verbatim. Only the update path has the context to know we're
transitioning between modes.
Pyramid sort
- Config._applyPyramidSort: pyramid now sorts series data ascending
(smallest value at top, largest at bottom) so the rendered shape is
actually a pyramid regardless of input order. The same permutation is
applied to xaxis.categories and the top-level labels array so legend
and tooltips stay aligned. Sort is non-mutating — the user's input
arrays are deep-cloned via Array.prototype.map before being placed on
`opts.series` / `opts.xaxis.categories` / `opts.labels`.
Pre-existing `defaults.pyramid()` was a stub that just returned
`defaults.funnel()`; the comment claiming "ordering is handled in
Config" was aspirational. This adds the missing piece.
Demo
- samples chart-type-morph: Funnel + Pyramid buttons added.
`plotOptions.funnel: { shape: 'trapezoid', lastShape: 'taper' }` so
the funnel renders in trapezoid mode. Bar-height slider (30–100%)
added beneath the speed slider, controlling
`plotOptions.bar.barHeight` live and threading through type-switch
transitions so horizontal-bar / funnel / pyramid all honor the chosen
thickness on subsequent morphs.
Tests
- first-class-types.spec.js: two new cases for pyramid sort —
verifies sorted internal config (series / xaxis.categories) AND that
the user's original arrays are not mutated; second case proves the
same for top-level labels.
- morph-type-change.spec.js: new pair / shape rules for funnel ↔
pie/donut/radialBar/polarArea, within-family bar ↔ funnel ↔ pyramid,
and gauge ↔ bar / pie / radialBar.
1647/1647 unit tests pass.1 parent 2583060 commit 2838f65
8 files changed
Lines changed: 276 additions & 10 deletions
File tree
- samples
- source/misc
- vanilla-js/misc
- src
- charts
- modules
- helpers
- settings
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
87 | 89 | | |
88 | 90 | | |
89 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
90 | 98 | | |
91 | 99 | | |
92 | 100 | | |
| |||
119 | 127 | | |
120 | 128 | | |
121 | 129 | | |
| 130 | + | |
122 | 131 | | |
123 | 132 | | |
124 | 133 | | |
125 | 134 | | |
126 | 135 | | |
127 | 136 | | |
128 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
129 | 141 | | |
130 | 142 | | |
131 | 143 | | |
| |||
161 | 173 | | |
162 | 174 | | |
163 | 175 | | |
| 176 | + | |
164 | 177 | | |
165 | 178 | | |
166 | | - | |
| 179 | + | |
167 | 180 | | |
168 | 181 | | |
169 | 182 | | |
| |||
191 | 204 | | |
192 | 205 | | |
193 | 206 | | |
194 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
195 | 213 | | |
196 | 214 | | |
197 | 215 | | |
| |||
217 | 235 | | |
218 | 236 | | |
219 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
220 | 251 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| |||
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
116 | 124 | | |
117 | 125 | | |
118 | 126 | | |
| |||
145 | 153 | | |
146 | 154 | | |
147 | 155 | | |
| 156 | + | |
148 | 157 | | |
149 | 158 | | |
150 | 159 | | |
151 | 160 | | |
152 | 161 | | |
153 | 162 | | |
154 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
155 | 167 | | |
156 | 168 | | |
157 | 169 | | |
| |||
184 | 196 | | |
185 | 197 | | |
186 | 198 | | |
| 199 | + | |
187 | 200 | | |
188 | 201 | | |
189 | | - | |
| 202 | + | |
190 | 203 | | |
191 | 204 | | |
192 | 205 | | |
| |||
215 | 228 | | |
216 | 229 | | |
217 | 230 | | |
218 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
219 | 237 | | |
220 | 238 | | |
221 | 239 | | |
| |||
241 | 259 | | |
242 | 260 | | |
243 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
244 | 274 | | |
245 | 275 | | |
246 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| 434 | + | |
| 435 | + | |
434 | 436 | | |
435 | 437 | | |
436 | 438 | | |
| 439 | + | |
| 440 | + | |
437 | 441 | | |
438 | 442 | | |
439 | 443 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| |||
180 | 185 | | |
181 | 186 | | |
182 | 187 | | |
183 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
184 | 191 | | |
185 | 192 | | |
186 | 193 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
64 | 72 | | |
65 | 73 | | |
66 | | - | |
| 74 | + | |
| 75 | + | |
67 | 76 | | |
68 | | - | |
| 77 | + | |
69 | 78 | | |
70 | 79 | | |
71 | 80 | | |
| |||
74 | 83 | | |
75 | 84 | | |
76 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
77 | 122 | | |
78 | 123 | | |
79 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
161 | 164 | | |
162 | 165 | | |
163 | 166 | | |
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
167 | 238 | | |
168 | 239 | | |
169 | 240 | | |
| |||
0 commit comments