@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.
- 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 +14 -5
- package/dist/component/ColorSelector/ColorSelectorComponent.js +260 -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 +16 -0
- package/dist/component/Legend/ColorLegend.js +35 -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 +190 -83
- package/dist/component/Legend/ContinuousLegend.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.d.ts +2 -0
- package/dist/component/Legend/DiscreteLegend.js +173 -71
- 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 +117 -41
- 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 +2 -1
- package/src/component/ColorSelector/{ColorTableSelectorWrapper.tsx → ColorSelectorAccordion.tsx} +11 -6
- package/src/component/ColorSelector/ColorSelectorComponent.tsx +315 -95
- package/src/component/ColorSelector/ColorSelectorWrapper.tsx +118 -0
- package/src/component/Legend/ColorLegend.tsx +91 -0
- package/src/component/Legend/ContinuousLegend.tsx +159 -80
- package/src/component/Legend/DiscreteLegend.tsx +168 -63
- package/src/component/Utils/continousLegend.ts +1 -1
- package/src/component/Utils/discreteLegend.ts +128 -53
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { useRef } from "react";
|
|
3
3
|
import { RGBToHex, colorsArray } from "../Utils/continousLegend";
|
|
4
|
-
import { select, scaleLinear, scaleSequential, axisBottom } from "d3";
|
|
4
|
+
import { select, scaleLinear, scaleSequential, axisBottom, axisRight } from "d3";
|
|
5
5
|
import { colorTablesArray } from "../ColorTableTypes";
|
|
6
6
|
|
|
7
7
|
declare type legendProps = {
|
|
@@ -12,6 +12,7 @@ declare type legendProps = {
|
|
|
12
12
|
colorName: string;
|
|
13
13
|
colorTables: colorTablesArray | string;
|
|
14
14
|
horizontal?: boolean | null;
|
|
15
|
+
updateLegend?: any;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
declare type ItemColor = {
|
|
@@ -27,108 +28,186 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
27
28
|
colorName,
|
|
28
29
|
colorTables,
|
|
29
30
|
horizontal,
|
|
31
|
+
updateLegend,
|
|
30
32
|
}: legendProps) => {
|
|
31
33
|
const divRef = useRef<HTMLDivElement>(null);
|
|
34
|
+
|
|
32
35
|
React.useEffect(() => {
|
|
33
36
|
if (divRef.current) {
|
|
34
37
|
continuousLegend();
|
|
35
38
|
};
|
|
36
39
|
return function cleanup() {
|
|
40
|
+
select(divRef.current).select("div").remove();
|
|
37
41
|
select(divRef.current).select("svg").remove();
|
|
38
42
|
};
|
|
39
|
-
}, [min, max, colorName, colorTables, horizontal]);
|
|
43
|
+
}, [min, max, colorName, colorTables, horizontal, updateLegend]);
|
|
40
44
|
|
|
41
45
|
async function continuousLegend() {
|
|
42
46
|
const itemColor: ItemColor[] = [];
|
|
43
47
|
let dataSet;
|
|
44
48
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
try {
|
|
50
|
+
// fix for dash wrapper
|
|
51
|
+
if (typeof colorTables === "string") {
|
|
52
|
+
const res = await fetch(colorTables);
|
|
53
|
+
dataSet = await res.json()
|
|
54
|
+
}
|
|
55
|
+
//Return the matched colors array from color.tables.json file
|
|
56
|
+
let legendColors = typeof colorTables === "string" ?
|
|
57
|
+
colorsArray(colorName, dataSet)
|
|
58
|
+
:
|
|
59
|
+
colorsArray(colorName, colorTables);
|
|
60
|
+
|
|
61
|
+
// Update color of legend based on color selector scales
|
|
62
|
+
// data is passed on click upon color scales
|
|
63
|
+
if (updateLegend) {
|
|
64
|
+
// legend using color table data
|
|
65
|
+
if (updateLegend.color) {
|
|
66
|
+
legendColors = updateLegend.color;
|
|
67
|
+
}
|
|
68
|
+
// legend using d3 data
|
|
69
|
+
else if (updateLegend.arrayData) {
|
|
70
|
+
legendColors = updateLegend.arrayData;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// main continuous legend
|
|
74
|
+
else {
|
|
75
|
+
legendColors
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
legendColors.forEach((value: [number, number, number, number]) => {
|
|
79
|
+
// return the color and offset needed to draw the legend
|
|
80
|
+
itemColor.push({
|
|
81
|
+
offset: RGBToHex(value).offset,
|
|
82
|
+
color: RGBToHex(value).color,
|
|
83
|
+
});
|
|
59
84
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
|
|
86
|
+
const colorScale = scaleSequential().domain([min, max]);
|
|
87
|
+
// append a defs (for definition) element to your SVG
|
|
88
|
+
const svgLegend = select(divRef.current)
|
|
89
|
+
.append("svg")
|
|
90
|
+
.style("background-color", "#ffffffcc")
|
|
91
|
+
.style("border-radius", "5px");
|
|
92
|
+
|
|
93
|
+
const defs = svgLegend.append("defs");
|
|
94
|
+
let linearGradient;
|
|
95
|
+
// vertical legend
|
|
96
|
+
if (!horizontal) {
|
|
97
|
+
svgLegend
|
|
98
|
+
// .style("transform", "rotate(270deg)")
|
|
99
|
+
// .style("margin-top", "80px");
|
|
100
|
+
.attr("width", "100")
|
|
101
|
+
.attr("height", "190");
|
|
102
|
+
linearGradient = defs
|
|
103
|
+
.append("linearGradient")
|
|
104
|
+
.attr("id", "linear-gradient")
|
|
105
|
+
.attr("x1", "0%")
|
|
106
|
+
.attr("x2", "0%")
|
|
107
|
+
.attr("y1", "0%")
|
|
108
|
+
.attr("y2", "100%"); //since it's a vertical linear gradient
|
|
109
|
+
}
|
|
110
|
+
// horizontal legend
|
|
111
|
+
else {
|
|
112
|
+
svgLegend.attr("width", "200").attr("height", "90");
|
|
113
|
+
|
|
114
|
+
// append a linearGradient element to the defs and give it a unique id
|
|
115
|
+
linearGradient = defs
|
|
116
|
+
.append("linearGradient")
|
|
117
|
+
.attr("id", "linear-gradient")
|
|
118
|
+
.attr("x1", "0%")
|
|
119
|
+
.attr("x2", "100%") //since it's a horizontal linear gradient
|
|
120
|
+
.attr("y1", "0%")
|
|
121
|
+
.attr("y2", "0%");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// append multiple color stops by using D3's data/enter step
|
|
125
|
+
linearGradient
|
|
126
|
+
.selectAll("stop")
|
|
127
|
+
.data(itemColor)
|
|
128
|
+
.enter()
|
|
129
|
+
.append("stop")
|
|
130
|
+
.attr("offset", function (data) {
|
|
131
|
+
return data.offset + "%";
|
|
132
|
+
})
|
|
133
|
+
.attr("stop-color", function (data) {
|
|
134
|
+
return data.color;
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// append title
|
|
68
138
|
svgLegend
|
|
69
|
-
.
|
|
70
|
-
.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
139
|
+
.append("text")
|
|
140
|
+
.attr("class", "legendTitle")
|
|
141
|
+
.attr("x", 25)
|
|
142
|
+
.attr("y", 20)
|
|
143
|
+
.style("text-anchor", "left")
|
|
144
|
+
.text(dataObjectName);
|
|
145
|
+
|
|
146
|
+
// vertical legend
|
|
147
|
+
if (!horizontal) {
|
|
148
|
+
// draw the rectangle and fill with gradient
|
|
149
|
+
svgLegend
|
|
150
|
+
.append("rect")
|
|
151
|
+
.attr("x", 25)
|
|
152
|
+
.attr("y", 30)
|
|
153
|
+
.attr("width", 25)
|
|
154
|
+
.attr("height", "150")
|
|
155
|
+
.style("fill", "url(#linear-gradient)");
|
|
156
|
+
}
|
|
157
|
+
// horizontal legend
|
|
158
|
+
else {
|
|
159
|
+
// draw the rectangle and fill with gradient
|
|
160
|
+
svgLegend
|
|
161
|
+
.append("rect")
|
|
162
|
+
.attr("x", 25)
|
|
163
|
+
.attr("y", 30)
|
|
164
|
+
.attr("width", "150")
|
|
165
|
+
.attr("height", 25)
|
|
166
|
+
.style("fill", "url(#linear-gradient)");
|
|
167
|
+
}
|
|
93
168
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.
|
|
97
|
-
.
|
|
98
|
-
|
|
99
|
-
.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
169
|
+
// create tick marks
|
|
170
|
+
// range varies the size of the axis
|
|
171
|
+
const xLeg = scaleLinear().domain([min, max]).range([10, 158]);
|
|
172
|
+
const yLeg = scaleLinear().domain([min, max]).range([10, 158]);
|
|
173
|
+
|
|
174
|
+
const horizontalAxisLeg = axisBottom(xLeg).tickValues(
|
|
175
|
+
colorScale.domain()
|
|
176
|
+
);
|
|
177
|
+
const VerticalAxisLeg = axisRight(yLeg)
|
|
178
|
+
.tickSize(24)
|
|
179
|
+
.tickValues(colorScale.domain());
|
|
180
|
+
|
|
181
|
+
if (horizontal) {
|
|
182
|
+
svgLegend
|
|
183
|
+
.attr("class", "axis")
|
|
184
|
+
.append("g")
|
|
185
|
+
.attr("transform", "translate(15, 55)")
|
|
186
|
+
.style("font-size", "10px")
|
|
187
|
+
.style("font-weight", "700")
|
|
188
|
+
.call(horizontalAxisLeg)
|
|
189
|
+
.style("height", 25);
|
|
190
|
+
} else {
|
|
191
|
+
svgLegend
|
|
192
|
+
.attr("class", "axis")
|
|
193
|
+
.append("g")
|
|
194
|
+
.attr("transform", "translate(25, 20)")
|
|
195
|
+
.style("font-size", "10px")
|
|
196
|
+
.style("font-weight", "700")
|
|
197
|
+
.call(VerticalAxisLeg);
|
|
198
|
+
}
|
|
199
|
+
} catch (error) {
|
|
200
|
+
console.error(error);
|
|
201
|
+
}
|
|
124
202
|
}
|
|
125
203
|
|
|
126
204
|
return (
|
|
127
205
|
<div
|
|
128
206
|
style={{
|
|
129
207
|
position: "absolute",
|
|
130
|
-
right: position ? position[0] :
|
|
131
|
-
top: position ? position[1] :
|
|
208
|
+
right: position ? position[0] : " ",
|
|
209
|
+
top: position ? position[1] : " ",
|
|
210
|
+
zIndex: 999,
|
|
132
211
|
}}
|
|
133
212
|
>
|
|
134
213
|
<div id="legend" ref={divRef}></div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { useRef } from "react";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import discreteLegendUtil from "../Utils/discreteLegend";
|
|
4
|
+
import { select, scaleOrdinal } from "d3";
|
|
5
5
|
import { colorTablesArray, colorTablesObj } from "../ColorTableTypes";
|
|
6
6
|
|
|
7
7
|
declare type ItemColor = {
|
|
@@ -15,6 +15,7 @@ declare type colorLegendProps = {
|
|
|
15
15
|
colorName: string;
|
|
16
16
|
colorTables: colorTablesArray | string;
|
|
17
17
|
horizontal?: boolean | null;
|
|
18
|
+
updateLegend?: any
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
|
|
@@ -24,90 +25,184 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
|
|
|
24
25
|
colorName,
|
|
25
26
|
colorTables,
|
|
26
27
|
horizontal,
|
|
28
|
+
updateLegend,
|
|
27
29
|
}: colorLegendProps) => {
|
|
28
30
|
const divRef = useRef<HTMLDivElement>(null);
|
|
31
|
+
let itemName: string[] = [];
|
|
32
|
+
let itemColor: ItemColor[] = [];
|
|
33
|
+
const testColor: ItemColor[] = [];
|
|
34
|
+
const testName: string[] = [];
|
|
35
|
+
|
|
29
36
|
React.useEffect(() => {
|
|
30
37
|
if (divRef.current) {
|
|
38
|
+
select(divRef.current).select("div").remove();
|
|
39
|
+
select(divRef.current).select("svg").remove();
|
|
31
40
|
discreteLegend();
|
|
32
41
|
}
|
|
33
42
|
return function cleanup() {
|
|
34
43
|
select(divRef.current).select("div").remove();
|
|
35
44
|
select(divRef.current).select("svg").remove();
|
|
36
45
|
};
|
|
37
|
-
}, [discreteData, colorName, colorTables, horizontal]);
|
|
46
|
+
}, [discreteData, colorName, colorTables, horizontal, updateLegend]);
|
|
47
|
+
|
|
38
48
|
async function discreteLegend() {
|
|
39
|
-
const itemName: string[] = [];
|
|
40
|
-
const itemColor: ItemColor[] = [];
|
|
41
49
|
let dataSet;
|
|
50
|
+
let useSelectorLegend = false;
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
try {
|
|
53
|
+
// fix for dash wrapper
|
|
54
|
+
if (typeof colorTables === "string") {
|
|
55
|
+
const res = await fetch(colorTables);
|
|
56
|
+
dataSet = await res.json();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const colorsArray =
|
|
60
|
+
typeof colorTables === "string"
|
|
61
|
+
? colorTableData(colorName, dataSet)
|
|
62
|
+
: colorTableData(colorName, colorTables);
|
|
47
63
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
console.log('updateLegend', updateLegend)
|
|
65
|
+
|
|
66
|
+
// Main discrete legend
|
|
67
|
+
if (!updateLegend || updateLegend.length == 0) {
|
|
68
|
+
Object.keys(discreteData).forEach((key) => {
|
|
69
|
+
//eslint-disable-next-line
|
|
70
|
+
let code = (discreteData as { [key: string]: any })[key][1]
|
|
71
|
+
//compare the first value in colorarray(colortable) and code from discreteData
|
|
72
|
+
const matchedColorsArrays = colorsArray.find(
|
|
73
|
+
(value: number[]) => {
|
|
74
|
+
return value[0] == code;
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
if (matchedColorsArrays)
|
|
78
|
+
itemColor.push({
|
|
79
|
+
color: RGBToHex(matchedColorsArrays),
|
|
80
|
+
});
|
|
81
|
+
itemName.push(key);
|
|
63
82
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
83
|
+
useSelectorLegend = false;
|
|
84
|
+
}
|
|
85
|
+
// Discrete legend using Colortable colors
|
|
86
|
+
else if (updateLegend?.color) {
|
|
87
|
+
updateLegend.color.forEach((key: any) => {
|
|
88
|
+
testColor.push({ color: RGBToHex(key) });
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
itemColor = testColor;
|
|
92
|
+
itemName = testName;
|
|
93
|
+
useSelectorLegend = true;
|
|
94
|
+
}
|
|
95
|
+
// Discrete legend using d3 colors
|
|
96
|
+
else if (updateLegend?.colorsObject) {
|
|
97
|
+
updateLegend.colorsObject.forEach((key: any) => {
|
|
98
|
+
itemColor.push({ color: key });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
//itemColor = itemColor;
|
|
102
|
+
itemName = updateLegend.legendColorName;
|
|
103
|
+
useSelectorLegend = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// const toolTipName = itemName.map((word, idx) => {
|
|
107
|
+
// return <li key={idx}>{word}</li>;
|
|
108
|
+
// });
|
|
109
|
+
|
|
110
|
+
// let nameTool;
|
|
111
|
+
|
|
112
|
+
// toolTipName.forEach((data) => {
|
|
113
|
+
// //nameTool.push(data.props.children)
|
|
114
|
+
// nameTool = data.props.children;
|
|
115
|
+
// });
|
|
116
|
+
|
|
117
|
+
// // create a tooltip
|
|
118
|
+
// const tooltip = select(divRef.current)
|
|
119
|
+
// .append("div")
|
|
120
|
+
// .style("position", "absolute")
|
|
121
|
+
// .style("visibility", "hidden")
|
|
122
|
+
// .style("background-color", "black")
|
|
123
|
+
// .style("border", "solid")
|
|
124
|
+
// .style("border-width", "1px")
|
|
125
|
+
// .style("border-radius", "5px")
|
|
126
|
+
// .style("padding", "10px")
|
|
127
|
+
// .text(nameTool)
|
|
128
|
+
// .style("color", "grey");
|
|
129
|
+
|
|
130
|
+
const ordinalValues = scaleOrdinal().domain(itemName);
|
|
131
|
+
const colorLegend = discreteLegendUtil(
|
|
132
|
+
itemColor,
|
|
133
|
+
useSelectorLegend,
|
|
134
|
+
horizontal
|
|
135
|
+
).inputScale(ordinalValues);
|
|
136
|
+
const currentDiv = select(divRef.current);
|
|
137
|
+
let totalRect;
|
|
138
|
+
|
|
139
|
+
// append the title
|
|
140
|
+
currentDiv
|
|
141
|
+
.append("div")
|
|
142
|
+
.text(dataObjectName)
|
|
143
|
+
.style("color", "grey")
|
|
144
|
+
.attr("y", 10)
|
|
145
|
+
.style("margin-bottom", "5px");
|
|
146
|
+
|
|
147
|
+
// Append svg to the div
|
|
148
|
+
const svgLegend = currentDiv
|
|
149
|
+
.style("margin", "5px")
|
|
150
|
+
.append("svg")
|
|
151
|
+
// .on("mouseover", function () {
|
|
152
|
+
// return tooltip.style("visibility", "visible");
|
|
153
|
+
// })
|
|
154
|
+
// .on("mouseout", function () {
|
|
155
|
+
// return tooltip.style("visibility", "hidden");
|
|
156
|
+
// })
|
|
157
|
+
.call(colorLegend);
|
|
158
|
+
|
|
159
|
+
// Style for main horizontal legend
|
|
160
|
+
if (!useSelectorLegend) {
|
|
161
|
+
totalRect = itemColor.length;
|
|
162
|
+
}
|
|
163
|
+
// Style for color selector legend
|
|
164
|
+
else {
|
|
165
|
+
// calculate width for legend using colortable colors
|
|
166
|
+
if (updateLegend?.color) {
|
|
167
|
+
totalRect = updateLegend.color.length;
|
|
168
|
+
}
|
|
169
|
+
// calculate width for legend using d3 colors
|
|
170
|
+
else {
|
|
171
|
+
totalRect = updateLegend.colorsObject.length;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (horizontal) {
|
|
176
|
+
svgLegend
|
|
177
|
+
.attr("viewBox", `0 0 ${totalRect} 2`)
|
|
178
|
+
.attr("preserveAspectRatio", "none")
|
|
179
|
+
.style("font-size", ".4")
|
|
180
|
+
.attr("height", "50px")
|
|
181
|
+
.attr("width", "150px");
|
|
182
|
+
}
|
|
183
|
+
// vertical legend
|
|
184
|
+
else if (!horizontal) {
|
|
185
|
+
svgLegend
|
|
186
|
+
.attr("viewBox", `0 0 4 ${totalRect}`)
|
|
187
|
+
.attr("preserveAspectRatio", "none")
|
|
188
|
+
.style("font-size", ".4")
|
|
189
|
+
.attr("height", "150px")
|
|
190
|
+
.attr("width", "100px");
|
|
191
|
+
}
|
|
192
|
+
} catch (error) {
|
|
193
|
+
console.error(error);
|
|
101
194
|
}
|
|
102
195
|
}
|
|
196
|
+
|
|
103
197
|
return (
|
|
104
198
|
<div
|
|
105
199
|
style={{
|
|
106
200
|
position: "absolute",
|
|
107
|
-
right: position ? position[0] :
|
|
108
|
-
top: position ? position[1] :
|
|
201
|
+
right: position ? position[0] : " ",
|
|
202
|
+
top: position ? position[1] : " ",
|
|
109
203
|
backgroundColor: "#ffffffcc",
|
|
110
204
|
borderRadius: "5px",
|
|
205
|
+
zIndex: "999 !important",
|
|
111
206
|
}}
|
|
112
207
|
>
|
|
113
208
|
<div id="legend" ref={divRef}></div>
|
|
@@ -127,6 +222,16 @@ export function colorTableData(
|
|
|
127
222
|
return colorTableData.length > 0 ? colorTableData[0].colors : [];
|
|
128
223
|
}
|
|
129
224
|
|
|
225
|
+
export function RGBToHex(rgb: number[]) {
|
|
226
|
+
let r = rgb[1].toString(16),
|
|
227
|
+
g = rgb[2].toString(16),
|
|
228
|
+
b = rgb[3].toString(16);
|
|
229
|
+
if (r.length == 1) r = "0" + r;
|
|
230
|
+
if (g.length == 1) g = "0" + g;
|
|
231
|
+
if (b.length == 1) b = "0" + b;
|
|
232
|
+
return "#" + r + g + b;
|
|
233
|
+
}
|
|
234
|
+
|
|
130
235
|
DiscreteColorLegend.defaultProps = {
|
|
131
236
|
position: [5, 10],
|
|
132
237
|
};
|
|
@@ -60,7 +60,7 @@ export function rgbValues(
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
// return the hex color code and offset
|
|
63
|
-
export function RGBToHex(rgb: number[])
|
|
63
|
+
export function RGBToHex(rgb: number[]) {
|
|
64
64
|
let r = Math.round(rgb[1]).toString(16),
|
|
65
65
|
g = Math.round(rgb[2]).toString(16),
|
|
66
66
|
b = Math.round(rgb[3]).toString(16);
|