@emerson-eps/color-tables 0.2.11 → 0.2.14

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 (122) hide show
  1. package/dist/component/ColorSelector/ColorSelectorAccordion.js +2 -2
  2. package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -1
  3. package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +1 -2
  4. package/dist/component/ColorSelector/ColorSelectorComponent.js +7 -7
  5. package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
  6. package/dist/component/ColorSelector/ColorSelectorWrapper.d.ts +6 -2
  7. package/dist/component/ColorSelector/ColorSelectorWrapper.js +10 -10
  8. package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -1
  9. package/dist/component/Legend/ColorLegend.js +13 -5
  10. package/dist/component/Legend/ColorLegend.js.map +1 -1
  11. package/dist/component/Legend/ContinuousLegend.d.ts +1 -1
  12. package/dist/component/Legend/ContinuousLegend.js +18 -4
  13. package/dist/component/Legend/ContinuousLegend.js.map +1 -1
  14. package/dist/component/Legend/DiscreteLegend.d.ts +1 -1
  15. package/dist/component/Legend/DiscreteLegend.js +25 -16
  16. package/dist/component/Legend/DiscreteLegend.js.map +1 -1
  17. package/dist/component/Utils/continousLegend.d.ts +2 -2
  18. package/dist/component/Utils/continousLegend.js.map +1 -1
  19. package/dist/component/Utils/discreteLegend.js +14 -27
  20. package/dist/component/Utils/discreteLegend.js.map +1 -1
  21. package/dist/component/{Utils/ColorTableTypes.d.ts → colorTableTypes.d.ts} +0 -0
  22. package/dist/component/colorTableTypes.js +2 -0
  23. package/dist/component/colorTableTypes.js.map +1 -0
  24. package/dist/index.d.ts +2 -4
  25. package/dist/index.js +1 -3
  26. package/dist/index.js.map +1 -1
  27. package/package.json +6 -3
  28. package/.storybook/main.js +0 -11
  29. package/.storybook/preview.js +0 -9
  30. package/.vscode/settings.json +0 -3
  31. package/dist/component/Utils/ColorTableTypes.js +0 -2
  32. package/dist/component/Utils/ColorTableTypes.js.map +0 -1
  33. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.d.ts +0 -7
  34. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js +0 -11
  35. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js.map +0 -1
  36. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.d.ts +0 -7
  37. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js +0 -38
  38. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +0 -1
  39. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.d.ts +0 -7
  40. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js +0 -38
  41. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +0 -1
  42. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.d.ts +0 -7
  43. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js +0 -38
  44. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +0 -1
  45. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.d.ts +0 -7
  46. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js +0 -38
  47. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +0 -1
  48. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.d.ts +0 -7
  49. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js +0 -38
  50. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +0 -1
  51. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.d.ts +0 -7
  52. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js +0 -38
  53. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +0 -1
  54. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.d.ts +0 -7
  55. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js +0 -38
  56. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +0 -1
  57. package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.d.ts +0 -7
  58. package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js +0 -47
  59. package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js.map +0 -1
  60. package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.d.ts +0 -7
  61. package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js +0 -47
  62. package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js.map +0 -1
  63. package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.d.ts +0 -7
  64. package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js +0 -39
  65. package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js.map +0 -1
  66. package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.d.ts +0 -7
  67. package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js +0 -39
  68. package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js.map +0 -1
  69. package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.d.ts +0 -7
  70. package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js +0 -42
  71. package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js.map +0 -1
  72. package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.d.ts +0 -7
  73. package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js +0 -53
  74. package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js.map +0 -1
  75. package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.d.ts +0 -7
  76. package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js +0 -42
  77. package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js.map +0 -1
  78. package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.d.ts +0 -7
  79. package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js +0 -52
  80. package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js.map +0 -1
  81. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.d.ts +0 -7
  82. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js +0 -52
  83. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js.map +0 -1
  84. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.d.ts +0 -7
  85. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js +0 -38
  86. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js.map +0 -1
  87. package/dist/stories/ColorLegends/SingleComponent/Single.stories.d.ts +0 -7
  88. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js +0 -58
  89. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js.map +0 -1
  90. package/src/component/ColorSelector/ColorSelectorAccordion.tsx +0 -54
  91. package/src/component/ColorSelector/ColorSelectorComponent.tsx +0 -312
  92. package/src/component/ColorSelector/ColorSelectorWrapper.tsx +0 -119
  93. package/src/component/Legend/ColorLegend.tsx +0 -89
  94. package/src/component/Legend/ContinuousLegend.tsx +0 -220
  95. package/src/component/Legend/DiscreteLegend.tsx +0 -195
  96. package/src/component/Utils/ColorTableTypes.ts +0 -6
  97. package/src/component/Utils/continousLegend.ts +0 -73
  98. package/src/component/Utils/d3ColorScale.ts +0 -84
  99. package/src/component/Utils/discreteLegend.ts +0 -84
  100. package/src/component/color-tables.json +0 -203
  101. package/src/custom.d.ts +0 -1
  102. package/src/index.ts +0 -26
  103. package/src/stories/ColorLegends/ColorSelector/Selector.stories.jsx +0 -12
  104. package/src/stories/ColorLegends/ContinousLegends/MD.stories.jsx +0 -29
  105. package/src/stories/ColorLegends/ContinousLegends/NTG.stories.jsx +0 -29
  106. package/src/stories/ColorLegends/ContinousLegends/PermTot.stories.jsx +0 -29
  107. package/src/stories/ColorLegends/ContinousLegends/Permeability.stories.jsx +0 -29
  108. package/src/stories/ColorLegends/ContinousLegends/PoroTot.stories.jsx +0 -29
  109. package/src/stories/ColorLegends/ContinousLegends/Porosity.stories.jsx +0 -29
  110. package/src/stories/ColorLegends/ContinousLegends/SW.stories.jsx +0 -29
  111. package/src/stories/ColorLegends/DiscreteLegends/Facies.stories.jsx +0 -39
  112. package/src/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.jsx +0 -39
  113. package/src/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.jsx +0 -31
  114. package/src/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.jsx +0 -31
  115. package/src/stories/ColorLegends/DiscreteLegends/RDE.stories.jsx +0 -34
  116. package/src/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.jsx +0 -45
  117. package/src/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.jsx +0 -34
  118. package/src/stories/ColorLegends/DiscreteLegends/Zonelog.stories.jsx +0 -46
  119. package/src/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.jsx +0 -44
  120. package/src/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.jsx +0 -30
  121. package/src/stories/ColorLegends/SingleComponent/Single.stories.jsx +0 -51
  122. package/tsconfig.json +0 -23
