@emerson-eps/color-tables 0.1.21 → 0.2.1

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 (69) hide show
  1. package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +7 -0
  2. package/dist/component/ColorSelector/ColorSelectorComponent.js +62 -0
  3. package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -0
  4. package/dist/component/ColorSelector/ColorTableSelectorWrapper.d.ts +2 -0
  5. package/dist/component/ColorSelector/ColorTableSelectorWrapper.js +25 -0
  6. package/dist/component/ColorSelector/ColorTableSelectorWrapper.js.map +1 -0
  7. package/dist/component/ColorSelector/legendComponent.d.ts +14 -0
  8. package/dist/component/ColorSelector/legendComponent.js +228 -0
  9. package/dist/component/ColorSelector/legendComponent.js.map +1 -0
  10. package/dist/component/Legend/ContinuousLegend.d.ts +2 -2
  11. package/dist/component/Legend/ContinuousLegend.js +2 -2
  12. package/dist/component/Legend/ContinuousLegend.js.map +1 -1
  13. package/dist/component/Legend/DiscreteLegend.d.ts +2 -2
  14. package/dist/component/Legend/DiscreteLegend.js +4 -4
  15. package/dist/component/Legend/DiscreteLegend.js.map +1 -1
  16. package/dist/component/Utils/d3ColorScale.d.ts +10 -0
  17. package/dist/component/Utils/d3ColorScale.js +84 -0
  18. package/dist/component/Utils/d3ColorScale.js.map +1 -0
  19. package/dist/component/Utils/discreteLegend.d.ts +2 -2
  20. package/dist/component/Utils/discreteLegend.js +26 -15
  21. package/dist/component/Utils/discreteLegend.js.map +1 -1
  22. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.d.ts +7 -0
  23. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js +11 -0
  24. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js.map +1 -0
  25. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/MD.stories.d.ts +0 -0
  26. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/MD.stories.js +0 -2
  27. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +1 -0
  28. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/NTG.stories.d.ts +0 -0
  29. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/NTG.stories.js +0 -2
  30. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +1 -0
  31. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/PermTot.stories.d.ts +0 -0
  32. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/PermTot.stories.js +0 -2
  33. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +1 -0
  34. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/Permeability.stories.d.ts +0 -0
  35. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/Permeability.stories.js +0 -2
  36. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +1 -0
  37. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/PoroTot.stories.d.ts +0 -0
  38. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/PoroTot.stories.js +0 -2
  39. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +1 -0
  40. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/Porosity.stories.d.ts +0 -0
  41. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/Porosity.stories.js +0 -2
  42. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +1 -0
  43. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/SW.stories.d.ts +0 -0
  44. package/dist/stories/ColorLegends/{ContinousLgends → ContinousLegends}/SW.stories.js +2 -4
  45. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +1 -0
  46. package/package.json +3 -1
  47. package/src/component/ColorSelector/ColorSelectorComponent.tsx +109 -0
  48. package/src/component/ColorSelector/ColorTableSelectorWrapper.tsx +49 -0
  49. package/src/component/ColorSelector/legendComponent.tsx +289 -0
  50. package/src/component/Legend/ContinuousLegend.tsx +4 -4
  51. package/src/component/Legend/DiscreteLegend.tsx +6 -6
  52. package/src/component/Utils/d3ColorScale.ts +84 -0
  53. package/src/component/Utils/discreteLegend.ts +34 -23
  54. package/src/stories/ColorLegends/ColorSelector/Selector.stories.jsx +12 -0
  55. package/src/stories/ColorLegends/{ContinousLgends → ContinousLegends}/MD.stories.jsx +0 -2
  56. package/src/stories/ColorLegends/{ContinousLgends → ContinousLegends}/NTG.stories.jsx +0 -2
  57. package/src/stories/ColorLegends/{ContinousLgends → ContinousLegends}/PermTot.stories.jsx +0 -2
  58. package/src/stories/ColorLegends/{ContinousLgends → ContinousLegends}/Permeability.stories.jsx +0 -2
  59. package/src/stories/ColorLegends/{ContinousLgends → ContinousLegends}/PoroTot.stories.jsx +0 -2
  60. package/src/stories/ColorLegends/{ContinousLgends → ContinousLegends}/Porosity.stories.jsx +0 -2
  61. package/src/stories/ColorLegends/{ContinousLgends → ContinousLegends}/SW.stories.jsx +2 -4
  62. package/tsconfig.json +1 -1
  63. package/dist/stories/ColorLegends/ContinousLgends/MD.stories.js.map +0 -1
  64. package/dist/stories/ColorLegends/ContinousLgends/NTG.stories.js.map +0 -1
  65. package/dist/stories/ColorLegends/ContinousLgends/PermTot.stories.js.map +0 -1
  66. package/dist/stories/ColorLegends/ContinousLgends/Permeability.stories.js.map +0 -1
  67. package/dist/stories/ColorLegends/ContinousLgends/PoroTot.stories.js.map +0 -1
  68. package/dist/stories/ColorLegends/ContinousLgends/Porosity.stories.js.map +0 -1
  69. package/dist/stories/ColorLegends/ContinousLgends/SW.stories.js.map +0 -1
