@emerson-eps/color-tables 0.2.3 → 0.2.6

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 (92) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/dist/component/ColorSelector/ColorSelectorAccordion.d.ts +2 -0
  3. package/dist/component/ColorSelector/{ColorTableSelectorWrapper.js → ColorSelectorAccordion.js} +12 -7
  4. package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -0
  5. package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +14 -5
  6. package/dist/component/ColorSelector/ColorSelectorComponent.js +260 -51
  7. package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
  8. package/dist/component/ColorSelector/ColorSelectorWrapper.d.ts +8 -0
  9. package/dist/component/ColorSelector/ColorSelectorWrapper.js +65 -0
  10. package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -0
  11. package/dist/component/Legend/ColorLegend.d.ts +16 -0
  12. package/dist/component/Legend/ColorLegend.js +35 -0
  13. package/dist/component/Legend/ColorLegend.js.map +1 -0
  14. package/dist/component/Legend/ContinuousLegend.d.ts +1 -0
  15. package/dist/component/Legend/ContinuousLegend.js +190 -83
  16. package/dist/component/Legend/ContinuousLegend.js.map +1 -1
  17. package/dist/component/Legend/DiscreteLegend.d.ts +2 -0
  18. package/dist/component/Legend/DiscreteLegend.js +173 -71
  19. package/dist/component/Legend/DiscreteLegend.js.map +1 -1
  20. package/dist/component/Utils/continousLegend.js +14 -12
  21. package/dist/component/Utils/continousLegend.js.map +1 -1
  22. package/dist/component/Utils/d3ColorScale.js +1 -1
  23. package/dist/component/Utils/d3ColorScale.js.map +1 -1
  24. package/dist/component/Utils/discreteLegend.d.ts +1 -1
  25. package/dist/component/Utils/discreteLegend.js +117 -41
  26. package/dist/component/Utils/discreteLegend.js.map +1 -1
  27. package/dist/component/color-tables.json +4 -4
  28. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.d.ts +2 -2
  29. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js +5 -5
  30. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js.map +1 -1
  31. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js +27 -16
  32. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +1 -1
  33. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js +27 -16
  34. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +1 -1
  35. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js +27 -16
  36. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +1 -1
  37. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js +27 -16
  38. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +1 -1
  39. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js +27 -16
  40. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +1 -1
  41. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js +27 -16
  42. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +1 -1
  43. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js +27 -16
  44. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +1 -1
  45. package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js +35 -24
  46. package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js.map +1 -1
  47. package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js +25 -14
  48. package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js.map +1 -1
  49. package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js +25 -14
  50. package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js.map +1 -1
  51. package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js +25 -14
  52. package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js.map +1 -1
  53. package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js +25 -14
  54. package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js.map +1 -1
  55. package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js +25 -14
  56. package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js.map +1 -1
  57. package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js +25 -14
  58. package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js.map +1 -1
  59. package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js +25 -14
  60. package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js.map +1 -1
  61. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.d.ts +7 -0
  62. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js +52 -0
  63. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js.map +1 -0
  64. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.d.ts +7 -0
  65. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js +38 -0
  66. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js.map +1 -0
  67. package/dist/stories/ColorLegends/SingleComponent/Single.stories.d.ts +7 -0
  68. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js +58 -0
  69. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js.map +1 -0
  70. package/package.json +2 -1
  71. package/src/component/ColorSelector/{ColorTableSelectorWrapper.tsx → ColorSelectorAccordion.tsx} +11 -6
  72. package/src/component/ColorSelector/ColorSelectorComponent.tsx +315 -95
  73. package/src/component/ColorSelector/ColorSelectorWrapper.tsx +118 -0
  74. package/src/component/Legend/ColorLegend.tsx +91 -0
  75. package/src/component/Legend/ContinuousLegend.tsx +159 -80
  76. package/src/component/Legend/DiscreteLegend.tsx +168 -63
  77. package/src/component/Utils/continousLegend.ts +1 -1
  78. package/src/component/Utils/discreteLegend.ts +128 -53
  79. package/src/component/color-tables.json +4 -4
  80. package/src/stories/ColorLegends/ColorSelector/Selector.stories.jsx +3 -3
  81. package/src/stories/ColorLegends/DiscreteLegends/Facies.stories.jsx +39 -39
  82. package/src/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.jsx +1 -1
  83. package/src/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.jsx +44 -0
  84. package/src/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.jsx +30 -0
  85. package/src/stories/ColorLegends/SingleComponent/Single.stories.jsx +51 -0
  86. package/tsconfig.json +1 -1
  87. package/dist/component/ColorSelector/ColorTableSelectorWrapper.d.ts +0 -2
  88. package/dist/component/ColorSelector/ColorTableSelectorWrapper.js.map +0 -1
  89. package/dist/component/ColorSelector/legendComponent.d.ts +0 -14
  90. package/dist/component/ColorSelector/legendComponent.js +0 -228
  91. package/dist/component/ColorSelector/legendComponent.js.map +0 -1
  92. package/src/component/ColorSelector/legendComponent.tsx +0 -289