@@ -1,54 +0,0 @@
1
- import * as React from "react";
2
- import { Accordion } from "@equinor/eds-core-react";
3
- import { ColorSelectorWrapper } from "./ColorSelectorWrapper";
4
-
5
- export const ColorSelectorAccordion = (props: any) => {
6
- return (
7
- <div className="Container" style={{width: "316px",
8
- position: "absolute",
9
- zIndex: 1,
10
- top: props.isHorizontal ? 100 : 30,
11
- right: props.isHorizontal ? 5 : 165,
12
- }}>
13
- <Accordion >
14
- <Accordion.Item isExpanded>
15
- <Accordion.Header>
16
- Color Scales
17
- </Accordion.Header>
18
- <Accordion.Panel>
19
- <Accordion >
20
- <Accordion.Item>
21
- <Accordion.Header>
22
- Geologic Color Scale
23
- </Accordion.Header>
24
- <Accordion.Panel>
25
- <ColorSelectorWrapper useColorTableColors={true} useD3Colors={false} colorScaleObject={props}/>
26
- </Accordion.Panel>
27
- </Accordion.Item>
28
- </Accordion>
29
- <Accordion >
30
- <Accordion.Item>
31
- <Accordion.Header>
32
- D3 Color Scale
33
- </Accordion.Header>
34
- <Accordion.Panel>
35
- <ColorSelectorWrapper useD3Colors={true} useColorTableColors={false} colorScaleObject={props}/>
36
- </Accordion.Panel>
37
- </Accordion.Item>
38
- </Accordion>
39
- <Accordion >
40
- <Accordion.Item>
41
- <Accordion.Header>
42
- Custom Color Scale
43
- </Accordion.Header>
44
- <Accordion.Panel>
45
- Custom Content
46
- </Accordion.Panel>
47
- </Accordion.Item>
48
- </Accordion>
49
- </Accordion.Panel>
50
- </Accordion.Item>
51
- </Accordion>
52
- </div>
53
- );
54
- };
@@ -1,312 +0,0 @@
1
- import * as React from "react";
2
- import { useRef } from "react";
3
- import { RGBToHex } from "../Utils/continousLegend";
4
- import {d3ColorScales} from "../Utils/d3ColorScale";
5
- import { select, range} from "d3";
6
- import * as d3 from "d3";
7
- import discreteLegendUtil from "../Utils/discreteLegend";
8
- import { color } from "d3-color";
9
-
10
- declare type legendProps = {
11
- position: number[];
12
- colorsObject?: any;
13
- legendColor?: any;
14
- legendColorName?: string | undefined;
15
- useContColorTable?: boolean;
16
- useDiscColorTable?: boolean;
17
- valueIndex?: any;
18
- colorScaleData: any;
19
- }
20
-
21
- declare type ItemColor = {
22
- color: string;
23
- offset?: number;
24
- }
25
-
26
- export const ColorSelectorComponent: React.FC<legendProps> = ({
27
- colorsObject,
28
- legendColor,
29
- legendColorName,
30
- useContColorTable,
31
- useDiscColorTable,
32
- valueIndex,
33
- colorScaleData,
34
- }: legendProps) => {
35
-
36
- const divRef = useRef<HTMLDivElement>(null);
37
- // create an array of steps based on the color scale
38
- // returns an array of evenly-spaced numbers. Returns the integers from zero to the specified end minus one.
39
- // d3.range(start, stop, step)
40
- let data: any;
41
- var extent: any
42
- if (legendColor) {
43
- data = range(10).map((d) => ({
44
- color: legendColor(d / 10),
45
- value: d,
46
- }));
47
- // get the array's min and max value
48
- extent = d3.extent(data, (d: any) => d?.value);
49
- }
50
-
51
- const handleChange = React.useCallback(() => {
52
- // continous legend with colortable colors
53
- if (colorsObject && Object.keys(colorsObject).length > 0 && useContColorTable) {
54
- colorScaleData(colorsObject, true);
55
- }
56
- // continous legend with d3 colors
57
- else if (data && !useContColorTable) {
58
- const arrayData: any = []
59
- data.forEach((colorsObject: any) => {
60
- arrayData.push([0 + "." + colorsObject.value, color(colorsObject.color)?.rgb().r, color(colorsObject.color)?.rgb().g, color(colorsObject.color)?.rgb().b])
61
- });
62
- colorScaleData({ arrayData, legendColorName }, true);
63
- }
64
- // discrete legend with colortable colors
65
- else if (colorsObject && Object.keys(colorsObject).length > 0 && useDiscColorTable) {
66
- colorScaleData(colorsObject, false);
67
- }
68
- // discrete legend with d3 colors
69
- else {
70
- colorScaleData({colorsObject, legendColorName}, false);
71
- }
72
- }, []);
73
-
74
- React.useEffect(() => {
75
- // continuous legend using color table colors
76
- if (useContColorTable == true && divRef.current) {
77
- contColortableLegend();
78
- return function cleanup() {
79
- select(divRef.current).select("svg").remove();
80
- select(divRef.current).select("div").remove();
81
- };
82
- }
83
- // discrete legend using color table colors
84
- if (useDiscColorTable == true && divRef.current) {
85
- discColorTableLegend();
86
- return function cleanup() {
87
- select(divRef.current).select("div").remove();
88
- select(divRef.current).select("svg").remove();
89
- };
90
- }
91
- // discrete legend using d3 colors
92
- if (useDiscColorTable == false && divRef.current) {
93
- discD3legend();
94
- return function cleanup() {
95
- select(divRef.current).select("div").remove();
96
- select(divRef.current).select("svg").remove();
97
- }
98
- }
99
- // continuous legend using d3 colors
100
- else if (useContColorTable == false && divRef.current) {
101
- contD3Legend();
102
- return function cleanup() {
103
- select(divRef.current).select("svg").remove();
104
- select(divRef.current).select("div").remove();
105
- };
106
- }
107
- }, [useContColorTable]);
108
-
109
- // continuous legend using color table colors (using linear gradiend)
110
- function contColortableLegend() {
111
- const itemColor: ItemColor[] = [];
112
-
113
- colorsObject.color.forEach((value: [number, number, number, number]) => {
114
- // return the color and offset needed to draw the legend
115
- itemColor.push({
116
- offset: RGBToHex(value).offset,
117
- color: RGBToHex(value).color,
118
- });
119
- });
120
-
121
- // append a defs (for definition) element to your SVG
122
- const svgLegend = select(divRef.current)
123
- .append("svg")
124
- .style("height", "30px")
125
-
126
- const defs = svgLegend.append("defs");
127
- const currentIndex = "linear-gradient-" + valueIndex;
128
- // append a linearGradient element to the defs and give it a unique id
129
- const linearGradient = defs
130
- .append("linearGradient")
131
- .attr("id", currentIndex)
132
- .attr("x1", "0%")
133
- .attr("x2", "100%") //since it's a horizontal linear gradient
134
- .attr("y1", "0%")
135
- .attr("y2", "0%");
136
- // append multiple color stops by using D3's data/enter step
137
-
138
- linearGradient
139
- .selectAll("stop")
140
- .data(itemColor)
141
- .enter()
142
- .append("stop")
143
- .attr("offset", function (data) {
144
- return data.offset + "%";
145
- })
146
- .attr("stop-color", function (data) {
147
- return data.color;
148
- });
149
-
150
- // append title
151
- svgLegend
152
- .append("text")
153
- .attr("id", "legendTitle")
154
- .attr("x", 0)
155
- .attr("y", 15)
156
- .style("font-size", "smaller")
157
- .style("font-weight", "900")
158
- .text(colorsObject.name);
159
-
160
- // draw the rectangle and fill with gradient
161
- svgLegend
162
- .append("rect")
163
- .attr("x", 85)
164
- .attr("y", 5)
165
- .attr("width", "110")
166
- .attr("height", 20)
167
- .style("fill", "url(#"+currentIndex+")");
168
- }
169
-
170
- // continuous legend using d3 colors (using linear gradiend)
171
- function contD3Legend() {
172
- const itemColor: any = [];
173
-
174
- d3ColorScales.forEach((value: any) => {
175
- // return the color and offset needed to draw the legend
176
- itemColor.push(value.colors);
177
- });
178
-
179
- // append a defs (for definition) element to your SVG
180
- const svgLegend = select(divRef.current)
181
- .append("svg")
182
- .style("height", "50px")
183
-
184
- const defs = svgLegend.append("defs");
185
- const currentIndex = "linear-gradient-" + valueIndex;
186
- // append a linearGradient element to the defs and give it a unique id
187
- const linearGradient = defs
188
- .append("linearGradient")
189
- .attr("id", currentIndex)
190
- .attr("x1", "0%")
191
- .attr("x2", "100%") //since it's a horizontal linear gradient
192
- .attr("y1", "0%")
193
- .attr("y2", "0%");
194
-
195
- // append multiple color stops by using D3's data/enter step
196
- linearGradient.selectAll("stop")
197
- .data(data)
198
- .enter().append("stop")
199
- .attr("offset", (d: any) => ((d.value - extent[0]) / (extent[1] - extent[0]) * 100) + "%")
200
- .attr("stop-color", (d: any) => d.color);
201
-
202
- // append title
203
- svgLegend
204
- .append("text")
205
- .attr("id", "legendTitle")
206
- .attr("x", 0)
207
- .attr("y", 15)
208
- .style("font-size", "smaller")
209
- .style("font-weight", "900")
210
- .text(legendColorName ? legendColorName : '');
211
-
212
- // draw the rectangle and fill with gradient
213
- svgLegend
214
- .append("rect")
215
- .attr("x", 85)
216
- .attr("y", 5)
217
- .attr("width", "110")
218
- .attr("height", 20)
219
- .style("fill", "url(#"+currentIndex+")");
220
- }
221
-
222
- // discrete legend using color table colors
223
- function discColorTableLegend() {
224
- const itemColor: ItemColor[] = [];
225
- const itemName: any = [];
226
-
227
- colorsObject.color.forEach((element: any, key: any) => {
228
- itemColor.push({color: RGBToHex(element)});
229
- itemName.push(key);
230
- })
231
-
232
- function RGBToHex(rgb: number[]) {
233
- let r = rgb[1].toString(16),
234
- g = rgb[2].toString(16),
235
- b = rgb[3].toString(16);
236
- if (r.length == 1) r = "0" + r;
237
- if (g.length == 1) g = "0" + g;
238
- if (b.length == 1) b = "0" + b;
239
- return "#" + r + g + b;
240
- }
241
-
242
- //const ordinalValues = scaleOrdinal().domain(itemName);
243
- let count = itemName.length
244
- const colorLegend = discreteLegendUtil(itemColor, true)
245
- //const calcLegendHeight = 22 * itemColor.length + 4 * itemColor.length;
246
- const selectedLegend = select(divRef.current);
247
- // colorname as label for the legend (ex: facies)
248
- selectedLegend
249
- .append("label")
250
- .text(legendColorName ? legendColorName : '')
251
- .attr("y", 7)
252
- .style("float", "left")
253
- .style("width", "15px")
254
- .style("margin", "10px 0px")
255
- .style("white-space", "nowrap")
256
- .style("font-size", "smaller")
257
- .style("font-weight", "900")
258
-
259
- selectedLegend
260
- .append("svg")
261
- .style("margin-top", "13px")
262
- .style("margin-left", "70px")
263
- .attr("viewBox", `0 0 ${count} 1`)
264
- .attr("preserveAspectRatio", "none")
265
-
266
- .style("width", "109px")
267
- .style("height", "20px")
268
- .call(colorLegend);
269
- }
270
-
271
- // discrete legend using d3 colors
272
- function discD3legend() {
273
- const itemName: any = [];
274
- const itemColor: any = [];
275
- colorsObject.forEach((element: any, key: any) => {
276
- itemColor.push({color: element});
277
- itemName.push(key);
278
- });
279
- //const ordinalValues = scaleOrdinal(colorsObject).domain(itemName);
280
- const count = itemName.length
281
- const discreteLegend = discreteLegendUtil(itemColor, true);
282
- select("svg").append("g").attr("transform", "translate(50,70)").attr("class", "legend").call(discreteLegend);
283
- const selectedLegend = select(divRef.current);
284
- selectedLegend
285
- .append("text")
286
- .text(legendColorName ? legendColorName : '')
287
- .attr("y", 7)
288
- .style("float", "left")
289
- .style("width", "15px")
290
- .style("margin", "10px 0px")
291
- .style("font-size", "smaller")
292
- .style("font-weight", "900");
293
- selectedLegend
294
- .append("svg")
295
- .style("margin-top", "13px")
296
- .style("margin-left", "70px")
297
- .style("background", "grey")
298
- .attr("viewBox", `0 0 ${count} 1`)
299
- .attr("preserveAspectRatio", "none")
300
-
301
- .style("width", "109px")
302
- .style("height", "20px")
303
- .call(discreteLegend);
304
- }
305
-
306
- return (
307
- <div>
308
- <div id="legend" style={{height: 30}}
309
- ref={divRef} onClick={handleChange}></div>
310
- </div>
311
- );
312
- };
@@ -1,119 +0,0 @@
1
- import * as React from "react";
2
- import * as colorTables from "../color-tables.json";
3
- import {d3ColorScales} from "../Utils/d3ColorScale";
4
- import {ColorSelectorComponent} from "./ColorSelectorComponent";
5
-
6
- const position = [16, 206];
7
- const continuosColorData: any = [];
8
- const continuosD3ColorData: any = [];
9
- const discreteColorData: any = [];
10
- const discreteD3ColorData: any = [];
11
-
12
- declare type legendProps = {
13
- useColorTableColors: boolean,
14
- useD3Colors: boolean,
15
- colorScaleObject: any
16
- }
17
-
18
- // Continuous legend using color table data
19
- const colorTableContinuousData = colorTables.filter((element: any) => {
20
- return element.discrete == false;
21
- });
22
-
23
- colorTableContinuousData.forEach((element: any) => {
24
- continuosColorData.push({color: element.colors, name: element.name});
25
- });
26
-
27
- // Continuous legend using d3 data
28
- const d3continuousData = d3ColorScales.filter((element: any) => {
29
- return element.discrete == false;
30
- });
31
-
32
- d3continuousData.forEach((element: any) => {
33
- continuosD3ColorData.push({color: element.colors, name: element.name});
34
- });
35
-
36
- // Discrete legend using color table data
37
- const discreteData = colorTables.filter((element: any) => {
38
- return element.discrete == true;
39
- });
40
-
41
- discreteData.forEach((element: any) => {
42
- discreteColorData.push({color: element.colors, name: element.name});
43
- });
44
-
45
- // Discrete legend using d3 data
46
- const d3discreteData = d3ColorScales.filter((element: any) => {
47
- return element.discrete == true;
48
- });
49
-
50
- d3discreteData.forEach((element: any) => {
51
- discreteD3ColorData.push({color: element.colors, name: element.name});
52
- });
53
-
54
- export const ColorSelectorWrapper: React.FC<legendProps> = ({
55
- useColorTableColors,
56
- useD3Colors,
57
- colorScaleObject,
58
- }: legendProps) => {
59
- let continuousLegend;
60
- let discreteLegend;
61
-
62
- // return continuous and discrete legend which uses d3 data
63
- if (useD3Colors) {
64
- continuousLegend = continuosD3ColorData.map((val: any, key: any) => {
65
- return <ColorSelectorComponent
66
- position={position + key}
67
- legendColor={val.color}
68
- legendColorName={val.name}
69
- useContColorTable={false}
70
- valueIndex={key + "0"}
71
- colorScaleData={colorScaleObject.colorScaleObject}
72
- />
73
- });
74
-
75
- discreteLegend = d3discreteData.map((val: any, key: any) => {
76
- return <ColorSelectorComponent
77
- position={position + key}
78
- colorsObject={val.colors}
79
- legendColorName={val.name}
80
- useDiscColorTable={false}
81
- colorScaleData={colorScaleObject.colorScaleObject}
82
- />
83
- });
84
- }
85
-
86
- // return continuous and discrete legend which uses colortable data
87
- if (useColorTableColors) {
88
- continuousLegend = continuosColorData.map((value: any, key: any) => {
89
- return <div>
90
- <ColorSelectorComponent
91
- position={position + key}
92
- colorsObject={value}
93
- useContColorTable={true}
94
- valueIndex={key}
95
- colorScaleData={colorScaleObject.colorScaleObject}
96
- />
97
- </div>
98
- });
99
-
100
- discreteLegend = discreteColorData.map((val: any, key: any) => {
101
- return <ColorSelectorComponent
102
- position={position + key}
103
- colorsObject={discreteColorData[key]}
104
- legendColorName={val.name}
105
- useDiscColorTable={true}
106
- colorScaleData={colorScaleObject.colorScaleObject}
107
- />
108
- });
109
- }
110
-
111
- return (
112
- <div className="legendWrapper"
113
- style={{height: 200, overflow: "auto", display: "flex", flexDirection: "column", overflowX: "hidden"}}
114
- >
115
- {continuousLegend}
116
- {discreteLegend}
117
- </div>
118
- );
119
- };
@@ -1,89 +0,0 @@
1
- import * as React from "react";
2
- import { DiscreteColorLegend } from "./DiscreteLegend";
3
- import { ContinuousLegend } from "./ContinuousLegend";
4
- import {useCallback} from "react";
5
- import { ColorSelectorAccordion } from "../ColorSelector/ColorSelectorAccordion";
6
-
7
- declare type ColorLegendProps = {
8
- colorTables: any;
9
- min: number;
10
- max: number;
11
- dataObjectName: string;
12
- position?: number[] | null;
13
- colorName: string;
14
- horizontal?: boolean | null;
15
- discreteData: { objects: Record<string, [number[], number]> };
16
- getColorMapname?: any;
17
- }
18
-
19
- // Todo: Adapt it for other layers too
20
- export const ColorLegend: React.FC<ColorLegendProps> = ({
21
- position,
22
- horizontal,
23
- colorTables,
24
- min,
25
- max,
26
- dataObjectName,
27
- colorName,
28
- discreteData,
29
- getColorMapname
30
- }: ColorLegendProps) => {
31
-
32
- const [isToggled, setIsToggled] = React.useState(false);
33
- const handleClick = useCallback(() => {
34
- setIsToggled(true);
35
- }, []);
36
-
37
- const [updateLegend, setUpdateLegendColor] = React.useState([] as any);
38
- const [isCont, setIsCont] = React.useState(true);
39
-
40
- // Get new colorscale from colorselector and update legend
41
- const colorScaleObject = React.useCallback((data: any, value: any) => {
42
- // update color map layer
43
- if (data.name && getColorMapname) {
44
- getColorMapname(data.name);
45
- }
46
- // d3 color name
47
- else if (getColorMapname) {
48
- getColorMapname(data.legendColorName);
49
- }
50
- setUpdateLegendColor(data);
51
- setIsCont(value);
52
- }, []);
53
-
54
- return (
55
- <div>
56
- <div onClick={handleClick}>
57
- {isCont && (
58
- <ContinuousLegend
59
- min={min}
60
- max={max}
61
- dataObjectName={dataObjectName}
62
- position={position}
63
- colorName={colorName}
64
- colorTables={colorTables}
65
- horizontal={horizontal}
66
- updateLegend={updateLegend}
67
- />
68
- )}
69
- {!isCont && (
70
- <DiscreteColorLegend
71
- discreteData={discreteData}
72
- dataObjectName={dataObjectName}
73
- position={position}
74
- colorName={colorName}
75
- colorTables={colorTables}
76
- horizontal={horizontal}
77
- updateLegend={updateLegend}
78
- />
79
- )}
80
- </div>
81
- <div>
82
- {isToggled && (
83
- <ColorSelectorAccordion colorScaleObject={colorScaleObject} isHorizontal={horizontal} />
84
- )}
85
- </div>
86
- </div>
87
-
88
- );
89
- };