@@ -0,0 +1,289 @@
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 * as d3 from "d3";
6
+ import { scaleOrdinal, select } from "d3";
7
+ import { colorTablesArray, colorTablesObj } from "../ColorTableTypes";
8
+ import discreteLegendUtil from "../Utils/discreteLegend";
9
+
10
+ interface legendProps {
11
+ position: number[];
12
+ colorsObject?: any;
13
+ legendColor?: any;
14
+ legendColorName: string;
15
+ useContColorTable?: boolean;
16
+ useDiscColorTable?: boolean;
17
+ valueIndex?: any;
18
+ }
19
+
20
+ interface ItemColor {
21
+ color: string;
22
+ offset?: number;
23
+ }
24
+
25
+ export const LegendComponent: React.FC<legendProps> = ({
26
+ position,
27
+ colorsObject,
28
+ legendColor,
29
+ legendColorName,
30
+ useContColorTable,
31
+ useDiscColorTable,
32
+ valueIndex,
33
+ }: legendProps) => {
34
+
35
+ const divRef = useRef<HTMLDivElement>(null);
36
+
37
+ React.useEffect(() => {
38
+ // continuous legend using color table colors
39
+ if (useContColorTable == true && divRef.current) {
40
+ contColortableLegend();
41
+ return function cleanup() {
42
+ d3.select(divRef.current).select("svg").remove();
43
+ };
44
+ }
45
+ // discrete legend using color table colors
46
+ if (useDiscColorTable == true && divRef.current) {
47
+ discColorTableLegend();
48
+ return function cleanup() {
49
+ select(divRef.current).select("div").remove();
50
+ select(divRef.current).select("svg").remove();
51
+ };
52
+ }
53
+ // discrete legend using d3 colors
54
+ if (useDiscColorTable == false && divRef.current) {
55
+ discD3legend();
56
+ return function cleanup() {
57
+ select(divRef.current).select("div").remove();
58
+ select(divRef.current).select("svg").remove();
59
+ }
60
+ }
61
+ // continuous legend using d3 colors
62
+ else if (useContColorTable == false && divRef.current) {
63
+ contD3Legend();
64
+ return function cleanup() {
65
+ d3.select(divRef.current).select("svg").remove();
66
+ };
67
+ }
68
+ }, [useContColorTable]);
69
+
70
+ // continuous legend using color table colors (linear gradiend code)
71
+ function contColortableLegend() {
72
+ const itemColor: ItemColor[] = [];
73
+
74
+ colorsObject.color.forEach((value: [number, number, number, number]) => {
75
+ // return the color and offset needed to draw the legend
76
+ itemColor.push({
77
+ offset: RGBToHex(value).offset,
78
+ color: RGBToHex(value).color,
79
+ });
80
+ });
81
+
82
+ // append a defs (for definition) element to your SVG
83
+ const svgLegend = d3.select(divRef.current)
84
+ .append("svg")
85
+ .style("height", "50px")
86
+ .style("display", "flex")
87
+
88
+ const defs = svgLegend.append("defs");
89
+ let currentIndex = "linear-gradient-" + valueIndex;
90
+ // append a linearGradient element to the defs and give it a unique id
91
+ const linearGradient = defs
92
+ .append("linearGradient")
93
+ .attr("id", currentIndex)
94
+ .attr("x1", "0%")
95
+ .attr("x2", "100%") //since it's a horizontal linear gradient
96
+ .attr("y1", "0%")
97
+ .attr("y2", "0%");
98
+ // append multiple color stops by using D3's data/enter step
99
+
100
+ linearGradient
101
+ .selectAll("stop")
102
+ .data(itemColor)
103
+ .enter()
104
+ .append("stop")
105
+ .attr("offset", function (data) {
106
+ return data.offset + "%";
107
+ })
108
+ .attr("stop-color", function (data) {
109
+ return data.color;
110
+ });
111
+
112
+ // append title
113
+ svgLegend
114
+ .append("text")
115
+ .attr("class", "legendTitle")
116
+ .attr("x", 0)
117
+ .attr("y", 43)
118
+ .style("text-anchor", "left")
119
+ .text(colorsObject.name);
120
+
121
+ // draw the rectangle and fill with gradient
122
+ svgLegend
123
+ .append("rect")
124
+ .attr("x", 180)
125
+ .attr("y", 30)
126
+ .attr("width", 150)
127
+ .attr("height", 25)
128
+ .style("fill", "url(#"+currentIndex+")");
129
+ }
130
+
131
+ // continuous legend using d3 colors (linear gradiend code)
132
+ function contD3Legend() {
133
+ const itemColor: any = [];
134
+
135
+ d3ColorScales.forEach((value: any) => {
136
+ // return the color and offset needed to draw the legend
137
+ itemColor.push(value.colors);
138
+ });
139
+
140
+ // create an array of steps based on the color scale
141
+ // returns an array of evenly-spaced numbers. Returns the integers from zero to the specified end minus one.
142
+ // d3.range(start, stop, step)
143
+ var data = d3.range(10).map(d=> ({color:legendColor(d/10), value:d}))
144
+ // get the array's min and max value
145
+ var extent: any = d3.extent(data, d => d.value);
146
+
147
+ // append a defs (for definition) element to your SVG
148
+ const svgLegend = d3.select(divRef.current)
149
+ .append("svg")
150
+ .style("height", "50px")
151
+ .style("display", "flex")
152
+
153
+ const defs = svgLegend.append("defs");
154
+ let currentIndex = "linear-gradient-" + valueIndex;
155
+ // append a linearGradient element to the defs and give it a unique id
156
+ const linearGradient = defs
157
+ .append("linearGradient")
158
+ .attr("id", currentIndex)
159
+ .attr("x1", "0%")
160
+ .attr("x2", "100%") //since it's a horizontal linear gradient
161
+ .attr("y1", "0%")
162
+ .attr("y2", "0%");
163
+
164
+ // append multiple color stops by using D3's data/enter step
165
+ linearGradient.selectAll("stop")
166
+ .data(data)
167
+ .enter().append("stop")
168
+ .attr("offset", d => ((d.value - extent[0]) / (extent[1] - extent[0]) * 100) + "%")
169
+ .attr("stop-color", d => d.color);
170
+
171
+ // append title
172
+ svgLegend
173
+ .append("text")
174
+ .attr("class", "legendTitle")
175
+ .attr("x", 0)
176
+ .attr("y", 43)
177
+ .style("text-anchor", "left")
178
+ .text(legendColorName);
179
+
180
+
181
+ // draw the rectangle and fill with gradient
182
+ svgLegend
183
+ .append("rect")
184
+ .attr("x", 180)
185
+ .attr("y", 30)
186
+ .attr("width", 150)
187
+ .attr("height", 25)
188
+ .style("fill", "url(#"+currentIndex+")");
189
+ }
190
+
191
+ // discrete legend using color table colors
192
+ function discColorTableLegend() {
193
+ const itemColor: ItemColor[] = [];
194
+ const itemName: any = [];
195
+
196
+ colorsObject.color.forEach((element: any, key: any) => {
197
+ itemColor.push({color: RGBToHex(element)});
198
+ itemName.push(key);
199
+ })
200
+
201
+ function RGBToHex(rgb: number[]) {
202
+ let r = rgb[1].toString(16),
203
+ g = rgb[2].toString(16),
204
+ b = rgb[3].toString(16);
205
+ if (r.length == 1) r = "0" + r;
206
+ if (g.length == 1) g = "0" + g;
207
+ if (b.length == 1) b = "0" + b;
208
+ return "#" + r + g + b;
209
+ }
210
+
211
+ const ordinalValues = scaleOrdinal().domain(itemName);
212
+ const colorLegend = discreteLegendUtil(itemColor, "ColorSelector").inputScale(ordinalValues);
213
+ select("svg").append("g").attr("transform", "translate(50,70)").attr("class", "legend").call(colorLegend);
214
+ //const calcLegendHeight = 22 * itemColor.length + 4 * itemColor.length;
215
+ const selectedLegend = select(divRef.current);
216
+ selectedLegend
217
+ .append("text")
218
+ .text(legendColorName)
219
+ .attr("y", 7)
220
+ .style("float", "left")
221
+ .style("width", "30%")
222
+ .style("margin", "10px 0px");
223
+ selectedLegend
224
+ .append("svg")
225
+ .style("margin-top", "13px")
226
+ .style("margin-right", "103px")
227
+ .style("float", "right")
228
+ // .style("width", "60%")
229
+ .style("height", "25px")
230
+ .call(colorLegend);
231
+ }
232
+
233
+ // discrete legend using d3 colors
234
+ function discD3legend() {
235
+ const itemName: any = [];
236
+ const itemColor: any = [];
237
+
238
+ colorsObject.forEach((element: any, key: any) => {
239
+ itemColor.push({color: element});
240
+ itemName.push(key);
241
+ });
242
+
243
+ const ordinalValues = scaleOrdinal(colorsObject).domain(itemName);
244
+ const discreteLegend = discreteLegendUtil(itemColor, "ColorSelector").inputScale(ordinalValues);
245
+ select("svg").append("g").attr("transform", "translate(50,70)").attr("class", "legend").call(discreteLegend);
246
+ const selectedLegend = select(divRef.current);
247
+ selectedLegend
248
+ .append("text")
249
+ .text(legendColorName)
250
+ .attr("y", 7)
251
+ .style("float", "left")
252
+ .style("width", "30%")
253
+ .style("margin", "10px 0px");
254
+ selectedLegend
255
+ .append("svg")
256
+ .style("margin-top", "13px")
257
+ .style("margin-right", "103px")
258
+ .style("float", "right")
259
+ // .style("width", "60%")
260
+ .style("height", "25px")
261
+ .call(discreteLegend);
262
+ }
263
+
264
+ return (
265
+ <div
266
+ style={{
267
+ right: position[0],
268
+ top: position[1],
269
+ borderRadius: "5px",
270
+ height: "35px",
271
+ marginTop: "15px"
272
+ }}
273
+ >
274
+ <div id="legend" ref={divRef}></div>
275
+ </div>
276
+ );
277
+ };
278
+
279
+ // Based on name return the colors array from color.tables.json file
280
+ export function colorTableData(
281
+ colorName: string,
282
+ colorTables: colorTablesArray
283
+ ): [number, number, number, number][] {
284
+ const colorTableData = colorTables.filter(
285
+ (value: colorTablesObj) =>
286
+ value.name.toLowerCase() == colorName.toLowerCase()
287
+ );
288
+ return colorTableData.length > 0 ? colorTableData[0].colors : [];
289
+ }
@@ -8,10 +8,10 @@ declare type legendProps = {
8
8
  min: number;
9
9
  max: number;
10
10
  dataObjectName: string;
11
- position: number[];
11
+ position?: number[] | null;
12
12
  colorName: string;
13
13
  colorTables: colorTablesArray;
14
- horizontal: boolean;
14
+ horizontal?: boolean | null;
15
15
  }