@@ -7,105 +7,212 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
10
37
  import * as React from "react";
11
38
  import { useRef } from "react";
12
39
  import { RGBToHex, colorsArray } from "../Utils/continousLegend";
13
- import { select, scaleLinear, scaleSequential, axisBottom } from "d3";
14
- export const ContinuousLegend = ({ min, max, dataObjectName, position, colorName, colorTables, horizontal, }) => {
15
- const divRef = useRef(null);
16
- React.useEffect(() => {
40
+ import { select, scaleLinear, scaleSequential, axisBottom, axisRight } from "d3";
41
+ export var ContinuousLegend = function (_a) {
42
+ var min = _a.min, max = _a.max, dataObjectName = _a.dataObjectName, position = _a.position, colorName = _a.colorName, colorTables = _a.colorTables, horizontal = _a.horizontal, updateLegend = _a.updateLegend;
43
+ var divRef = useRef(null);
44
+ React.useEffect(function () {
17
45
  if (divRef.current) {
18
46
  continuousLegend();
19
47
  }
20
48
  ;
21
49
  return function cleanup() {
50
+ select(divRef.current).select("div").remove();
22
51
  select(divRef.current).select("svg").remove();
23
52
  };
24
- }, [min, max, colorName, colorTables, horizontal]);
53
+ }, [min, max, colorName, colorTables, horizontal, updateLegend]);
25
54
  function continuousLegend() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const itemColor = [];
28
- let dataSet;
29
- if (typeof colorTables === "string") {
30
- let res = yield fetch(colorTables);
31
- dataSet = yield res.json();
32
- }
33
- // Return the matched colors array from color.tables.json file
34
- let colorTableColors = typeof colorTables === "string" ?
35
- colorsArray(colorName, dataSet)
36
- :
37
- colorsArray(colorName, colorTables);
38
- colorTableColors.forEach((value) => {
39
- // return the color and offset needed to draw the legend
40
- itemColor.push({
41
- offset: RGBToHex(value).offset,
42
- color: RGBToHex(value).color,
43
- });
44
- });
45
- const colorScale = scaleSequential().domain([min, max]);
46
- // append a defs (for definition) element to your SVG
47
- const svgLegend = select(divRef.current)
48
- .append("svg")
49
- .style("background-color", "#ffffffcc")
50
- .style("border-radius", "5px");
51
- if (!horizontal) {
52
- svgLegend
53
- .style("transform", "rotate(270deg)")
54
- .style("margin-top", "80px");
55
- }
56
- const defs = svgLegend.append("defs");
57
- // append a linearGradient element to the defs and give it a unique id
58
- const linearGradient = defs
59
- .append("linearGradient")
60
- .attr("id", "linear-gradient")
61
- .attr("x1", "0%")
62
- .attr("x2", "100%") //since it's a horizontal linear gradient
63
- .attr("y1", "0%")
64
- .attr("y2", "0%");
65
- // append multiple color stops by using D3's data/enter step
66
- linearGradient
67
- .selectAll("stop")
68
- .data(itemColor)
69
- .enter()
70
- .append("stop")
71
- .attr("offset", function (data) {
72
- return data.offset + "%";
73
- })
74
- .attr("stop-color", function (data) {
75
- return data.color;
55
+ return __awaiter(this, void 0, void 0, function () {
56
+ var itemColor, dataSet, res, legendColors, colorScale, svgLegend, defs, linearGradient, xLeg, yLeg, horizontalAxisLeg, VerticalAxisLeg, error_1;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
59
+ case 0:
60
+ itemColor = [];
61
+ _a.label = 1;
62
+ case 1:
63
+ _a.trys.push([1, 5, , 6]);
64
+ if (!(typeof colorTables === "string")) return [3 /*break*/, 4];
65
+ return [4 /*yield*/, fetch(colorTables)];
66
+ case 2:
67
+ res = _a.sent();
68
+ return [4 /*yield*/, res.json()];
69
+ case 3:
70
+ dataSet = _a.sent();
71
+ _a.label = 4;
72
+ case 4:
73
+ legendColors = typeof colorTables === "string" ?
74
+ colorsArray(colorName, dataSet)
75
+ :
76
+ colorsArray(colorName, colorTables);
77
+ // Update color of legend based on color selector scales
78
+ // data is passed on click upon color scales
79
+ if (updateLegend) {
80
+ // legend using color table data
81
+ if (updateLegend.color) {
82
+ legendColors = updateLegend.color;
83
+ }
84
+ // legend using d3 data
85
+ else if (updateLegend.arrayData) {
86
+ legendColors = updateLegend.arrayData;
87
+ }
88
+ }
89
+ // main continuous legend
90
+ else {
91
+ legendColors;
92
+ }
93
+ legendColors.forEach(function (value) {
94
+ // return the color and offset needed to draw the legend
95
+ itemColor.push({
96
+ offset: RGBToHex(value).offset,
97
+ color: RGBToHex(value).color,
98
+ });
99
+ });
100
+ colorScale = scaleSequential().domain([min, max]);
101
+ svgLegend = select(divRef.current)
102
+ .append("svg")
103
+ .style("background-color", "#ffffffcc")
104
+ .style("border-radius", "5px");
105
+ defs = svgLegend.append("defs");
106
+ linearGradient = void 0;
107
+ // vertical legend
108
+ if (!horizontal) {
109
+ svgLegend
110
+ // .style("transform", "rotate(270deg)")
111
+ // .style("margin-top", "80px");
112
+ .attr("width", "100")
113
+ .attr("height", "190");
114
+ linearGradient = defs
115
+ .append("linearGradient")
116
+ .attr("id", "linear-gradient")
117
+ .attr("x1", "0%")
118
+ .attr("x2", "0%")
119
+ .attr("y1", "0%")
120
+ .attr("y2", "100%"); //since it's a vertical linear gradient
121
+ }
122
+ // horizontal legend
123
+ else {
124
+ svgLegend.attr("width", "200").attr("height", "90");
125
+ // append a linearGradient element to the defs and give it a unique id
126
+ linearGradient = defs
127
+ .append("linearGradient")
128
+ .attr("id", "linear-gradient")
129
+ .attr("x1", "0%")
130
+ .attr("x2", "100%") //since it's a horizontal linear gradient
131
+ .attr("y1", "0%")
132
+ .attr("y2", "0%");
133
+ }
134
+ // append multiple color stops by using D3's data/enter step
135
+ linearGradient
136
+ .selectAll("stop")
137
+ .data(itemColor)
138
+ .enter()
139
+ .append("stop")
140
+ .attr("offset", function (data) {
141
+ return data.offset + "%";
142
+ })
143
+ .attr("stop-color", function (data) {
144
+ return data.color;
145
+ });
146
+ // append title
147
+ svgLegend
148
+ .append("text")
149
+ .attr("class", "legendTitle")
150
+ .attr("x", 25)
151
+ .attr("y", 20)
152
+ .style("text-anchor", "left")
153
+ .text(dataObjectName);
154
+ // vertical legend
155
+ if (!horizontal) {
156
+ // draw the rectangle and fill with gradient
157
+ svgLegend
158
+ .append("rect")
159
+ .attr("x", 25)
160
+ .attr("y", 30)
161
+ .attr("width", 25)
162
+ .attr("height", "150")
163
+ .style("fill", "url(#linear-gradient)");
164
+ }
165
+ // horizontal legend
166
+ else {
167
+ // draw the rectangle and fill with gradient
168
+ svgLegend
169
+ .append("rect")
170
+ .attr("x", 25)
171
+ .attr("y", 30)
172
+ .attr("width", "150")
173
+ .attr("height", 25)
174
+ .style("fill", "url(#linear-gradient)");
175
+ }
176
+ xLeg = scaleLinear().domain([min, max]).range([10, 158]);
177
+ yLeg = scaleLinear().domain([min, max]).range([10, 158]);
178
+ horizontalAxisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
179
+ VerticalAxisLeg = axisRight(yLeg)
180
+ .tickSize(24)
181
+ .tickValues(colorScale.domain());
182
+ if (horizontal) {
183
+ svgLegend
184
+ .attr("class", "axis")
185
+ .append("g")
186
+ .attr("transform", "translate(15, 55)")
187
+ .style("font-size", "10px")
188
+ .style("font-weight", "700")
189
+ .call(horizontalAxisLeg)
190
+ .style("height", 25);
191
+ }
192
+ else {
193
+ svgLegend
194
+ .attr("class", "axis")
195
+ .append("g")
196
+ .attr("transform", "translate(25, 20)")
197
+ .style("font-size", "10px")
198
+ .style("font-weight", "700")
199
+ .call(VerticalAxisLeg);
200
+ }
201
+ return [3 /*break*/, 6];
202
+ case 5:
203
+ error_1 = _a.sent();
204
+ console.error(error_1);
205
+ return [3 /*break*/, 6];
206
+ case 6: return [2 /*return*/];
207
+ }
76
208
  });
77
- // append title
78
- svgLegend
79
- .append("text")
80
- .attr("class", "legendTitle")
81
- .attr("x", 25)
82
- .attr("y", 20)
83
- .style("text-anchor", "left")
84
- .text(dataObjectName);
85
- // draw the rectangle and fill with gradient
86
- svgLegend
87
- .append("rect")
88
- .attr("x", 25)
89
- .attr("y", 30)
90
- .attr("width", 250)
91
- .attr("height", 25)
92
- .style("fill", "url(#linear-gradient)");
93
- //create tick marks
94
- const xLeg = scaleLinear().domain([min, max]).range([10, 258]);
95
- const axisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
96
- svgLegend
97
- .attr("class", "axis")
98
- .append("g")
99
- .attr("transform", "translate(15, 55)")
100
- .style("font-size", "10px")
101
- .style("font-weight", "700")
102
- .call(axisLeg);
103
209
  });
104
210
  }
