@devgateway/dvz-wp-commons 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/build/APIConfig.cjs +479 -0
  2. package/build/APIConfig.d.ts +12 -0
  3. package/build/APIConfig.js +367 -283
  4. package/build/APIutils.cjs +54 -0
  5. package/build/APIutils.js +7 -1
  6. package/build/Blocks.cjs +672 -0
  7. package/build/Blocks.d.ts +14 -1
  8. package/build/Blocks.js +523 -330
  9. package/build/CSVSourceConfig.cjs +99 -0
  10. package/build/CSVSourceConfig.js +63 -46
  11. package/build/ChartColors.cjs +593 -0
  12. package/build/ChartColors.d.ts +0 -1
  13. package/build/ChartColors.js +430 -366
  14. package/build/ChartLegends.cjs +157 -0
  15. package/build/ChartLegends.d.ts +0 -1
  16. package/build/ChartLegends.js +173 -54
  17. package/build/ChartMeasures.cjs +192 -0
  18. package/build/ChartMeasures.d.ts +0 -1
  19. package/build/ChartMeasures.js +197 -109
  20. package/build/Constants.cjs +21 -0
  21. package/build/Constants.js +3 -1
  22. package/build/DataFilters.cjs +176 -0
  23. package/build/DataFilters.js +100 -89
  24. package/build/Format.cjs +1038 -0
  25. package/build/Format.js +428 -378
  26. package/build/MapCSVSourceConfig.cjs +36 -0
  27. package/build/MapCSVSourceConfig.js +19 -8
  28. package/build/Measures.cjs +196 -0
  29. package/build/Measures.js +204 -108
  30. package/build/MobileConfigUtils.cjs +92 -0
  31. package/build/MobileConfigUtils.js +19 -8
  32. package/build/Tooltip.cjs +63 -0
  33. package/build/Tooltip.d.ts +1 -3
  34. package/build/Tooltip.js +27 -51
  35. package/build/Util.cjs +29 -0
  36. package/build/Util.js +7 -7
  37. package/build/hooks/index.cjs +1 -0
  38. package/build/hooks/index.js +0 -3
  39. package/build/icons/Chart.cjs +49 -0
  40. package/build/icons/Chart.d.ts +1 -2
  41. package/build/icons/Chart.js +10 -11
  42. package/build/icons/Generic.cjs +24 -0
  43. package/build/icons/Generic.d.ts +1 -2
  44. package/build/icons/Generic.js +25 -4
  45. package/build/icons/index.cjs +19 -0
  46. package/build/icons/index.js +2 -2
  47. package/build/index.cjs +225 -0
  48. package/build/index.d.ts +1 -1
  49. package/build/index.js +47 -16
  50. package/package.json +16 -7
  51. package/build/tsconfig.tsbuildinfo +0 -1
@@ -1,388 +1,452 @@
1
- import { PanelBody, PanelRow, SelectControl } from '@wordpress/components';
2
- import { PanelColorSettings } from '@wordpress/block-editor';
3
- import { __ } from '@wordpress/i18n';
1
+ import { PanelBody, PanelRow, SelectControl } from "@wordpress/components";
2
+ import { PanelColorSettings } from "@wordpress/block-editor";
3
+ import { __ } from "@wordpress/i18n";
4
4
  import { useEffect } from "react";
5
- import Papa from 'papaparse';
5
+ import Papa from "papaparse";
6
6
  import { useRef, useState } from "@wordpress/element";
