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