105
211
  return (React.createElement("div", { style: {
106
212
  position: "absolute",
107
- right: position ? position[0] : ' ',
108
- top: position ? position[1] : ' ',
213
+ right: position ? position[0] : " ",
214
+ top: position ? position[1] : " ",
215
+ zIndex: 999,
109
216
  } },
110
217
  React.createElement("div", { id: "legend", ref: divRef })));
111
218
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ContinuousLegend.js","sourceRoot":"","sources":["../../../src/component/Legend/ContinuousLegend.tsx"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAkBtE,MAAM,CAAC,MAAM,gBAAgB,GAA0B,CAAC,EACpD,GAAG,EACH,GAAG,EACH,cAAc,EACd,QAAQ,EACR,SAAS,EACT,WAAW,EACX,UAA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AAC,GAAG;YACnC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;YACjC,MAAM,EAAE,GAAG;SACd;QAED,6BAAK,EAAE,EAAC,QAAQ,EAAC,GAAG,EAAE,MAAM,GAAQ,CAClC,CACT,CAAC;AACN,CAAC,CAAC;AAEF,gBAAgB,CAAC,YAAY,GAAG;IAC5B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;CACpB,CAAC"}
@@ -9,7 +9,9 @@ declare type colorLegendProps = {
9
9
  colorName: string;
10
10
  colorTables: colorTablesArray | string;
11
11
  horizontal?: boolean | null;
12
+ updateLegend?: any;
12
13
  };
