@emerson-eps/color-tables 0.2.12 → 0.2.15

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 (120) 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 -1
  7. package/dist/component/ColorSelector/ColorSelectorWrapper.js +9 -10
  8. package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -1
  9. package/dist/component/Legend/ColorLegend.js +2 -2
  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.map +1 -1
  13. package/dist/component/Legend/DiscreteLegend.d.ts +1 -1
  14. package/dist/component/Legend/DiscreteLegend.js +4 -8
  15. package/dist/component/Legend/DiscreteLegend.js.map +1 -1
  16. package/dist/component/Utils/continousLegend.d.ts +1 -1
  17. package/dist/component/Utils/discreteLegend.js +14 -27
  18. package/dist/component/Utils/discreteLegend.js.map +1 -1
  19. package/dist/component/{Utils/ColorTableTypes.d.ts → colorTableTypes.d.ts} +0 -0
  20. package/dist/component/colorTableTypes.js +2 -0
  21. package/dist/component/colorTableTypes.js.map +1 -0
  22. package/dist/index.d.ts +7 -5
  23. package/dist/index.js +3 -4
  24. package/dist/index.js.map +1 -1
  25. package/package.json +6 -3
  26. package/.storybook/main.js +0 -11
  27. package/.storybook/preview.js +0 -9
  28. package/.vscode/settings.json +0 -3
  29. package/dist/component/Utils/ColorTableTypes.js +0 -2
  30. package/dist/component/Utils/ColorTableTypes.js.map +0 -1
  31. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.d.ts +0 -7
  32. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js +0 -11
  33. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js.map +0 -1
  34. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.d.ts +0 -7
  35. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js +0 -38
  36. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +0 -1
  37. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.d.ts +0 -7
  38. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js +0 -38
  39. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +0 -1
  40. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.d.ts +0 -7
  41. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js +0 -38
  42. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +0 -1
  43. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.d.ts +0 -7
  44. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js +0 -38
  45. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +0 -1
  46. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.d.ts +0 -7
  47. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js +0 -38
  48. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +0 -1
  49. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.d.ts +0 -7
  50. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js +0 -38
  51. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +0 -1
  52. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.d.ts +0 -7
  53. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js +0 -38
  54. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +0 -1
  55. package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.d.ts +0 -7
  56. package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js +0 -47
  57. package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js.map +0 -1
  58. package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.d.ts +0 -7
  59. package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js +0 -47
  60. package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js.map +0 -1
  61. package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.d.ts +0 -7
  62. package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js +0 -39
  63. package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js.map +0 -1
  64. package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.d.ts +0 -7
  65. package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js +0 -39
  66. package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js.map +0 -1
  67. package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.d.ts +0 -7
  68. package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js +0 -42
  69. package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js.map +0 -1
  70. package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.d.ts +0 -7
  71. package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js +0 -53
  72. package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js.map +0 -1
  73. package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.d.ts +0 -7
  74. package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js +0 -42
  75. package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js.map +0 -1
  76. package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.d.ts +0 -7
  77. package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js +0 -52
  78. package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js.map +0 -1
  79. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.d.ts +0 -7
  80. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js +0 -52
  81. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js.map +0 -1
  82. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.d.ts +0 -7
  83. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js +0 -38
  84. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js.map +0 -1
  85. package/dist/stories/ColorLegends/SingleComponent/Single.stories.d.ts +0 -7
  86. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js +0 -58
  87. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js.map +0 -1
  88. package/src/component/ColorSelector/ColorSelectorAccordion.tsx +0 -54
  89. package/src/component/ColorSelector/ColorSelectorComponent.tsx +0 -312
  90. package/src/component/ColorSelector/ColorSelectorWrapper.tsx +0 -119
  91. package/src/component/Legend/ColorLegend.tsx +0 -106
  92. package/src/component/Legend/ContinuousLegend.tsx +0 -233
  93. package/src/component/Legend/DiscreteLegend.tsx +0 -209
  94. package/src/component/Utils/ColorTableTypes.ts +0 -6
  95. package/src/component/Utils/continousLegend.ts +0 -73
  96. package/src/component/Utils/d3ColorScale.ts +0 -84
  97. package/src/component/Utils/discreteLegend.ts +0 -84
  98. package/src/component/color-tables.json +0 -203
  99. package/src/custom.d.ts +0 -1
  100. package/src/index.ts +0 -26
  101. package/src/stories/ColorLegends/ColorSelector/Selector.stories.jsx +0 -12
  102. package/src/stories/ColorLegends/ContinousLegends/MD.stories.jsx +0 -29
  103. package/src/stories/ColorLegends/ContinousLegends/NTG.stories.jsx +0 -29
  104. package/src/stories/ColorLegends/ContinousLegends/PermTot.stories.jsx +0 -29
  105. package/src/stories/ColorLegends/ContinousLegends/Permeability.stories.jsx +0 -29
  106. package/src/stories/ColorLegends/ContinousLegends/PoroTot.stories.jsx +0 -29
  107. package/src/stories/ColorLegends/ContinousLegends/Porosity.stories.jsx +0 -29
  108. package/src/stories/ColorLegends/ContinousLegends/SW.stories.jsx +0 -29
  109. package/src/stories/ColorLegends/DiscreteLegends/Facies.stories.jsx +0 -39
  110. package/src/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.jsx +0 -39
  111. package/src/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.jsx +0 -31
  112. package/src/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.jsx +0 -31
  113. package/src/stories/ColorLegends/DiscreteLegends/RDE.stories.jsx +0 -34
  114. package/src/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.jsx +0 -45
  115. package/src/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.jsx +0 -34
  116. package/src/stories/ColorLegends/DiscreteLegends/Zonelog.stories.jsx +0 -46
  117. package/src/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.jsx +0 -44
  118. package/src/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.jsx +0 -30
  119. package/src/stories/ColorLegends/SingleComponent/Single.stories.jsx +0 -51
  120. package/tsconfig.json +0 -23