7
- import { getTranslation } from "./APIutils";
8
- const OVERALL = 'Overall';
9
- const system = [{ value: "system", label: 'System Colors' }, { value: "manual", label: 'Manual Colors' }];
10
- export const categorical = [{ value: "nivo", label: 'nivo' }, {
11
- value: "category10", label: 'category10'
12
- }, { value: "accent", label: 'Accent' }, { value: "dark2", label: 'dark2' }, {
13
- value: "paired", label: 'paired'
14
- }, { value: "pastel1", label: 'pastel1' }, { value: "pastel2", label: 'pastel2' }, {
15
- value: "set1", label: 'set1'
16
- }, { value: "set2", label: 'set2' }, { value: "set3", label: 'set3' }];
17
- export const sequential = [{ value: "blues", label: 'blues' }, { value: "greens", label: 'greens' }, {
18
- value: "greys", label: 'greys'
19
- }, { value: "oranges", label: 'oranges' }, { value: "purples", label: 'purples' }, {
20
- value: "reds", label: 'reds'
21
- }, { value: "blue_green", label: 'blue_green' }, { value: "blue_purple", label: 'blue_purple' }, {
22
- value: "green_blue", label: 'green_blue'
23
- }, { value: "orange_red", label: 'orange_red' }, {
24
- value: "purple_blue_green", label: 'purple_blue_green'
25
- }, { value: "purple_blue", label: 'purple_blue' }, { value: "purple_red", label: 'purple_red' }, {
26
- value: "red_purple", label: 'red_purple'
27
- }, { value: "yellow_green_blue", label: 'yellow_green_blue' }, {
28
- value: "yellow_green", label: 'yellow_green'
29
- }, { value: "yellow_orange_brown", label: 'yellow_orange_brown' }, {
30
- value: "yellow_orange_red", label: 'yellow_orange_brown'
31
- }];
32
- export const diverging = [{ value: "brown_blueGreen", label: 'brown_blueGreen' },
33
- { value: "purpleRed_green", label: 'purpleRed_green' },
34
- { value: "pink_yellowGreen", label: 'pink_yellowGreen' },
35
- { value: "purple_orange", label: 'purple_orange' },
36
- { value: "red_blue", label: 'red_blue' },
37
- { value: "red_grey", label: 'red_grey' },
38
- { value: "red_yellow_blue", label: 'red_yellow_blue' },
39
- { value: "red_yellow_green", label: 'red_yellow_green' },
40
- { value: "spectral", label: 'spectral' }
7
+ import { getTranslation } from "./APIutils.js";
8
+ const OVERALL = "Overall";
9
+ const system = [{ value: "system", label: "System Colors" }, { value: "manual", label: "Manual Colors" }];
10
+ export const categorical = [{ value: "nivo", label: "nivo" }, {
11
+ value: "category10",
12
+ label: "category10"
13
+ }, { value: "accent", label: "Accent" }, { value: "dark2", label: "dark2" }, {
14
+ value: "paired",
15
+ label: "paired"
16
+ }, { value: "pastel1", label: "pastel1" }, { value: "pastel2", label: "pastel2" }, {
17
+ value: "set1",
18
+ label: "set1"
19
+ }, { value: "set2", label: "set2" }, { value: "set3", label: "set3" }];
20
+ export const sequential = [{ value: "blues", label: "blues" }, { value: "greens", label: "greens" }, {
21
+ value: "greys",
22
+ label: "greys"
23
+ }, { value: "oranges", label: "oranges" }, { value: "purples", label: "purples" }, {
24
+ value: "reds",
25
+ label: "reds"
26
+ }, { value: "blue_green", label: "blue_green" }, { value: "blue_purple", label: "blue_purple" }, {
27
+ value: "green_blue",
28
+ label: "green_blue"
29
+ }, { value: "orange_red", label: "orange_red" }, {
30
+ value: "purple_blue_green",
31
+ label: "purple_blue_green"
32
+ }, { value: "purple_blue", label: "purple_blue" }, { value: "purple_red", label: "purple_red" }, {
33
+ value: "red_purple",
34
+ label: "red_purple"
35
+ }, { value: "yellow_green_blue", label: "yellow_green_blue" }, {
36
+ value: "yellow_green",
37
+ label: "yellow_green"
38
+ }, { value: "yellow_orange_brown", label: "yellow_orange_brown" }, {
39
+ value: "yellow_orange_red",
40
+ label: "yellow_orange_brown"
41
+ }];
42
+ export const diverging = [
43
+ { value: "brown_blueGreen", label: "brown_blueGreen" },
44
+ { value: "purpleRed_green", label: "purpleRed_green" },
45
+ { value: "pink_yellowGreen", label: "pink_yellowGreen" },
46
+ { value: "purple_orange", label: "purple_orange" },
47
+ { value: "red_blue", label: "red_blue" },
48
+ { value: "red_grey", label: "red_grey" },
49
+ { value: "red_yellow_blue", label: "red_yellow_blue" },
50
+ { value: "red_yellow_green", label: "red_yellow_green" },
51
+ { value: "spectral", label: "spectral" }
41
52
  ];
42
- const plainColor = { value: "plain_color", label: 'Use Plain color' };
53
+ const plainColor = { value: "plain_color", label: "Use Plain color" };
43
54
  export const ChartColors = (props) => {
44
- const { allDimensions, allFilters, allMeasures, allCategories, allApps, setAttributes, attributes: { swap, measures, manualColors, scheme, colorBy, dimension1, dimension2, barColor, type, app, csv, includeOverall } } = props;
45
- let l1Label;
46
- let d2Label;
47
- let d3Label;
48
- const selectedMeasures = measures[app] ? Object.keys(measures[app]).map(k => measures[app][k]).filter(m => m.selected) : [];
49
- let colorOptions = [];
50
- if (app !== "csv") {
51
- l1Label = dimension1 != 'none' && allDimensions ? '1st Dimension - ' + allDimensions.filter(d => d.value == dimension1)[0].label : null;
52
- //if one dimensions is selected o
53
- if (dimension2 == 'none' && selectedMeasures.length > 0) {
54
- d2Label = __("Measure Labels");
55
- d3Label = __("Measure Values");
56
- }
57
- else if (dimension2 != 'none') {
58
- //if two dimensions are selected show dimensions 1, dimensions 2 and values
59
- d2Label = allDimensions ? '2nd Dimension - ' + allDimensions.filter(d => d.value == dimension2)[0].label : null;
60
- d3Label = __("Measure Values");
61
- }
55
+ const {
56
+ allDimensions,
57
+ allFilters,
58
+ allMeasures,
59
+ allCategories,
60
+ allApps,
61
+ setAttributes,
62
+ attributes: {
63
+ swap,
64
+ measures,
65
+ manualColors,
66
+ scheme,
67
+ colorBy,
68
+ dimension1,
69
+ dimension2,
70
+ barColor,
71
+ type,
72
+ app,
73
+ csv,
74
+ includeOverall
62
75
  }
63
- else {
64
- //CSV Color Options
65
- const data = Papa.parse(csv, { header: true, dynamicTyping: true });
66
- l1Label = data.meta.fields.length > 0 ? '1st Column Values ' : null;
67
- d2Label = __("Measure Columns Labels");
68
- d3Label = __("Measure Columns Values");
76
+ } = props;
77
+ let l1Label;
78
+ let d2Label;
79
+ let d3Label;
80
+ const selectedMeasures = measures[app] ? Object.keys(measures[app]).map((k) => measures[app][k]).filter((m) => m.selected) : [];
81
+ let colorOptions = [];
82
+ if (app !== "csv") {
83
+ l1Label = dimension1 != "none" && allDimensions ? "1st Dimension - " + allDimensions.filter((d) => d.value == dimension1)[0].label : null;
84
+ if (dimension2 == "none" && selectedMeasures.length > 0) {
85
+ d2Label = __("Measure Labels");
86
+ d3Label = __("Measure Values");
87
+ } else if (dimension2 != "none") {
88
+ d2Label = allDimensions ? "2nd Dimension - " + allDimensions.filter((d) => d.value == dimension2)[0].label : null;
89
+ d3Label = __("Measure Values");
69
90
  }
70
- if (type == 'bar' || type == 'line') {
71
- if (swap && dimension2 == "none" && selectedMeasures.length > 0) {
72
- colorOptions = [];
73
- if (l1Label) {
74
- colorOptions.push({ label: l1Label, value: 'id' });
75
- colorOptions.push({ label: d2Label, value: 'index' });
76
- }
77
- else {
78
- colorOptions.push({ label: d2Label, value: 'id' });
79
- colorOptions.push({ label: "Measure Values", value: 'values' });
80
- }
81
- }
82
- else {
83
- colorOptions = [];
84
- if (l1Label && l1Label !== 'none') {
85
- colorOptions.push({ label: l1Label, value: 'index' });
86
- }
87
- if (d2Label && d2Label !== 'none') {
88
- colorOptions.push({ label: d2Label, value: (l1Label && l1Label !== 'none') ? 'id' : 'index' });
89
- }
90
- if (d3Label && d3Label !== 'none') {
91
- colorOptions.push({ label: d3Label, value: 'values' });
92
- }
93
- }
91
+ } else {
92
+ const data = Papa.parse(csv, { header: true, dynamicTyping: true });
93
+ l1Label = data.meta.fields.length > 0 ? "1st Column Values " : null;
94
+ d2Label = __("Measure Columns Labels");
95
+ d3Label = __("Measure Columns Values");
96
+ }
97
+ if (type == "bar" || type == "line") {
98
+ if (swap && dimension2 == "none" && selectedMeasures.length > 0) {
99
+ colorOptions = [];
100
+ if (l1Label) {
101
+ colorOptions.push({ label: l1Label, value: "id" });
102
+ colorOptions.push({ label: d2Label, value: "index" });
103
+ } else {
104
+ colorOptions.push({ label: d2Label, value: "id" });
105
+ colorOptions.push({ label: "Measure Values", value: "values" });
106
+ }
107
+ } else {
108
+ colorOptions = [];
109
+ if (l1Label && l1Label !== "none") {
110
+ colorOptions.push({ label: l1Label, value: "index" });
111
+ }
112
+ if (d2Label && d2Label !== "none") {
113
+ colorOptions.push({ label: d2Label, value: l1Label && l1Label !== "none" ? "id" : "index" });
114
+ }
115
+ if (d3Label && d3Label !== "none") {
116
+ colorOptions.push({ label: d3Label, value: "values" });
117
+ }
94
118
  }
95
- if (type == 'pie') {
96
- if (dimension1 != 'none' && dimension2 == 'none' && colorBy != 'index') {
97
- setAttributes({ colorBy: 'index' });
98
- return null;
99
- }
100
- if (dimension1 != 'none' && dimension2 != 'none' && colorBy != 'id') {
101
- setAttributes({ colorBy: 'id' });
102
- return null;
103
- }
119
+ }
120
+ if (type == "pie") {
121
+ if (dimension1 != "none" && dimension2 == "none" && colorBy != "index") {
122
+ setAttributes({ colorBy: "index" });
123
+ return null;
104
124
  }
105
- let options = [];
106
- if (colorBy === 'index' || colorBy === 'id') {
107
- if (type == "bar") {
108
- options = [...system, plainColor, ...categorical, ...sequential];
109
- }
110
- else if (type == "line") {
111
- options = [...system, plainColor, ...categorical];
112
- }
113
- else {
114
- options = [...system, ...categorical, ...sequential];
125
+ if (dimension1 != "none" && dimension2 != "none" && colorBy != "id") {
126
+ setAttributes({ colorBy: "id" });
127
+ return null;
128
+ }
129
+ }
130
+ let options = [];
131
+ if (colorBy === "index" || colorBy === "id") {
132
+ if (type == "bar") {
133
+ options = [...system, plainColor, ...categorical, ...sequential];
134
+ } else if (type == "line") {
135
+ options = [...system, plainColor, ...categorical];
136
+ } else {
137
+ options = [...system, ...categorical, ...sequential];
138
+ }
139
+ }
140
+ if (colorBy === "values") {
141
+ options = [...sequential];
142
+ }
143
+ const [useColors, setUseColors] = useState("dimension");
144
+ useEffect(() => {
145
+ let nextUseColors = useColors;
146
+ if (app != "csv") {
147
+ if (dimension2 == "none" && colorBy === "index" && swap || dimension1 == "none" && dimension2 == "none") {
148
+ nextUseColors = "measure";
149
+ } else if (dimension2 == "none" && colorBy === "id" && !swap) {
150
+ nextUseColors = "measure";
151
+ } else {
152
+ nextUseColors = "dimension";
153
+ }
154
+ if (prevStatus.current) {
155
+ if (nextUseColors == "dimension") {
156
+ if (prevStatus.current["scheme"] != scheme && scheme === "manual") {
157
+ initColors(colorBy === "index" ? dimension1 : dimension2);
158
+ }
159
+ if (prevStatus.current["colorBy"] != colorBy) {
160
+ initColors(colorBy === "index" ? dimension1 : dimension2);
161
+ }
162
+ if (prevStatus.current["dimension1"] != dimension1 || prevStatus.current["dimension2"] != dimension2) {
163
+ initColors(colorBy === "index" ? dimension1 : dimension2);
164
+ }
165
+ } else {
166
+ initMeasuresColors();
115
167
  }
168
+ }
169
+ setUseColors(nextUseColors);
170
+ } else {
171
+ if (!manualColors["csv"]) {
172
+ setAttributes({ manualColors: { "csv": {} } });
173
+ }
116
174
  }
117
- if (colorBy === 'values') {
118
- options = [...sequential];
175
+ prevStatus.current = { scheme, colorBy, dimension1, dimension2, useColors, app };
176
+ }, [scheme, dimension1, dimension2, colorBy, swap, app, type]);
177
+ const prevStatus = useRef();
178
+ const updateColor = (value, color, colorByMode = null) => {
179
+ const newColors = Object.assign({}, manualColors);
180
+ if (colorByMode) {
181
+ if (!newColors[app][colorByMode]) {
182
+ newColors[app][colorByMode] = {};
183
+ }
184
+ newColors[app][colorByMode][value] = color;
185
+ } else {
186
+ newColors[app][value] = color;
119
187
  }
120
- const [useColors, setUseColors] = useState("dimension");
121
- useEffect(() => {
122
- let nextUseColors = useColors;
123
- if (app != "csv") {
124
- // All conditions for coloring by measures
125
- if ((dimension2 == "none" && colorBy === "index" && swap) ||
126
- (dimension1 == "none" && dimension2 == "none")) { //Multi measure colored by first dimension but swapped (Colored by Measure) or dimensionless bar charts
127
- nextUseColors = "measure";
128
- }
129
- else if (dimension2 == "none" && colorBy === "id" && !swap) { //Multi Measure chart colored by (Measure)
130
- nextUseColors = "measure";
131
- }
132
- else {
133
- //colored by a dimensions
134
- nextUseColors = "dimension";
135
- }
136
- if (prevStatus.current) {
137
- if (nextUseColors == "dimension") {
138
- if (prevStatus.current["scheme"] != scheme && scheme === "manual") {
139
- initColors(colorBy === "index" ? dimension1 : dimension2);
140
- }
141
- if (prevStatus.current["colorBy"] != colorBy) {
142
- initColors(colorBy === "index" ? dimension1 : dimension2);
188
+ setAttributes({ manualColors: newColors });
189
+ };
190
+ const initColors = (dimension) => {
191
+ const ds = allDimensions.filter((d) => d.value == dimension);
192
+ const newColors = Object.assign({}, manualColors);
193
+ if (!newColors[app]) {
194
+ newColors[app] = {};
195
+ }
196
+ if (ds.length > 0) {
197
+ const { type: type2 } = ds[0];
198
+ const cat = allCategories.filter((a) => a.type === type2);
199
+ if (cat.length > 0) {
200
+ cat[0].items.forEach((item) => {
201
+ if (!newColors[app][item.code]) {
202
+ newColors[app][item.code] = item.categoryStyle ? item.categoryStyle.color : "#eeeeee";
203
+ }
204
+ });
205
+ }
206
+ setAttributes({ manualColors: newColors });
207
+ }
208
+ };
209
+ const initMeasuresColors = () => {
210
+ const newColors = Object.assign({}, manualColors);
211
+ if (!newColors[app]) {
212
+ newColors[app] = {};
213
+ }
214
+ if (!allMeasures) {
215
+ }
216
+ if (allMeasures) {
217
+ allMeasures.forEach((p) => {
218
+ if (!newColors[app][p.value]) {
219
+ newColors[app][p.value] = p.styles ? p.styles.color : "#eeeeee";
220
+ }
221
+ });
222
+ }
223
+ setAttributes({ manualColors: newColors });
224
+ };
225
+ const combinedCatColors = (dimension12, dimension22) => {
226
+ if (manualColors[app]) {
227
+ const ds1 = allDimensions.filter((d) => d.value == dimension12);
228
+ const ds2 = allDimensions.filter((d) => d.value == dimension22);
229
+ if (ds1.length > 0 && ds2.length > 0) {
230
+ const { type: type2 } = ds1[0];
231
+ const { type: type22 } = ds2[0];
232
+ const cat = allCategories.filter((a) => a.type === type2);
233
+ const cat2 = allCategories.filter((a) => a.type === type22);
234
+ const list = [];
235
+ cat[0].items.sort((a, b) => a.position - b.position).forEach((c1) => {
236
+ cat2[0].items.sort((a, b) => a.position - b.position).forEach((c2) => {
237
+ list.push(/* @__PURE__ */ React.createElement(
238
+ PanelColorSettings,
239
+ {
240
+ colorSettings: [{
241
+ value: manualColors[app][c1.value + " - " + c2.value],
242
+ onChange: (color) => {
243
+ if (color) {
244
+ updateColor(c1.value + " - " + c2.value, color);
245
+ } else {
246
+ updateColor(c1.value + " - " + c2.value, "#eeeeee");
143
247
  }
144
- if (prevStatus.current["dimension1"] != dimension1 || prevStatus.current["dimension2"] != dimension2) {
145
- initColors(colorBy === "index" ? dimension1 : dimension2);
248
+ },
249
+ label: c1.value + " - " + c2.value
250
+ }]
251
+ }
252
+ ));
253
+ });
254
+ });
255
+ return list;
256
+ }
257
+ }
258
+ return null;
259
+ };
260
+ const catColors = (dimension) => {
261
+ if (manualColors[app]) {
262
+ const ds = allDimensions.filter((d) => d.value == dimension);
263
+ if (ds.length > 0) {
264
+ const { type: type2 } = ds[0];
265
+ const cat = allCategories.filter((a) => a.type === type2);
266
+ if (cat && cat.length > 0) {
267
+ const list = cat[0].items.filter((c) => c.code !== null && c.code !== void 0 && c.code !== "").sort((a, b) => b.position - a.position).map((item) => {
268
+ return /* @__PURE__ */ React.createElement(
269
+ PanelColorSettings,
270
+ {
271
+ colorSettings: [{
272
+ value: manualColors[app][item.code],
273
+ onChange: (color) => {
274
+ if (color) {
275
+ updateColor(item.code, color);
276
+ } else {
277
+ updateColor(item.code, item.categoryStyle ? item.categoryStyle.color : "#eeeeee");
146
278
  }
147
- }
148
- else {
149
- initMeasuresColors();
150
- }
279
+ },
280
+ label: getTranslation(item)
281
+ }]
282
+ }
283
+ );
284
+ });
285
+ const dimensions = [dimension1, dimension2].filter((f) => f != "" && f != "none");
286
+ let selectedMeasures2 = [];
287
+ allMeasures.forEach((m) => {
288
+ if (measures[app] && measures[app][m.value] && measures[app][m.value].selected) {
289
+ selectedMeasures2.push(m.value);
151
290
  }
152
- setUseColors(nextUseColors);
153
- }
154
- else {
155
- if (!manualColors["csv"]) {
156
- setAttributes({ manualColors: { "csv": {} } });
157
- }
158
- }
159
- prevStatus.current = { scheme, colorBy, dimension1, dimension2, useColors, app };
160
- }, [scheme, dimension1, dimension2, colorBy, swap, app, type]);
161
- const prevStatus = useRef();
162
- const updateColor = (value, color) => {
163
- const newColors = Object.assign({}, manualColors);
164
- newColors[app][value] = color;
165
- setAttributes({ manualColors: newColors });
166
- };
167
- const initColors = (dimension) => {
168
- const ds = allDimensions.filter(d => d.value == dimension);
169
- const newColors = Object.assign({}, manualColors);
170
- if (!newColors[app]) {
171
- newColors[app] = {};
172
- }
173
- if (ds.length > 0) {
174
- const { type } = ds[0];
175
- const cat = allCategories.filter(a => a.type === type);
176
- if (cat.length > 0) {
177
- cat[0].items.forEach(item => {
178
- if (!newColors[app][item.code]) {
179
- newColors[app][item.code] = item.categoryStyle ? item.categoryStyle.color : "#eeeeee";
291
+ });
292
+ if (includeOverall) {
293
+ list.push(/* @__PURE__ */ React.createElement(
294
+ PanelColorSettings,
295
+ {
296
+ colorSettings: [{
297
+ value: manualColors[app][OVERALL],
298
+ onChange: (color) => {
299
+ if (color) {
300
+ updateColor(OVERALL, color);
301
+ } else {
302
+ updateColor(OVERALL, "#eeeeee");
180
303
  }
181
- });
182
- }
183
- setAttributes({ manualColors: newColors });
184
- }
185
- };
186
- const initMeasuresColors = () => {
187
- const newColors = Object.assign({}, manualColors);
188
- if (!newColors[app]) {
189
- newColors[app] = {};
190
- }
191
- if (!allMeasures) {
304
+ },
305
+ label: __("Overall")
306
+ }]
307
+ }
308
+ ));
309
+ }
310
+ return list;
311
+ } else {
312
+ return null;
192
313
  }
193
- if (allMeasures) {
194
- allMeasures.forEach(p => {
195
- if (!newColors[app][p.value]) {
196
- newColors[app][p.value] = p.styles ? p.styles.color : "#eeeeee";
197
- }
198
- });
199
- }
200
- setAttributes({ manualColors: newColors });
201
- };
202
- const combinedCatColors = (dimension1, dimension2) => {
203
- if (manualColors[app]) {
204
- const ds1 = allDimensions.filter(d => d.value == dimension1);
205
- const ds2 = allDimensions.filter(d => d.value == dimension2);
206
- if (ds1.length > 0 && ds2.length > 0) {
207
- const { type } = ds1[0];
208
- const { type: type2 } = ds2[0];
209
- const cat = allCategories.filter(a => a.type === type);
210
- const cat2 = allCategories.filter(a => a.type === type2);
211
- const list = [];
212
- cat[0].items.sort((a, b) => a.position - b.position).forEach(c1 => {
213
- cat2[0].items.sort((a, b) => a.position - b.position).forEach(c2 => {
214
- list.push(React.createElement(PanelColorSettings, { colorSettings: [{
215
- value: manualColors[app][c1.value + ' - ' + c2.value],
216
- onChange: (color) => {
217
- if (color) {
218
- updateColor(c1.value + ' - ' + c2.value, color);
219
- }
220
- else {
221
- updateColor(c1.value + ' - ' + c2.value, "#eeeeee");
222
- }
223
- },
224
- label: c1.value + ' - ' + c2.value
225
- }] }));
226
- });
227
- });
228
- return list;
314
+ }
315
+ }
316
+ return null;
317
+ };
318
+ const measureColors = () => {
319
+ if (manualColors[app] && allMeasures && measures[app]) {
320
+ const selectedMeasures2 = allMeasures.filter((m) => Object.keys(measures[app]).indexOf(m.value) > -1 && measures[app][m.value].selected);
321
+ if (selectedMeasures2.length > 0) {
322
+ const list = selectedMeasures2.sort((a, b) => b.position - a.position).map((item) => {
323
+ return /* @__PURE__ */ React.createElement(
324
+ PanelColorSettings,
325
+ {
326
+ colorSettings: [{
327
+ value: manualColors[app][item.value],
328
+ onChange: (color) => {
329
+ if (color) {
330
+ updateColor(item.value, color);
331
+ } else {
332
+ updateColor(item.value, item.styles ? item.styles.color : "#555555");
333
+ }
334
+ },
335
+ label: __(item.label)
336
+ }]
229
337
  }
230
- }
231
- return null;
232
- };
233
- const catColors = (dimension) => {
234
- if (manualColors[app]) {
235
- const ds = allDimensions.filter(d => d.value == dimension);
236
- if (ds.length > 0) {
237
- const { type } = ds[0];
238
- const cat = allCategories.filter(a => a.type === type);
239
- if (cat && cat.length > 0) {
240
- const list = cat[0].items.filter(c => c.code !== null && c.code !== undefined && c.code !== "").sort((a, b) => b.position - a.position).map(item => {
241
- return React.createElement(PanelColorSettings, { colorSettings: [{
242
- value: manualColors[app][item.code],
243
- onChange: (color) => {
244
- if (color) {
245
- updateColor(item.code, color);
246
- }
247
- else {
248
- updateColor(item.code, item.categoryStyle ? item.categoryStyle.color : "#eeeeee");
249
- }
250
- }, label: getTranslation(item)
251
- }] });
252
- });
253
- const dimensions = [dimension1, dimension2].filter(f => f != '' && f != "none");
254
- let selectedMeasures = [];
255
- allMeasures.forEach(m => {
256
- if (measures[app] && measures[app][m.value] && measures[app][m.value].selected) {
257
- selectedMeasures.push(m.value);
258
- }
259
- });
260
- if (includeOverall) {
261
- list.push(React.createElement(PanelColorSettings, { colorSettings: [{
262
- value: manualColors[app][OVERALL],
263
- onChange: (color) => {
264
- if (color) {
265
- updateColor(OVERALL, color);
266
- }
267
- else {
268
- updateColor(OVERALL, "#eeeeee");
269
- }
270
- }, label: __("Overall")
271
- }] }));
272
- }
273
- return list;
274
- }
275
- else {
276
- return null;
277
- }
338
+ );
339
+ });
340
+ if (includeOverall && selectedMeasures2.length == 1) {
341
+ list.push(/* @__PURE__ */ React.createElement(
342
+ PanelColorSettings,
343
+ {
344
+ colorSettings: [{
345
+ value: manualColors[app][OVERALL],
346
+ onChange: (color) => {
347
+ if (color) {
348
+ updateColor(OVERALL, color);
349
+ } else {
350
+ updateColor(OVERALL, "#eeeeee");
351
+ }
352
+ },
353
+ label: __("Overall")
354
+ }]
278
355
  }
356
+ ));
279
357
  }
280
- return null;
281
- };
282
- const measureColors = () => {
283
- if (manualColors[app] && allMeasures && measures[app]) {
284
- const selectedMeasures = allMeasures.filter(m => Object.keys(measures[app]).indexOf(m.value) > -1 && measures[app][m.value].selected);
285
- if (selectedMeasures.length > 0) {
286
- const list = selectedMeasures.sort((a, b) => b.position - a.position)
287
- .map(item => {
288
- return React.createElement(PanelColorSettings, { colorSettings: [{
289
- value: manualColors[app][item.value], onChange: (color) => {
290
- if (color) {
291
- updateColor(item.value, color);
292
- }
293
- else {
294
- updateColor(item.value, item.styles ? item.styles.color : "#555555");
295
- }
296
- }, label: __(item.label)
297
- }] });
298
- });
299
- if (includeOverall && selectedMeasures.length == 1) {
300
- list.push(React.createElement(PanelColorSettings, { colorSettings: [{
301
- value: manualColors[app][OVERALL], onChange: (color) => {
302
- if (color) {
303
- updateColor(OVERALL, color);
304
- }
305
- else {
306
- updateColor(OVERALL, "#eeeeee");
307
- }
308
- }, label: __("Overall")
309
- }] }));
358
+ return list;
359
+ }
360
+ }
361
+ return null;
362
+ };
363
+ const csvColors = () => {
364
+ const data = Papa.parse(csv, { header: true, dynamicTyping: true });
365
+ const values = [];
366
+ if (colorBy === "index" && type != "line" || type == "pie") {
367
+ const field = data.meta.fields[0];
368
+ values.push(...data.data.map((d) => d[field]));
369
+ }
370
+ if (colorBy === "id" || type == "line") {
371
+ values.push(...data.meta.fields.slice(1));
372
+ }
373
+ if (colorBy === "values") {
374
+ values.push(0, 100);
375
+ }
376
+ if (manualColors[app] && values) {
377
+ return values.map((v) => {
378
+ const colorByColors = manualColors[app][colorBy] || {};
379
+ return /* @__PURE__ */ React.createElement(
380
+ PanelColorSettings,
381
+ {
382
+ colorSettings: [{
383
+ value: colorByColors[v],
384
+ onChange: (color) => {
385
+ if (color) {
386
+ updateColor(v, color, colorBy);
310
387
  }
311
- return list;
312
- }
313
- }
314
- return null;
315
- };
316
- const csvColors = () => {
317
- const data = Papa.parse(csv, { header: true, dynamicTyping: true });
318
- const values = [];
319
- if (colorBy === "index" && type != 'line') {
320
- const field = data.meta.fields[0];
321
- values.push(...data.data.map(d => d[field]));
322
- }
323
- if (colorBy === "id" || type == 'line') {
324
- values.push(...data.meta.fields.slice(1));
325
- }
326
- if (colorBy === "values") {
327
- values.push(0, 100);
328
- }
329
- if (manualColors[app] && values) {
330
- return values.map(v => {
331
- return React.createElement(PanelColorSettings, { colorSettings: [{
332
- value: manualColors[app][v],
333
- onChange: (color) => {
334
- if (color) {
335
- updateColor(v, color);
336
- }
337
- }, label: __(v)
338
- }] });
339
- });
340
- }
341
- return null;
342
- };
343
- const elements = [];
344
- if (type == 'bar' || type == 'line') {
345
- elements.push(React.createElement(PanelRow, null,
346
- React.createElement(SelectControl, { label: __('Color By'), value: [colorBy], onChange: (colorBy) => {
347
- setAttributes({ colorBy });
348
- if (colorBy === 'index' || colorBy === 'id') {
349
- setAttributes({ colorBy });
350
- }
351
- if (colorBy === 'values') {
352
- setAttributes({ scheme: "blues", colorBy });
353
- }
354
- }, options: colorOptions })));
388
+ },
389
+ label: __(v)
390
+ }]
391
+ }
392
+ );
393
+ });
355
394
  }
356
- return [
357
- ...elements,
358
- React.createElement(PanelRow, null,
359
- React.createElement(SelectControl, { label: __('Color Scheme'), value: [scheme], onChange: (value) => {
360
- setAttributes({ scheme: value });
361
- }, options: options })),
362
- (scheme == "plain_color") && React.createElement(PanelRow, null,
363
- React.createElement(PanelColorSettings, { title: __('Color settings'), colorSettings: [{
364
- value: decodeURIComponent(barColor), onChange: (color) => {
365
- if (color) {
366
- setAttributes({ barColor: encodeURIComponent(color) });
367
- }
368
- else {
369
- setAttributes({ barColor: null });
370
- }
371
- }, label: __('Plain color')
372
- }] })),
373
- (scheme == "manual") && React.createElement(PanelRow, null,
374
- app != "csv" && useColors == "dimension" && colorBy == "index" &&
375
- React.createElement(PanelBody, { initialOpen: false, title: __("Set Colors") }, catColors(dimension1)),
376
- app != "csv" && useColors == "dimension" && (colorBy == "id" && dimension2 != "none") &&
377
- React.createElement(PanelBody, { initialOpen: false, title: __("Set Colors") },
378
- type == 'bar' && catColors(dimension2),
379
- type == 'line' && catColors(dimension2),
380
- type == 'pie' && combinedCatColors(dimension1, dimension2)),
381
- app != "csv" && useColors == "dimension" && swap && colorBy == "id" && dimension1 != "none" && dimension2 == "none" &&
382
- React.createElement(PanelBody, { initialOpen: false, title: __("Set Colors") }, catColors(dimension1)),
383
- app != 'csv' && useColors === "measure" &&
384
- React.createElement(PanelBody, { initialOpen: false, title: __("Set Color By Measure") }, measureColors()),
385
- app == "csv" && React.createElement(PanelBody, { initialOpen: false, title: __("Set Colors") }, csvColors(colorBy)))
386
- ];
395
+ return null;
396
+ };
397
+ const elements = [];
398
+ if (type == "bar" || type == "line") {
399
+ elements.push(/* @__PURE__ */ React.createElement(PanelRow, null, /* @__PURE__ */ React.createElement(
400
+ SelectControl,
401
+ {
402
+ label: __("Color By"),
403
+ value: [colorBy],
404
+ onChange: (colorBy2) => {
405
+ setAttributes({ colorBy: colorBy2 });
406
+ if (colorBy2 === "index" || colorBy2 === "id") {
407
+ setAttributes({ colorBy: colorBy2 });
408
+ }
409
+ if (colorBy2 === "values") {
410
+ setAttributes({ scheme: "blues", colorBy: colorBy2 });
411
+ }
412
+ },
413
+ options: colorOptions
414
+ }
415
+ )));
416
+ }
417
+ if (type == "pie") {
418
+ setAttributes({ colorBy: "index" });
419
+ }
420
+ return [
421
+ ...elements,
422
+ /* @__PURE__ */ React.createElement(PanelRow, null, /* @__PURE__ */ React.createElement(
423
+ SelectControl,
424
+ {
425
+ label: __("Color Scheme"),
426
+ value: [scheme],
427
+ onChange: (value) => {
428
+ setAttributes({ scheme: value });
429
+ },
430
+ options
431
+ }
432
+ )),
433
+ scheme == "plain_color" && /* @__PURE__ */ React.createElement(PanelRow, null, /* @__PURE__ */ React.createElement(
434
+ PanelColorSettings,
435
+ {
436
+ title: __("Color settings"),
437
+ colorSettings: [{
438
+ value: decodeURIComponent(barColor),
439
+ onChange: (color) => {
440
+ if (color) {
441
+ setAttributes({ barColor: encodeURIComponent(color) });
442
+ } else {
443
+ setAttributes({ barColor: null });
444
+ }
445
+ },
446
+ label: __("Plain color")
447
+ }]
448
+ }
449
+ )),
450
+ scheme == "manual" && /* @__PURE__ */ React.createElement(PanelRow, null, app != "csv" && useColors == "dimension" && colorBy == "index" && /* @__PURE__ */ React.createElement(PanelBody, { initialOpen: false, title: __("Set Colors") }, catColors(dimension1)), app != "csv" && useColors == "dimension" && (colorBy == "id" && dimension2 != "none") && /* @__PURE__ */ React.createElement(PanelBody, { initialOpen: false, title: __("Set Colors") }, type == "bar" && catColors(dimension2), type == "line" && catColors(dimension2), type == "pie" && combinedCatColors(dimension1, dimension2)), app != "csv" && useColors == "dimension" && swap && colorBy == "id" && dimension1 != "none" && dimension2 == "none" && /* @__PURE__ */ React.createElement(PanelBody, { initialOpen: false, title: __("Set Colors") }, catColors(dimension1)), app != "csv" && useColors === "measure" && /* @__PURE__ */ React.createElement(PanelBody, { initialOpen: false, title: __("Set Color By Measure") }, measureColors()), app == "csv" && /* @__PURE__ */ React.createElement(PanelBody, { initialOpen: false, title: __("Set Colors") }, csvColors(colorBy)))
451
+ ];
387
452
  };
388
- export default ChartColors;