16
16
 
17
17
  declare type ItemColor = {
@@ -118,8 +118,8 @@ export const ContinuousLegend: React.FC<legendProps> = ({
118
118
  <div
119
119
  style={{
120
120
  position: "absolute",
121
- right: position[0],
122
- top: position[1],
121
+ right: position ? position[0] : ' ',
122
+ top: position ? position[1] : ' ',
123
123
  }}
124
124
  >
125
125
  <div id="legend" ref={divRef}></div>
@@ -11,10 +11,10 @@ declare type ItemColor = {
11
11
  declare type colorLegendProps = {
12
12
  discreteData: { objects: Record<string, [number[], number]> };
13
13
  dataObjectName: string;
14
- position: number[];
14
+ position?: number[] | null;
15
15
  colorName: string;
16
16
  colorTables: colorTablesArray;
17
- horizontal: boolean;
17
+ horizontal?: boolean | null;
18
18
  }
19
19
 
20
20
  export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
@@ -76,12 +76,12 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
76
76
  .attr("y", 7)
77
77
  .style("color", "#6F6F6F")
78
78
  .style("margin", "10px 10px");
79
- if (!horizontal) selectedLegend.style("height", 150 + "px");
79
+ if (horizontal) selectedLegend.style("height", 150 + "px");
80
80
  const svgLegend = selectedLegend
81
81
  .append("svg")
82
82
  .style("margin", "10px 10px")
83
83
  .call(colorLegend);
84
- if (colorLegend && horizontal) {
84
+ if (colorLegend && !horizontal) {
85
85
  svgLegend
86
86
  .attr("height", calcLegendHeight + "px")
87
87
  .attr("width", 220 + "px");
@@ -96,8 +96,8 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
96
96
  <div
97
97
  style={{
98
98
  position: "absolute",
99
- right: position[0],
100
- top: position[1],
99
+ right: position ? position[0] : ' ',
100
+ top: position ? position[1] : ' ',
101
101
  backgroundColor: "#ffffffcc",
102
102
  borderRadius: "5px",
103
103
  }}
@@ -0,0 +1,84 @@
1
+ import * as d3 from "d3";
2
+
3
+ export const d3ColorScales = [
4
+ {
5
+ "name": "Spectral",
6
+ "discrete": false,
7
+ "colors": d3.interpolateSpectral
8
+ },
9
+ {
10
+ "name": "RdYlBu",
11
+ "discrete": false,
12
+ "colors": d3.interpolateRdYlBu
13
+ },
14
+ {
15
+ "name": "Warm",
16
+ "discrete": false,
17
+ "colors": d3.interpolateWarm
18
+ },
19
+ {
20
+ "name": "Cool",
21
+ "discrete": false,
22
+ "colors": d3.interpolateCool
23
+ },
24
+ {
25
+ "name": "Viridis",
26
+ "discrete": false,
27
+ "colors": d3.interpolateViridis
28
+ },
29
+ {
30
+ "name": "Inferno",
31
+ "discrete": false,
32
+ "colors": d3.interpolateInferno
33
+ },
34
+ {
35
+ "name": "Accent",
36
+ "discrete": true,
37
+ "colors": d3.schemeAccent
38
+ },
39
+ {
40
+ "name": "Dark2",
41
+ "discrete": true,
42
+ "colors": d3.schemeDark2
43
+ },
44
+ {
45
+ "name": "Paired",
46
+ "discrete": true,
47
+ "colors": d3.schemePaired
48
+ },
49
+ {
50
+ "name": "Pastel1",
51
+ "discrete": true,
52
+ "colors": d3.schemePastel1
53
+ },
54
+ {
55
+ "name": "Pastel2",
56
+ "discrete": true,
57
+ "colors": d3.schemePastel2
58
+ },
59
+ {
60
+ "name": "Set1",
61
+ "discrete": true,
62
+ "colors": d3.schemeSet1
63
+ },
64
+ {
65
+ "name": "Set2",
66
+ "discrete": true,
67
+ "colors": d3.schemeSet3
68
+ },
69
+ {
70
+ "name": "Set3",
71
+ "discrete": true,
72
+ "colors": d3.schemeSet3
73
+ },
74
+ {
75
+ "name": "Tableau10",
76
+ "discrete": true,
77
+ "colors": d3.schemeTableau10
78
+ },
79
+ {
80
+ "name": "Category10",
81
+ "discrete": true,
82
+ "colors": d3.schemeCategory10
83
+ },
84
+ ]
@@ -1,12 +1,12 @@
1
1
  declare type ItemColor = {
2
- color: string;
2
+ color: any;
3
3
  }
4
4
 
5
5
  // eslint-disable-next-line
6
- export default function legendUtil(itemColor: ItemColor[]): any {
6
+ export default function discreteLegendUtil(itemColor: ItemColor[], ColorSelector?: string): any {
7
7
  let legendValues: ItemColor[] = [];
8
8
  const cellWidth = 22;
9
- const cellHeight = 22;
9
+ const cellHeight: any = 22;
10
10
  const cellPadding = 4;
11
11
 
12
12
  // eslint-disable-next-line
@@ -20,30 +20,41 @@ export default function legendUtil(itemColor: ItemColor[]): any {
20
20
  .append("rect")
21
21
  .attr("height", cellHeight)
22
22
  .attr("width", cellWidth)
23
- .style("stroke", "black")
24
- .style("stroke-width", "1px")
25
23
  .style("fill", function (d: Record<string, unknown>) {
26
24
  return d["color"];
27
25
  });
26
+ if (!ColorSelector) {
27
+ g.selectAll("g.legendCells.rect").style("stroke", "black").style("stroke-width", "1px")
28
+ }
28
29
  // Display the label
29
- g.selectAll("g.legendCells")
30
- .append("text")
31
- .attr("class", "breakLabels")
32
- .style("fill", "#6F6F6F")
33
- .attr("x", cellWidth + cellPadding)
34
- .attr("y", 5 + cellHeight / 2)
35
- .text(function (d: Record<string, unknown>) {
36
- return d["label"];
37
- });
30
+ if (!ColorSelector) {
31
+ g.selectAll("g.legendCells")
32
+ .append("text")
33
+ .attr("class", "breakLabels")
34
+ .style("fill", "#6F6F6F")
35
+ .attr("x", cellWidth + cellPadding)
36
+ .attr("y", 5 + cellHeight / 2)
37
+ .text(function (d: Record<string, unknown>) {
38
+ return d["label"];
39
+ });
40
+ }
38
41
  // Alighment of cell in straight line
39
- g.selectAll("g.legendCells").attr(
40
- "transform",
41
- function (_d: Record<string, unknown>, i: number) {
42
- return (
43
- "translate(0," + i * (cellHeight + cellPadding) + ")"
44
- );
45
- }
46
- );
42
+ if (!ColorSelector) {
43
+ g.selectAll("g.legendCells").attr(
44
+ "transform",
45
+ function (_d: Record<string, unknown>, i: number) {
46
+ return (
47
+ "translate(0," + i * (cellHeight + cellPadding) + ")"
48
+ );
49
+ }
50
+ );
51
+ }
52
+ if (ColorSelector) {
53
+ g.selectAll("g.legendCells")
54
+ .attr("transform", function(d: any) {
55
+ return "translate(" + (d.label * cellWidth) + ",0)" }
56
+ );
57
+ }
47
58
  }
48
59
  // display the discrete legend
49
60
  g.selectAll("g.legendCells")
@@ -66,4 +77,4 @@ export default function legendUtil(itemColor: ItemColor[]): any {
66
77
  return this;
67
78
  };
68
79
  return legend;
69
- }
80
+ }
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+ import { ColorSelectorWrapper } from "../../../component/ColorSelector/ColorTableSelectorWrapper";
3
+ export default {
4
+ component: ColorSelectorWrapper,
5
+ title: "Legends/ColorSelector",
6
+ };
7
+
8
+ const Template = (args) => {
9
+ return <ColorSelectorWrapper />;
10
+ };
11
+
12
+ export const selectorTemplate = Template.bind({});
@@ -10,7 +10,6 @@ const min = 2918;
10
10
  const max = 4770;
11
11
  const dataObjectName = "Wells / MD";
12
12
  const position = [16, 10];
13
- const name = "MD";
14
13
  const horizontal = true;
15
14
  const colorName = "Time/Depth";
16
15
 
@@ -24,7 +23,6 @@ MDTemplate.args = {
24
23
  max,
25
24
  dataObjectName,
26
25
  position,
27
- name,
28
26
  colorName,
29
27
  colorTables,
30
28
  horizontal,
@@ -10,7 +10,6 @@ const min = 0;
10
10
  const max = 1;
11
11
  const dataObjectName = "Wells / NTG";
12
12
  const position = [16, 10];
13
- const name = "NTG";
14
13
  const horizontal = true;
15
14
  const colorName = "Rainbow";
16
15
 
@@ -24,7 +23,6 @@ NTGTemplate.args = {
24
23
  max,
25
24
  dataObjectName,
26
25
  position,
27
- name,
28
26
  colorName,
29
27
  colorTables,
30
28
  horizontal,
@@ -10,7 +10,6 @@ const min = -999;
10
10
  const max = 14023;
11
11
  const dataObjectName = "Wells / PERMTOT";
12
12
  const position = [16, 10];
13
- const name = "PERM_TOT";
14
13
  const horizontal = true;
15
14
  const colorName = "Porosity";
16
15
 
@@ -24,7 +23,6 @@ PermTotTemplate.args = {
24
23
  max,
25
24
  dataObjectName,
26
25
  position,
27
- name,
28
26
  colorName,
29
27
  colorTables,
30
28
  horizontal,
@@ -10,7 +10,6 @@ const min = -999;
10
10
  const max = 14023;
11
11
  const dataObjectName = "Wells / PERM";
12
12
  const position = [16, 10];
13
- const name = "PERM";
14
13
  const horizontal = true;
15
14
  const colorName = "Permeability";
16
15
 
@@ -24,7 +23,6 @@ PermeabilityTemplate.args = {
24
23
  max,
25
24
  dataObjectName,
26
25
  position,
27
- name,
28
26
  colorName,
29
27
  colorTables,
30
28
  horizontal,
@@ -10,7 +10,6 @@ const min = 0;
10
10
  const max = 0.35;
11
11
  const dataObjectName = "Wells / POROTOT";
12
12
  const position = [16, 10];
13
- const name = "PORO";
14
13
  const horizontal = true;
15
14
  const colorName = "Porosity";
16
15
 
@@ -24,7 +23,6 @@ PoroTotTemplate.args = {
24
23
  max,
25
24
  dataObjectName,
26
25
  position,
27
- name,
28
26
  colorName,
29
27
  colorTables,
30
28
  horizontal,
@@ -10,7 +10,6 @@ const min = 0;
10
10
  const max = 0.35;
11
11
  const dataObjectName = "Wells / PORO";
12
12
  const position = [16, 10];
13
- const name = "PORO";
14
13
  const horizontal = true;
15
14
  const colorName = "Porosity";
16
15
 
@@ -24,7 +23,6 @@ PorosityTemplate.args = {
24
23
  max,
25
24
  dataObjectName,
26
25
  position,
27
- name,
28
26
  colorName,
29
27
  colorTables,
30
28
  horizontal,
@@ -10,9 +10,8 @@ const min = 0;
10
10
  const max = 1;
11
11
  const dataObjectName = "Wells / SW";
12
12
  const position = [16, 10];
13
- const name = "SW";
14
13
  const horizontal = true;
15
- const colorName = "Physics";
14
+ const colorName = "Rainbow";
16
15
 
17
16
  const Template = (args) => {
18
17
  return <ContinuousLegend {...args} />;
@@ -24,8 +23,7 @@ SWTemplate.args = {
24
23
  max,
25
24
  dataObjectName,
26
25
  position,
27
- name,
28
- Physics,
26
+ colorName,
29
27
  colorTables,
30
28
  horizontal,
31
29
  };
package/tsconfig.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "declaration": true,
10
10
  "moduleResolution": "node",
11
11
  "forceConsistentCasingInFileNames": true,
12
- "noImplicitReturns": true,
12
+ "noImplicitReturns": false,
13
13
  "noImplicitThis": true,
14
14
  "noImplicitAny": true,
15
15
  "strictNullChecks": true,
@@ -1 +0,0 @@
1
- {"version":3,"file":"MD.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/ContinousLgends/MD.stories.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,eAAe;IACX,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,yBAAyB;CACnC,CAAC;AACF,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAE/D,MAAM,GAAG,GAAG,IAAI,CAAC;AACjB,MAAM,GAAG,GAAG,IAAI,CAAC;AACjB,MAAM,cAAc,GAAG,YAAY,CAAC;AACpC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,MAAM,IAAI,GAAG,IAAI,CAAC;AAClB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,YAAY,CAAC;AAE/B,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE;IACtB,OAAO,oBAAC,gBAAgB,oBAAK,IAAI,EAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5C,UAAU,CAAC,IAAI,GAAG;IACd,GAAG;IACH,GAAG;IACH,cAAc;IACd,QAAQ;IACR,IAAI;IACJ,SAAS;IACT,WAAW;IACX,UAAU;CACb,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"NTG.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/ContinousLgends/NTG.stories.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,eAAe;IACX,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,yBAAyB;CACnC,CAAC;AACF,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAE/D,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,cAAc,GAAG,aAAa,CAAC;AACrC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,MAAM,IAAI,GAAG,KAAK,CAAC;AACnB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,SAAS,CAAC;AAE5B,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE;IACtB,OAAO,oBAAC,gBAAgB,oBAAK,IAAI,EAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7C,WAAW,CAAC,IAAI,GAAG;IACf,GAAG;IACH,GAAG;IACH,cAAc;IACd,QAAQ;IACR,IAAI;IACJ,SAAS;IACT,WAAW;IACX,UAAU;CACb,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"PermTot.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/ContinousLgends/PermTot.stories.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,eAAe;IACX,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,yBAAyB;CACnC,CAAC;AACF,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAE/D,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC;AACjB,MAAM,GAAG,GAAG,KAAK,CAAC;AAClB,MAAM,cAAc,GAAG,iBAAiB,CAAC;AACzC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,MAAM,IAAI,GAAG,UAAU,CAAC;AACxB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE;IACtB,OAAO,oBAAC,gBAAgB,oBAAK,IAAI,EAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACjD,eAAe,CAAC,IAAI,GAAG;IACnB,GAAG;IACH,GAAG;IACH,cAAc;IACd,QAAQ;IACR,IAAI;IACJ,SAAS;IACT,WAAW;IACX,UAAU;CACb,CAAC"}