@emerson-eps/color-tables 0.2.2 → 0.2.5
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.
- package/.vscode/settings.json +3 -0
- package/dist/component/ColorSelector/ColorSelectorAccordion.d.ts +2 -0
- package/dist/component/ColorSelector/{ColorTableSelectorWrapper.js → ColorSelectorAccordion.js} +12 -7
- package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -0
- package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +12 -3
- package/dist/component/ColorSelector/ColorSelectorComponent.js +255 -51
- package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorWrapper.d.ts +8 -0
- package/dist/component/ColorSelector/ColorSelectorWrapper.js +65 -0
- package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -0
- package/dist/component/Legend/ColorLegend.d.ts +13 -0
- package/dist/component/Legend/ColorLegend.js +27 -0
- package/dist/component/Legend/ColorLegend.js.map +1 -0
- package/dist/component/Legend/ContinuousLegend.d.ts +1 -0
- package/dist/component/Legend/ContinuousLegend.js +192 -82
- package/dist/component/Legend/ContinuousLegend.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.d.ts +2 -0
- package/dist/component/Legend/DiscreteLegend.js +166 -69
- package/dist/component/Legend/DiscreteLegend.js.map +1 -1
- package/dist/component/Utils/continousLegend.js +14 -12
- package/dist/component/Utils/continousLegend.js.map +1 -1
- package/dist/component/Utils/d3ColorScale.js +1 -1
- package/dist/component/Utils/d3ColorScale.js.map +1 -1
- package/dist/component/Utils/discreteLegend.d.ts +1 -1
- package/dist/component/Utils/discreteLegend.js +70 -50
- package/dist/component/Utils/discreteLegend.js.map +1 -1
- package/dist/component/color-tables.json +4 -4
- package/dist/stories/ColorLegends/ColorSelector/Selector.stories.d.ts +2 -2
- package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js +5 -5
- package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js.map +1 -1
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js +27 -16
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +1 -1
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js +27 -16
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +1 -1
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js +27 -16
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +1 -1
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js +27 -16
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +1 -1
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js +27 -16
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +1 -1
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js +27 -16
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +1 -1
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js +27 -16
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +1 -1
- package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js +35 -24
- package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js.map +1 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js +25 -14
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js.map +1 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js +25 -14
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js.map +1 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js +25 -14
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js.map +1 -1
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js +25 -14
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js.map +1 -1
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js +25 -14
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js.map +1 -1
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js +25 -14
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js.map +1 -1
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js +25 -14
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js.map +1 -1
- package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js +52 -0
- package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js.map +1 -0
- package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js +38 -0
- package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js.map +1 -0
- package/dist/stories/ColorLegends/SingleComponent/Single.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/SingleComponent/Single.stories.js +58 -0
- package/dist/stories/ColorLegends/SingleComponent/Single.stories.js.map +1 -0
- package/package.json +4 -3
- package/src/component/ColorSelector/{ColorTableSelectorWrapper.tsx → ColorSelectorAccordion.tsx} +11 -6
- package/src/component/ColorSelector/ColorSelectorComponent.tsx +308 -93
- package/src/component/ColorSelector/ColorSelectorWrapper.tsx +118 -0
- package/src/component/Legend/ColorLegend.tsx +81 -0
- package/src/component/Legend/ContinuousLegend.tsx +163 -79
- package/src/component/Legend/DiscreteLegend.tsx +128 -61
- package/src/component/Utils/continousLegend.ts +1 -1
- package/src/component/Utils/discreteLegend.ts +77 -52
- package/src/component/color-tables.json +4 -4
- package/src/stories/ColorLegends/ColorSelector/Selector.stories.jsx +3 -3
- package/src/stories/ColorLegends/DiscreteLegends/Facies.stories.jsx +39 -39
- package/src/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.jsx +1 -1
- package/src/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.jsx +44 -0
- package/src/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.jsx +30 -0
- package/src/stories/ColorLegends/SingleComponent/Single.stories.jsx +51 -0
- package/tsconfig.json +1 -1
- package/dist/component/ColorSelector/ColorTableSelectorWrapper.d.ts +0 -2
- package/dist/component/ColorSelector/ColorTableSelectorWrapper.js.map +0 -1
- package/dist/component/ColorSelector/legendComponent.d.ts +0 -14
- package/dist/component/ColorSelector/legendComponent.js +0 -228
- package/dist/component/ColorSelector/legendComponent.js.map +0 -1
- package/src/component/ColorSelector/legendComponent.tsx +0 -289
|
@@ -7,99 +7,206 @@ 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
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
//let legendColors = colorsArray(colorName, colorTables);
|
|
78
|
+
// Update color of legend based on color selector scales
|
|
79
|
+
// data is passed on click upon color scales
|
|
80
|
+
if (updateLegend) {
|
|
81
|
+
// legend using color table data
|
|
82
|
+
if (updateLegend.color) {
|
|
83
|
+
legendColors = updateLegend.color;
|
|
84
|
+
}
|
|
85
|
+
// legend using d3 data
|
|
86
|
+
else if (updateLegend.length > 0) {
|
|
87
|
+
legendColors = updateLegend;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// main continuous legend
|
|
91
|
+
else {
|
|
92
|
+
legendColors;
|
|
93
|
+
}
|
|
94
|
+
legendColors.forEach(function (value) {
|
|
95
|
+
// return the color and offset needed to draw the legend
|
|
96
|
+
itemColor.push({
|
|
97
|
+
offset: RGBToHex(value).offset,
|
|
98
|
+
color: RGBToHex(value).color,
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
colorScale = scaleSequential().domain([min, max]);
|
|
102
|
+
svgLegend = select(divRef.current)
|
|
103
|
+
.append("svg")
|
|
104
|
+
.style("background-color", "#ffffffcc")
|
|
105
|
+
.style("border-radius", "5px");
|
|
106
|
+
defs = svgLegend.append("defs");
|
|
107
|
+
linearGradient = void 0;
|
|
108
|
+
// vertical legend
|
|
109
|
+
if (!horizontal) {
|
|
110
|
+
svgLegend
|
|
111
|
+
// .style("transform", "rotate(270deg)")
|
|
112
|
+
// .style("margin-top", "80px");
|
|
113
|
+
.attr("width", "100")
|
|
114
|
+
.attr("height", "150");
|
|
115
|
+
linearGradient = defs
|
|
116
|
+
.append("linearGradient")
|
|
117
|
+
.attr("id", "linear-gradient")
|
|
118
|
+
.attr("x1", "0%")
|
|
119
|
+
.attr("x2", "0%")
|
|
120
|
+
.attr("y1", "0%")
|
|
121
|
+
.attr("y2", "100%"); //since it's a vertical linear gradient
|
|
122
|
+
}
|
|
123
|
+
// horizontal legend
|
|
124
|
+
else {
|
|
125
|
+
svgLegend
|
|
126
|
+
.attr("width", "220")
|
|
127
|
+
.attr("height", "165");
|
|
128
|
+
// append a linearGradient element to the defs and give it a unique id
|
|
129
|
+
linearGradient = defs
|
|
130
|
+
.append("linearGradient")
|
|
131
|
+
.attr("id", "linear-gradient")
|
|
132
|
+
.attr("x1", "0%")
|
|
133
|
+
.attr("x2", "100%") //since it's a horizontal linear gradient
|
|
134
|
+
.attr("y1", "0%")
|
|
135
|
+
.attr("y2", "0%");
|
|
136
|
+
}
|
|
137
|
+
// append multiple color stops by using D3's data/enter step
|
|
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
|
+
// append title
|
|
150
|
+
svgLegend
|
|
151
|
+
.append("text")
|
|
152
|
+
.attr("class", "legendTitle")
|
|
153
|
+
.attr("x", 25)
|
|
154
|
+
.attr("y", 20)
|
|
155
|
+
.style("text-anchor", "left")
|
|
156
|
+
.text(dataObjectName);
|
|
157
|
+
// vertical legend
|
|
158
|
+
if (!horizontal) {
|
|
159
|
+
// draw the rectangle and fill with gradient
|
|
160
|
+
svgLegend
|
|
161
|
+
.append("rect")
|
|
162
|
+
.attr("x", 25)
|
|
163
|
+
.attr("y", 30)
|
|
164
|
+
.attr("width", 25)
|
|
165
|
+
.attr("height", "150")
|
|
166
|
+
.style("fill", "url(#linear-gradient)");
|
|
167
|
+
}
|
|
168
|
+
// horizontal legend
|
|
169
|
+
else {
|
|
170
|
+
// draw the rectangle and fill with gradient
|
|
171
|
+
svgLegend
|
|
172
|
+
.append("rect")
|
|
173
|
+
.attr("x", 25)
|
|
174
|
+
.attr("y", 30)
|
|
175
|
+
.attr("width", "150")
|
|
176
|
+
.attr("height", 25)
|
|
177
|
+
.style("fill", "url(#linear-gradient)");
|
|
178
|
+
}
|
|
179
|
+
xLeg = scaleLinear().domain([min, max]).range([10, 158]);
|
|
180
|
+
yLeg = scaleLinear().domain([min, max]).range([10, 127]);
|
|
181
|
+
horizontalAxisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
|
|
182
|
+
VerticalAxisLeg = axisRight(yLeg).tickSize(24).tickValues(colorScale.domain());
|
|
183
|
+
if (horizontal) {
|
|
184
|
+
svgLegend
|
|
185
|
+
.attr("class", "axis")
|
|
186
|
+
.append("g")
|
|
187
|
+
.attr("transform", "translate(15, 55)")
|
|
188
|
+
.style("font-size", "10px")
|
|
189
|
+
.style("font-weight", "700")
|
|
190
|
+
.call(horizontalAxisLeg)
|
|
191
|
+
.style("height", 25);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
svgLegend
|
|
195
|
+
.attr("class", "axis")
|
|
196
|
+
.append("g")
|
|
197
|
+
.attr("transform", "translate(25, 20)")
|
|
198
|
+
.style("font-size", "10px")
|
|
199
|
+
.style("font-weight", "700")
|
|
200
|
+
.call(VerticalAxisLeg);
|
|
201
|
+
}
|
|
202
|
+
return [3 /*break*/, 6];
|
|
203
|
+
case 5:
|
|
204
|
+
error_1 = _a.sent();
|
|
205
|
+
console.error(error_1);
|
|
206
|
+
return [3 /*break*/, 6];
|
|
207
|
+
case 6: return [2 /*return*/];
|
|
208
|
+
}
|
|
76
209
|
});
|
|
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
210
|
});
|
|
104
211
|
}
|
|
105
212
|
return (React.createElement("div", { style: {
|
|
@@ -107,7 +214,10 @@ export const ContinuousLegend = ({ min, max, dataObjectName, position, colorName
|
|
|
107
214
|
right: position ? position[0] : ' ',
|
|
108
215
|
top: position ? position[1] : ' ',
|
|
109
216
|
} },
|
|
110
|
-
React.createElement("div", { id: "legend", ref: divRef
|
|
217
|
+
React.createElement("div", { id: "legend", ref: divRef, style: {
|
|
218
|
+
width: horizontal ? "220px" : "100px",
|
|
219
|
+
height: horizontal ? "165px" : "150px",
|
|
220
|
+
} })));
|
|
111
221
|
};
|
|
112
222
|
ContinuousLegend.defaultProps = {
|
|
113
223
|
position: [5, 10],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContinuousLegend.js","sourceRoot":"","sources":["../../../src/component/Legend/ContinuousLegend.tsx"],"names":[],"mappings":"
|
|
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;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AAC;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,13 +7,45 @@ 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
|
|
13
|
-
import {
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
39
|
+
import discreteLegendUtil from "../Utils/discreteLegend";
|
|
40
|
+
import { select } 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) {
|
|
18
50
|
discreteLegend();
|
|
19
51
|
}
|
|
@@ -21,71 +53,124 @@ export const DiscreteColorLegend = ({ discreteData, dataObjectName, position, co
|
|
|
21
53
|
select(divRef.current).select("div").remove();
|
|
22
54
|
select(divRef.current).select("svg").remove();
|
|
23
55
|
};
|
|
24
|
-
}, [discreteData, colorName, colorTables, horizontal]);
|
|
56
|
+
}, [discreteData, colorName, colorTables, horizontal, updateLegend]);
|
|
25
57
|
function discreteLegend() {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
59
|
+
var dataSet, discreteFlag, res, colorsArray_1, colorLegend, legendLength, calcLegendHeight, selectedLegend, svgLegend, totalRect, error_1;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
discreteFlag = false;
|
|
64
|
+
_a.label = 1;
|
|
65
|
+
case 1:
|
|
66
|
+
_a.trys.push([1, 5, , 6]);
|
|
67
|
+
if (!(typeof colorTables === "string")) return [3 /*break*/, 4];
|
|
68
|
+
return [4 /*yield*/, fetch(colorTables)];
|
|
69
|
+
case 2:
|
|
70
|
+
res = _a.sent();
|
|
71
|
+
return [4 /*yield*/, res.json()];
|
|
72
|
+
case 3:
|
|
73
|
+
dataSet = _a.sent();
|
|
74
|
+
_a.label = 4;
|
|
75
|
+
case 4:
|
|
76
|
+
colorsArray_1 = typeof colorTables === "string" ?
|
|
77
|
+
colorTableData(colorName, dataSet)
|
|
78
|
+
:
|
|
79
|
+
colorTableData(colorName, colorTables);
|
|
80
|
+
// Main discrete legend
|
|
81
|
+
if (!updateLegend) {
|
|
82
|
+
Object.keys(discreteData).forEach(function (key) {
|
|
83
|
+
//eslint-disable-next-line
|
|
84
|
+
var code = discreteData[key][1];
|
|
85
|
+
//compare the first value in colorarray(colortable) and code from discreteData
|
|
86
|
+
var matchedColorsArrays = colorsArray_1.find(function (value) {
|
|
87
|
+
return value[0] == code;
|
|
88
|
+
});
|
|
89
|
+
if (matchedColorsArrays)
|
|
90
|
+
itemColor.push({ color: RGBToHex(matchedColorsArrays) });
|
|
91
|
+
itemName.push(key);
|
|
92
|
+
});
|
|
93
|
+
discreteFlag = false;
|
|
94
|
+
}
|
|
95
|
+
// Discrete legend using Colortable colors
|
|
96
|
+
else if (updateLegend && updateLegend.color) {
|
|
97
|
+
// Object.keys(discreteData).forEach((key) => {
|
|
98
|
+
// //eslint-disable-next-line
|
|
99
|
+
// let code = (discreteData as { [key: string]: any })[key][1]
|
|
100
|
+
// //compare the first value in colorarray(colortable) and code from discreteData
|
|
101
|
+
// const matchedColorsArrays = updateLegend.color.find((value: number[]) => {
|
|
102
|
+
// return value[0] == code;
|
|
103
|
+
// });
|
|
104
|
+
// if (matchedColorsArrays) {
|
|
105
|
+
// testColor.push({color: RGBToHex(matchedColorsArrays)});
|
|
106
|
+
// testName.push(key);
|
|
107
|
+
// }
|
|
108
|
+
// });
|
|
109
|
+
//let color = updateLegend;
|
|
110
|
+
updateLegend.color.forEach(function (key) {
|
|
111
|
+
testColor.push({ color: RGBToHex(key) });
|
|
112
|
+
});
|
|
113
|
+
itemColor = testColor;
|
|
114
|
+
itemName = testName;
|
|
115
|
+
discreteFlag = true;
|
|
116
|
+
}
|
|
117
|
+
// Discrete legend using d3 colors
|
|
118
|
+
else {
|
|
119
|
+
updateLegend.colorsObject.forEach(function (key) {
|
|
120
|
+
itemColor.push({ color: key });
|
|
121
|
+
});
|
|
122
|
+
itemColor = itemColor;
|
|
123
|
+
itemName = updateLegend.legendColorName;
|
|
124
|
+
discreteFlag = true;
|
|
125
|
+
}
|
|
126
|
+
colorLegend = discreteLegendUtil(itemColor, discreteFlag);
|
|
127
|
+
legendLength = itemColor.length;
|
|
128
|
+
calcLegendHeight = 22 * legendLength + 4 * legendLength;
|
|
129
|
+
selectedLegend = select(divRef.current);
|
|
130
|
+
selectedLegend
|
|
131
|
+
.append("div")
|
|
132
|
+
.text(dataObjectName)
|
|
133
|
+
.attr("y", 10)
|
|
134
|
+
.style("margin-bottom", "5px");
|
|
135
|
+
if (horizontal && !discreteFlag)
|
|
136
|
+
selectedLegend.style("height", 150 + "px");
|
|
137
|
+
svgLegend = selectedLegend
|
|
138
|
+
.style("margin-right", "41px")
|
|
139
|
+
.style("margin-top", "5px")
|
|
140
|
+
.append("svg")
|
|
141
|
+
.call(colorLegend);
|
|
142
|
+
if (colorLegend && !horizontal) {
|
|
143
|
+
svgLegend
|
|
144
|
+
.attr("height", calcLegendHeight + "px")
|
|
145
|
+
.attr("width", 220 + "px");
|
|
146
|
+
}
|
|
147
|
+
else if (!discreteFlag && horizontal) {
|
|
148
|
+
svgLegend
|
|
149
|
+
.style("transform", "rotate(90deg)")
|
|
150
|
+
.attr("height", calcLegendHeight + "px")
|
|
151
|
+
.attr("width", calcLegendHeight + "px");
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
if (updateLegend.color) {
|
|
155
|
+
totalRect = updateLegend.color.length;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
totalRect = updateLegend.colorsObject.length;
|
|
159
|
+
}
|
|
160
|
+
svgLegend.attr("viewBox", "0 0 ".concat(totalRect, " 2"))
|
|
161
|
+
.attr("preserveAspectRatio", "none")
|
|
162
|
+
.style("font-size", ".5")
|
|
163
|
+
.attr("height", "50px")
|
|
164
|
+
.attr("width", "150px");
|
|
165
|
+
}
|
|
166
|
+
return [3 /*break*/, 6];
|
|
167
|
+
case 5:
|
|
168
|
+
error_1 = _a.sent();
|
|
169
|
+
console.error(error_1);
|
|
170
|
+
return [3 /*break*/, 6];
|
|
171
|
+
case 6: return [2 /*return*/];
|
|
172
|
+
}
|
|
50
173
|
});
|
|
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
174
|
});
|
|
90
175
|
}
|
|
91
176
|
return (React.createElement("div", { style: {
|
|
@@ -99,9 +184,21 @@ export const DiscreteColorLegend = ({ discreteData, dataObjectName, position, co
|
|
|
99
184
|
};
|
|
100
185
|
// Based on name return the colors array from color.tables.json file
|
|
101
186
|
export function colorTableData(colorName, colorTables) {
|
|
102
|
-
|
|
187
|
+
var colorTableData = colorTables.filter(function (value) {
|
|
188
|
+
return value.name.toLowerCase() == colorName.toLowerCase();
|
|
189
|
+
});
|
|
103
190
|
return colorTableData.length > 0 ? colorTableData[0].colors : [];
|
|
104
191
|
}
|
|
192
|
+
export function RGBToHex(rgb) {
|
|
193
|
+
var r = rgb[1].toString(16), g = rgb[2].toString(16), b = rgb[3].toString(16);
|
|
194
|
+
if (r.length == 1)
|
|
195
|
+
r = "0" + r;
|
|
196
|
+
if (g.length == 1)
|
|
197
|
+
g = "0" + g;
|
|
198
|
+
if (b.length == 1)
|
|
199
|
+
b = "0" + b;
|
|
200
|
+
return "#" + r + g + b;
|
|
201
|
+
}
|
|
105
202
|
DiscreteColorLegend.defaultProps = {
|
|
106
203
|
position: [5, 10],
|
|
107
204
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiscreteLegend.js","sourceRoot":"","sources":["../../../src/component/Legend/DiscreteLegend.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DiscreteLegend.js","sourceRoot":"","sources":["../../../src/component/Legend/DiscreteLegend.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAiB5B,MAAM,CAAC,IAAM,mBAAmB,GAA+B,UAAC,EAQ7C;QAPf,YAAY,kBAAA,EACZ,cAAc,oBAAA,EACd,QAAQ,cAAA,EACR,SAAS,eAAA,EACT,WAAW,iBAAA,EACX,UAAU,gBAAA,EACV,YAAY,kBAAA;IAEZ,IAAM,MAAM,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC5C,IAAI,QAAQ,GAAa,EAAE,CAAC;IAC5B,IAAI,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