@@ -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
- const colorTables = require("../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
- colorScaleObject: any
15
- }
16
-
17
- // Continuous legend using color table data
18
- const colorTableContinuousData = colorTables.filter((element: any) => {
19
- return element.discrete == false;
20
- });
21
-
22
- colorTableContinuousData.forEach((element: any) => {
23
- continuosColorData.push({color: element.colors, name: element.name});
24
- });
25
-
26
- // Continuous legend using d3 data
27
- const d3continuousData = d3ColorScales.filter((element: any) => {
28
- return element.discrete == false;
29
- });
30
-
31
- d3continuousData.forEach((element: any) => {
32
- continuosD3ColorData.push({color: element.colors, name: element.name});
33
- });
34
-
35
- // Discrete legend using color table data
36
- const discreteData = colorTables.filter((element: any) => {
37
- return element.discrete == true;
38
- });
39
-
40
- discreteData.forEach((element: any) => {
41
- discreteColorData.push({color: element.colors, name: element.name});
42
- });
43
-
44
- // Discrete legend using d3 data
45
- const d3discreteData = d3ColorScales.filter((element: any) => {
46
- return element.discrete == true;
47
- });
48
-
49
- d3discreteData.forEach((element: any) => {
50
- discreteD3ColorData.push({color: element.colors, name: element.name});
51
- });
52
-
53
- export const ColorSelectorWrapper: React.FC<legendProps> = ({
54
- useColorTableColors,
55
- colorScaleObject,
56
- }: legendProps) => {
57
- let continuousLegend;
58
- let discreteLegend;
59
-
60
- // return continuous and discrete legend which uses d3 data
61
- if (useColorTableColors) {
62
-
63
- continuousLegend = continuosD3ColorData.map((val: any, key: any) => {
64
- return <ColorSelectorComponent
65
- position={position + key}
66
- legendColor={val.color}
67
- legendColorName={val.name}
68
- useContColorTable={false}
69
- valueIndex={key + "0"}
70
- colorScaleData={colorScaleObject.colorScaleObject}
71
- />
72
- });
73
-
74
- discreteLegend = d3discreteData.map((val: any, key: any) => {
75
- return <ColorSelectorComponent
76
- position={position + key}
77
- colorsObject={val.colors}
78
- legendColorName={val.name}
79
- useDiscColorTable={false}
80
- colorScaleData={colorScaleObject.colorScaleObject}
81
- />
82
- });
83
- }
84
-
85
- // return continuous and discrete legend which uses colortable data
86
- else if (!useColorTableColors) {
87
- continuousLegend = continuosColorData.map((value: any, key: any) => {
88
- return <div>
89
- <ColorSelectorComponent
90
- position={position + key}
91
- colorsObject={value}
92
- useContColorTable={true}
93
- valueIndex={key}
94
- colorScaleData={colorScaleObject.colorScaleObject}
95
- />
96
- </div>
97
- });
98
-
99
- discreteLegend = discreteColorData.map((val: any, key: any) => {
100
- return <ColorSelectorComponent
101
- position={position + key}
102
- colorsObject={discreteColorData[key]}
103
- legendColorName={val.name}
104
- useDiscColorTable={true}
105
- colorScaleData={colorScaleObject.colorScaleObject}
106
- />
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,106 +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
- import {d3ColorScales} from "../Utils/d3ColorScale";
7
-
8
- declare type ColorLegendProps = {
9
- colorTables: any;
10
- min: number;
11
- max: number;
12
- dataObjectName: string;
13
- position?: number[] | null;
14
- colorName: string;
15
- horizontal?: boolean | null;
16
- discreteData: { objects: Record<string, [number[], number]> };
17
- getColorMapname?: any;
18
- }
19
-
20
- // Todo: Adapt it for other layers too
21
- export const ColorLegend: React.FC<ColorLegendProps> = ({
22
- position,
23
- horizontal,
24
- colorTables,
25
- min,
26
- max,
27
- dataObjectName,
28
- colorName,
29
- discreteData,
30
- getColorMapname
31
- }: ColorLegendProps) => {
32
-
33
- const [isToggled, setIsToggled] = React.useState(false);
34
- const handleClick = useCallback(() => {
35
- setIsToggled(true);
36
- }, []);
37
-
38
- const [updateLegend, setUpdateLegendColor] = React.useState([] as any);
39
-
40
- const isColortableColors = colorTables.find(
41
- (value: any) => {
42
- return value?.name == colorName
43
- }
44
- );
45
-
46
- const isD3Colors = d3ColorScales.find(
47
- (value: any) => {
48
- return value?.name == colorName
49
- }
50
- );
51
-
52
- const [isCont, setIsCont] = React.useState(
53
- (isColortableColors || isD3Colors) &&
54
- (isColortableColors?.discrete == false || isD3Colors?.discrete == false) ? true : false
55
- );
56
-
57
- // Get new colorscale from colorselector and update legend
58
- const colorScaleObject = React.useCallback((data: any, value: any) => {
59
- // update color map layer
60
- if (data.name && getColorMapname) {
61
- getColorMapname(data.name);
62
- }
63
- // d3 color name
64
- else if (getColorMapname) {
65
- getColorMapname(data.legendColorName);
66
- }
67
- setUpdateLegendColor(data);
68
- setIsCont(value);
69
- }, []);
70
-
71
- return (
72
- <div>
73
- <div onClick={handleClick}>
74
- {isCont == true && (
75
- <ContinuousLegend
76
- min={min}
77
- max={max}
78
- dataObjectName={dataObjectName}
79
- position={position}
80
- colorName={colorName}
81
- colorTables={colorTables}
82
- horizontal={horizontal}
83
- updateLegend={updateLegend}
84
- />
85
- )}
86
- {isCont == false && (
87
- <DiscreteColorLegend
88
- discreteData={discreteData}
89
- dataObjectName={dataObjectName}
90
- position={position}
91
- colorName={colorName}
92
- colorTables={colorTables}
93
- horizontal={horizontal}
94
- updateLegend={updateLegend}
95
- />
96
- )}
97
- </div>
98
- <div>
99
- {isToggled && (
100
- <ColorSelectorAccordion colorScaleObject={colorScaleObject} isHorizontal={horizontal} />
101
- )}
102
- </div>
103
- </div>
104
-
105
- );
106
- };