13
14
  export declare const DiscreteColorLegend: React.FC<colorLegendProps>;
14
15
  export declare function colorTableData(colorName: string, colorTables: colorTablesArray): [number, number, number, number][];
16
+ export declare function RGBToHex(rgb: number[]): string;
15
17
  export {};
@@ -7,101 +7,203 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (_) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
10
37
  import * as React from "react";
11
38
  import { useRef } from "react";
12
- import legendUtil from "../Utils/discreteLegend";
13
- import { scaleOrdinal, select } from "d3";
14
- export const DiscreteColorLegend = ({ discreteData, dataObjectName, position, colorName, colorTables, horizontal, }) => {
15
- const divRef = useRef(null);
16
- React.useEffect(() => {
39
+ import discreteLegendUtil from "../Utils/discreteLegend";
40
+ import { select, scaleOrdinal } from "d3";
41
+ export var DiscreteColorLegend = function (_a) {
42
+ var discreteData = _a.discreteData, dataObjectName = _a.dataObjectName, position = _a.position, colorName = _a.colorName, colorTables = _a.colorTables, horizontal = _a.horizontal, updateLegend = _a.updateLegend;
43
+ var divRef = useRef(null);
44
+ var itemName = [];
45
+ var itemColor = [];
46
+ var testColor = [];
47
+ var testName = [];
48
+ React.useEffect(function () {
17
49
  if (divRef.current) {
50
+ select(divRef.current).select("div").remove();
51
+ select(divRef.current).select("svg").remove();
18
52
  discreteLegend();
19
53
  }
20
54
  return function cleanup() {
21
55
  select(divRef.current).select("div").remove();
22
56
  select(divRef.current).select("svg").remove();
23
57
  };
24
- }, [discreteData, colorName, colorTables, horizontal]);
58
+ }, [discreteData, colorName, colorTables, horizontal, updateLegend]);
25
59
  function discreteLegend() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const itemName = [];
28
- const itemColor = [];
29
- let dataSet;
30
- if (typeof colorTables === "string") {
31
- let res = yield fetch(colorTables);
32
- dataSet = yield res.json();
33
- }
34
- let colorsArray = typeof colorTables === "string" ?
35
- colorTableData(colorName, dataSet)
36
- :
37
- colorTableData(colorName, colorTables);
38
- Object.keys(discreteData).forEach((key) => {
39
- // eslint-disable-next-line
40
- let code = discreteData[key][1];
41
- // compare the first value in colorarray(colortable) and code from discreteData
42
- const matchedColorsArrays = colorsArray.find((value) => {
43
- return value[0] == code;
44
- });
45
- if (matchedColorsArrays)
46
- itemColor.push({
47
- color: RGBToHex(matchedColorsArrays),
48
- });
49
- itemName.push(key);
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ var dataSet, useSelectorLegend, res, colorsArray_1, ordinalValues, colorLegend, currentDiv, totalRect, svgLegend, error_1;
62
+ return __generator(this, function (_a) {
63
+ switch (_a.label) {
64
+ case 0:
65
+ useSelectorLegend = false;
66
+ _a.label = 1;
67
+ case 1:
68
+ _a.trys.push([1, 5, , 6]);
69
+ if (!(typeof colorTables === "string")) return [3 /*break*/, 4];
70
+ return [4 /*yield*/, fetch(colorTables)];
71
+ case 2:
72
+ res = _a.sent();
73
+ return [4 /*yield*/, res.json()];
74
+ case 3:
75
+ dataSet = _a.sent();
76
+ _a.label = 4;
77
+ case 4:
78
+ colorsArray_1 = typeof colorTables === "string"
79
+ ? colorTableData(colorName, dataSet)
80
+ : colorTableData(colorName, colorTables);
81
+ console.log('updateLegend', updateLegend);
82
+ // Main discrete legend
83
+ if (!updateLegend || updateLegend.length == 0) {
84
+ Object.keys(discreteData).forEach(function (key) {
85
+ //eslint-disable-next-line
86
+ var code = discreteData[key][1];
87
+ //compare the first value in colorarray(colortable) and code from discreteData
88
+ var matchedColorsArrays = colorsArray_1.find(function (value) {
89
+ return value[0] == code;
90
+ });
91
+ if (matchedColorsArrays)
92
+ itemColor.push({
93
+ color: RGBToHex(matchedColorsArrays),
94
+ });
95
+ itemName.push(key);
96
+ });
97
+ useSelectorLegend = false;
98
+ }
99
+ // Discrete legend using Colortable colors
100
+ else if (updateLegend === null || updateLegend === void 0 ? void 0 : updateLegend.color) {
101
+ updateLegend.color.forEach(function (key) {
102
+ testColor.push({ color: RGBToHex(key) });
103
+ });
104
+ itemColor = testColor;
105
+ itemName = testName;
106
+ useSelectorLegend = true;
107
+ }
108
+ // Discrete legend using d3 colors
109
+ else if (updateLegend === null || updateLegend === void 0 ? void 0 : updateLegend.colorsObject) {
110
+ updateLegend.colorsObject.forEach(function (key) {
111
+ itemColor.push({ color: key });
112
+ });
113
+ //itemColor = itemColor;
114
+ itemName = updateLegend.legendColorName;
115
+ useSelectorLegend = true;
116
+ }
117
+ ordinalValues = scaleOrdinal().domain(itemName);
118
+ colorLegend = discreteLegendUtil(itemColor, useSelectorLegend, horizontal).inputScale(ordinalValues);
119
+ currentDiv = select(divRef.current);
120
+ totalRect = void 0;
121
+ // append the title
122
+ currentDiv
123
+ .append("div")
124
+ .text(dataObjectName)
125
+ .style("color", "grey")
126
+ .attr("y", 10)
127
+ .style("margin-bottom", "5px");
128
+ svgLegend = currentDiv
129
+ .style("margin", "5px")
130
+ .append("svg")
131
+ // .on("mouseover", function () {
132
+ // return tooltip.style("visibility", "visible");
133
+ // })
134
+ // .on("mouseout", function () {
135
+ // return tooltip.style("visibility", "hidden");
136
+ // })
137
+ .call(colorLegend);
138
+ // Style for main horizontal legend
139
+ if (!useSelectorLegend) {
140
+ totalRect = itemColor.length;
141
+ }
142
+ // Style for color selector legend
143
+ else {
144
+ // calculate width for legend using colortable colors
145
+ if (updateLegend === null || updateLegend === void 0 ? void 0 : updateLegend.color) {
146
+ totalRect = updateLegend.color.length;
147
+ }
148
+ // calculate width for legend using d3 colors
149
+ else {
150
+ totalRect = updateLegend.colorsObject.length;
151
+ }
152
+ }
153
+ if (horizontal) {
154
+ svgLegend
155
+ .attr("viewBox", "0 0 ".concat(totalRect, " 2"))
156
+ .attr("preserveAspectRatio", "none")
157
+ .style("font-size", ".4")
158
+ .attr("height", "50px")
159
+ .attr("width", "150px");
160
+ }
161
+ // vertical legend
162
+ else if (!horizontal) {
163
+ svgLegend
164
+ .attr("viewBox", "0 0 4 ".concat(totalRect))
165
+ .attr("preserveAspectRatio", "none")
166
+ .style("font-size", ".4")
167
+ .attr("height", "150px")
168
+ .attr("width", "100px");
169
+ }
170
+ return [3 /*break*/, 6];
171
+ case 5:
172
+ error_1 = _a.sent();
173
+ console.error(error_1);
174
+ return [3 /*break*/, 6];
175
+ case 6: return [2 /*return*/];
176
+ }
50
177
  });
51
- function RGBToHex(rgb) {
52
- let r = rgb[1].toString(16), g = rgb[2].toString(16), b = rgb[3].toString(16);
53
- if (r.length == 1)
54
- r = "0" + r;
55
- if (g.length == 1)
56
- g = "0" + g;
57
- if (b.length == 1)
58
- b = "0" + b;
59
- return "#" + r + g + b;
60
- }
61
- const ordinalValues = scaleOrdinal().domain(itemName);
62
- const colorLegend = legendUtil(itemColor).inputScale(ordinalValues);
63
- const legendLength = itemColor.length;
64
- const calcLegendHeight = 22 * legendLength + 4 * legendLength;
65
- const selectedLegend = select(divRef.current);
66
- selectedLegend
67
- .append("div")
68
- .text(dataObjectName)
69
- .attr("y", 7)
70
- .style("color", "#6F6F6F")
71
- .style("margin", "10px 10px");
72
- if (horizontal)
73
- selectedLegend.style("height", 150 + "px");
74
- const svgLegend = selectedLegend
75
- .append("svg")
76
- .style("margin", "10px 10px")
77
- .call(colorLegend);
78
- if (colorLegend && !horizontal) {
79
- svgLegend
80
- .attr("height", calcLegendHeight + "px")
81
- .attr("width", 220 + "px");
82
- }
83
- else {
84
- svgLegend
85
- .style("transform", "rotate(90deg)")
86
- .attr("width", calcLegendHeight + "px")
87
- .attr("height", calcLegendHeight + "px");
88
- }
89
178
  });
90
179
  }
91
180
  return (React.createElement("div", { style: {
92
181
  position: "absolute",
93
- right: position ? position[0] : ' ',
94
- top: position ? position[1] : ' ',
182
+ right: position ? position[0] : " ",
183
+ top: position ? position[1] : " ",
95
184
  backgroundColor: "#ffffffcc",
96
185
  borderRadius: "5px",
186
+ zIndex: "999 !important",
97
187
  } },
98
188
  React.createElement("div", { id: "legend", ref: divRef })));
99
189
  };
100
190
  // Based on name return the colors array from color.tables.json file
101
191
  export function colorTableData(colorName, colorTables) {
102
- const colorTableData = colorTables.filter((value) => value.name.toLowerCase() == colorName.toLowerCase());
192
+ var colorTableData = colorTables.filter(function (value) {
193
+ return value.name.toLowerCase() == colorName.toLowerCase();
194
+ });
103
195
  return colorTableData.length > 0 ? colorTableData[0].colors : [];
104
196
  }
197
+ export function RGBToHex(rgb) {
198
+ var r = rgb[1].toString(16), g = rgb[2].toString(16), b = rgb[3].toString(16);
199
+ if (r.length == 1)
200
+ r = "0" + r;
201
+ if (g.length == 1)
202
+ g = "0" + g;
203
+ if (b.length == 1)
204
+ b = "0" + b;
205
+ return "#" + r + g + b;
206
+ }
105
207
  DiscreteColorLegend.defaultProps = {
106
208
  position: [5, 10],
107
209
  };