Skip to content

Commit 4fcf1ac

Browse files
authored
Merge pull request #114 from simzer/main
Presets finalized
2 parents 3fdfc97 + bfb7864 commit 4fcf1ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1770
-31
lines changed

src/apps/weblib/js-api/presets.js

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export default class Presets {
127127
y: "y",
128128
color: "color",
129129
size: "size",
130+
noop: "dividedBy",
130131
},
131132
geometry: "circle",
132133
},
@@ -145,7 +146,7 @@ export default class Presets {
145146
},
146147
geometry: "area",
147148
},
148-
precentageArea: {
149+
percentageArea: {
149150
channels: {
150151
x: "x",
151152
y: ["y", "stackedBy"],
@@ -219,8 +220,9 @@ export default class Presets {
219220
},
220221
pie: {
221222
channels: {
222-
x: ["angle", "stackedBy"],
223-
color: "stackedBy",
223+
x: ["angle", "by"],
224+
color: "by",
225+
label: "angle",
224226
},
225227
coordSystem: "polar",
226228
},
@@ -241,47 +243,39 @@ export default class Presets {
241243
},
242244
variableRadiusPie: {
243245
channels: {
244-
x: ["angle", "stackedBy"],
246+
x: ["angle", "by"],
245247
y: "radius",
246-
color: "stackedBy",
247-
},
248-
coordSystem: "polar",
249-
},
250-
polarArea: {
251-
channels: {
252-
x: "angle",
253-
y: ["radius", "stackedBy"],
254-
color: "stackedBy",
248+
color: "by",
255249
},
256250
coordSystem: "polar",
257-
geometry: "area",
258251
},
259252
radialBar: {
260253
channels: {
261254
x: "angle",
262-
y: "radius",
255+
y: { set: "radius", range: { min: "-50%" } },
263256
},
264257
coordSystem: "polar",
265258
},
266259
radialStackedBar: {
267260
channels: {
268261
x: ["angle", "stackedBy"],
269-
y: "radius",
262+
y: { set: "radius", range: { min: "-50%" } },
270263
color: "stackedBy",
271264
},
272265
coordSystem: "polar",
273266
},
274267
donut: {
275268
channels: {
276269
x: ["angle", "stackedBy"],
270+
y: { range: { min: "-200%", max: "100%" } },
277271
color: "stackedBy",
278272
},
279273
coordSystem: "polar",
280274
},
281275
nestedDonut: {
282276
channels: {
283277
x: ["angle", "stackedBy"],
284-
y: "groupedBy",
278+
y: { set: "radius", range: { min: "-50%" } },
285279
color: "stackedBy",
286280
label: "angle",
287281
},
@@ -295,6 +289,7 @@ export default class Presets {
295289
noop: "dividedBy",
296290
},
297291
coordSystem: "polar",
292+
geometry: "circle",
298293
},
299294
polarLine: {
300295
channels: {
@@ -314,10 +309,10 @@ export default class Presets {
314309
},
315310
stackedTreemap: {
316311
channels: {
317-
size: ["siye", "lightness"],
312+
size: ["size", "dividedBy"],
318313
color: "color",
319-
label: "lightness",
320-
lightness: "lightness",
314+
label: "dividedBy",
315+
lightness: "size",
321316
},
322317
},
323318
heatmap: {
@@ -345,12 +340,26 @@ export default class Presets {
345340
};
346341

347342
for (let key in this._presetConfigs) {
343+
this._initPresetConfigChannels(this._presetConfigs[key].channels);
348344
this[key] = (config) => {
349345
return this._buildPresetConfig(key, config);
350346
};
351347
}
352348
}
353349

350+
_initPresetConfigChannels(channels) {
351+
for (let channel in channels) {
352+
if (
353+
typeof channels[channel] !== "object" ||
354+
Array.isArray(channels[channel])
355+
) {
356+
channels[channel] = {
357+
set: channels[channel],
358+
};
359+
}
360+
}
361+
}
362+
354363
_nullConfig() {
355364
return {
356365
align: "none",
@@ -381,23 +390,34 @@ export default class Presets {
381390
}
382391

383392
_getChannelCopy(channel) {
384-
if (Array.isArray(channel)) {
385-
return channel.map((v) => v);
386-
} else {
387-
return [channel];
388-
}
393+
if (channel === null) return null;
394+
if (channel === undefined) return null;
395+
if (Array.isArray(channel)) channel.map((v) => v);
396+
return [channel];
389397
}
390398

391399
_fillChannels(presetConfig, config) {
392400
if (!config) return;
393401
let channels = presetConfig.channels;
394402
for (let channel in channels) {
395-
if (typeof channels[channel] === "string") {
396-
channels[channel] = this._getChannelCopy(config[channels[channel]]);
397-
} else if (Array.isArray(channels[channel])) {
398-
channels[channel] = channels[channel]
399-
.map((v) => this._getChannelCopy(config[v]))
400-
.flat();
403+
if (channels[channel] === null) {
404+
continue;
405+
} else if (typeof channels[channel].set === "string") {
406+
channels[channel].set = this._getChannelCopy(
407+
config[channels[channel].set]
408+
);
409+
} else if (Array.isArray(channels[channel].set)) {
410+
let newChannel = [];
411+
for (let i = 0; i < channels[channel].set.length; i++) {
412+
let channelConfig = this._getChannelCopy(
413+
config[channels[channel].set[i]]
414+
);
415+
if (channelConfig !== null) {
416+
newChannel.push(channelConfig);
417+
}
418+
}
419+
channels[channel].set =
420+
newChannel.length > 0 ? newChannel.flat() : null;
401421
}
402422
}
403423
}

test/integration/test_cases/test_cases.json

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,211 @@
736736
"15fc180"
737737
]
738738
},
739+
"web_content/preset/02_C_R_column": {
740+
"refs": [
741+
"ede9506"
742+
]
743+
},
744+
"web_content/preset/03_C_R_grouped_column_negative": {
745+
"refs": [
746+
"400b8ff"
747+
]
748+
},
749+
"web_content/preset/04_C_R_stacked_column": {
750+
"refs": [
751+
"4d80b7e"
752+
]
753+
},
754+
"web_content/preset/05_C_R_splitted_column": {
755+
"refs": [
756+
"4469c14"
757+
]
758+
},
759+
"web_content/preset/06_C_R_percentage_column": {
760+
"refs": [
761+
"f393af2"
762+
]
763+
},
764+
"web_content/preset/08_C_R_waterfall": {
765+
"refs": [
766+
"54a0d38"
767+
]
768+
},
769+
"web_content/preset/09_C_R_stacked_mekko": {
770+
"refs": [
771+
"e0c83e6"
772+
]
773+
},
774+
"web_content/preset/10_C_R_marimekko": {
775+
"refs": [
776+
"6bb6e84"
777+
]
778+
},
779+
"web_content/preset/13_C_R_bar_negative": {
780+
"refs": [
781+
"15761d9"
782+
]
783+
},
784+
"web_content/preset/14_C_R_grouped_bar_negative": {
785+
"refs": [
786+
"415ba82"
787+
]
788+
},
789+
"web_content/preset/15_C_R_stacked_bar": {
790+
"refs": [
791+
"8980717"
792+
]
793+
},
794+
"web_content/preset/16_C_R_splitted_bar": {
795+
"refs": [
796+
"f84936b"
797+
]
798+
},
799+
"web_content/preset/17_C_R_percentage_bar": {
800+
"refs": [
801+
"e14b2ab"
802+
]
803+
},
804+
"web_content/preset/20_C_C_lollipop chart": {
805+
"refs": [
806+
"3fbff62"
807+
]
808+
},
809+
"web_content/preset/22_C_C_scatter": {
810+
"refs": [
811+
"7186aaf"
812+
]
813+
},
814+
"web_content/preset/24_C_C_bubbleplot": {
815+
"refs": [
816+
"7c51dd9"
817+
]
818+
},
819+
"web_content/preset/27_C_A_area_negative": {
820+
"refs": [
821+
"0daef00"
822+
]
823+
},
824+
"web_content/preset/28_C_A_stacked_area": {
825+
"refs": [
826+
"6501de8"
827+
]
828+
},
829+
"web_content/preset/29_C_A_percentage_area": {
830+
"refs": [
831+
"4e49566"
832+
]
833+
},
834+
"web_content/preset/31_C_A_splitted_area": {
835+
"refs": [
836+
"fb68c11"
837+
]
838+
},
839+
"web_content/preset/32_C_A_stream": {
840+
"refs": [
841+
"245c5e6"
842+
]
843+
},
844+
"web_content/preset/33_C_A_vertical_stream": {
845+
"refs": [
846+
"c290013"
847+
]
848+
},
849+
"web_content/preset/34_C_A_violin": {
850+
"refs": [
851+
"a15441c"
852+
]
853+
},
854+
"web_content/preset/35_C_A_vertical_violin": {
855+
"refs": [
856+
"5d03a03"
857+
]
858+
},
859+
"web_content/preset/38_C_L_line": {
860+
"refs": [
861+
"12acc6d"
862+
]
863+
},
864+
"web_content/preset/39_C_L_vertical_line": {
865+
"refs": [
866+
"c8163da"
867+
]
868+
},
869+
"web_content/preset/40_P_R_pie": {
870+
"refs": [
871+
"9528558"
872+
]
873+
},
874+
"web_content/preset/42_P_R_polar_column": {
875+
"refs": [
876+
"5ccab38"
877+
]
878+
},
879+
"web_content/preset/42a_P_R_polar_stacked_column": {
880+
"refs": [
881+
"cc0bd7f"
882+
]
883+
},
884+
"web_content/preset/44_P_R_variable_radius_pie_chart": {
885+
"refs": [
886+
"21080f4"
887+
]
888+
},
889+
"web_content/preset/49_P_R_radial_bar": {
890+
"refs": [
891+
"cb9bf74"
892+
]
893+
},
894+
"web_content/preset/50_P_R_radial_stacked_bar": {
895+
"refs": [
896+
"3be7e75"
897+
]
898+
},
899+
"web_content/preset/51_P_R_donut": {
900+
"refs": [
901+
"5bdb358"
902+
]
903+
},
904+
"web_content/preset/52_P_R_nested_donut": {
905+
"refs": [
906+
"c01fc6d"
907+
]
908+
},
909+
"web_content/preset/53_P_C_polar_scatter": {
910+
"refs": [
911+
"d1d548a"
912+
]
913+
},
914+
"web_content/preset/56_P_A_polar_line": {
915+
"refs": [
916+
"6e798cd"
917+
]
918+
},
919+
"web_content/preset/58_W_R_treemap": {
920+
"refs": [
921+
"59dca33"
922+
]
923+
},
924+
"web_content/preset/59_W_R_stacked_treemap": {
925+
"refs": [
926+
"939a26c"
927+
]
928+
},
929+
"web_content/preset/60_W_R_heatmap": {
930+
"refs": [
931+
"2646223"
932+
]
933+
},
934+
"web_content/preset/61_W_R_bubble_chart": {
935+
"refs": [
936+
"c91118e"
937+
]
938+
},
939+
"web_content/preset/62_W_R_stacked_bubble": {
940+
"refs": [
941+
"928ab63"
942+
]
943+
},
739944
"web_content/sample_static/cartesian/area_negative_1dis_1con": {
740945
"refs": [
741946
"c9c3c20"

0 commit comments

Comments
 (0)