@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
|
@@ -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,100 +28,179 @@ 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
|
+
let 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
|
+
//let legendColors = colorsArray(colorName, colorTables);
|
|
62
|
+
|
|
63
|
+
// Update color of legend based on color selector scales
|
|
64
|
+
// data is passed on click upon color scales
|
|
65
|
+
if (updateLegend) {
|
|
66
|
+
// legend using color table data
|
|
67
|
+
if (updateLegend.color) {
|
|
68
|
+
legendColors = updateLegend.color;
|
|
69
|
+
}
|
|
70
|
+
// legend using d3 data
|
|
71
|
+
else if (updateLegend.length > 0) {
|
|
72
|
+
legendColors = updateLegend
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// main continuous legend
|
|
76
|
+
else {
|
|
77
|
+
legendColors
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
legendColors.forEach((value: [number, number, number, number]) => {
|
|
81
|
+
// return the color and offset needed to draw the legend
|
|
82
|
+
itemColor.push({
|
|
83
|
+
offset: RGBToHex(value).offset,
|
|
84
|
+
color: RGBToHex(value).color,
|
|
85
|
+
});
|
|
59
86
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
|
|
88
|
+
const colorScale = scaleSequential().domain([min, max]);
|
|
89
|
+
// append a defs (for definition) element to your SVG
|
|
90
|
+
const svgLegend = select(divRef.current)
|
|
91
|
+
.append("svg")
|
|
92
|
+
.style("background-color", "#ffffffcc")
|
|
93
|
+
.style("border-radius", "5px");
|
|
94
|
+
|
|
95
|
+
const defs = svgLegend.append("defs");
|
|
96
|
+
let linearGradient;
|
|
97
|
+
// vertical legend
|
|
98
|
+
if (!horizontal) {
|
|
99
|
+
svgLegend
|
|
100
|
+
// .style("transform", "rotate(270deg)")
|
|
101
|
+
// .style("margin-top", "80px");
|
|
102
|
+
.attr("width", "100")
|
|
103
|
+
.attr("height", "150")
|
|
104
|
+
linearGradient = defs
|
|
105
|
+
.append("linearGradient")
|
|
106
|
+
.attr("id", "linear-gradient")
|
|
107
|
+
.attr("x1", "0%")
|
|
108
|
+
.attr("x2", "0%")
|
|
109
|
+
.attr("y1", "0%")
|
|
110
|
+
.attr("y2", "100%"); //since it's a vertical linear gradient
|
|
111
|
+
}
|
|
112
|
+
// horizontal legend
|
|
113
|
+
else {
|
|
114
|
+
svgLegend
|
|
115
|
+
.attr("width", "220")
|
|
116
|
+
.attr("height", "165")
|
|
117
|
+
|
|
118
|
+
// append a linearGradient element to the defs and give it a unique id
|
|
119
|
+
linearGradient = defs
|
|
120
|
+
.append("linearGradient")
|
|
121
|
+
.attr("id", "linear-gradient")
|
|
122
|
+
.attr("x1", "0%")
|
|
123
|
+
.attr("x2", "100%") //since it's a horizontal linear gradient
|
|
124
|
+
.attr("y1", "0%")
|
|
125
|
+
.attr("y2", "0%");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// append multiple color stops by using D3's data/enter step
|
|
129
|
+
linearGradient
|
|
130
|
+
.selectAll("stop")
|
|
131
|
+
.data(itemColor)
|
|
132
|
+
.enter()
|
|
133
|
+
.append("stop")
|
|
134
|
+
.attr("offset", function (data) {
|
|
135
|
+
return data.offset + "%";
|
|
136
|
+
})
|
|
137
|
+
.attr("stop-color", function (data) {
|
|
138
|
+
return data.color;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// append title
|
|
68
142
|
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
|
-
|
|
143
|
+
.append("text")
|
|
144
|
+
.attr("class", "legendTitle")
|
|
145
|
+
.attr("x", 25)
|
|
146
|
+
.attr("y", 20)
|
|
147
|
+
.style("text-anchor", "left")
|
|
148
|
+
.text(dataObjectName);
|
|
149
|
+
|
|
150
|
+
// vertical legend
|
|
151
|
+
if (!horizontal) {
|
|
152
|
+
// draw the rectangle and fill with gradient
|
|
153
|
+
svgLegend
|
|
154
|
+
.append("rect")
|
|
155
|
+
.attr("x", 25)
|
|
156
|
+
.attr("y", 30)
|
|
157
|
+
.attr("width", 25)
|
|
158
|
+
.attr("height", "150")
|
|
159
|
+
.style("fill", "url(#linear-gradient)");
|
|
160
|
+
}
|
|
161
|
+
// horizontal legend
|
|
162
|
+
else {
|
|
163
|
+
// draw the rectangle and fill with gradient
|
|
164
|
+
svgLegend
|
|
165
|
+
.append("rect")
|
|
166
|
+
.attr("x", 25)
|
|
167
|
+
.attr("y", 30)
|
|
168
|
+
.attr("width", "150")
|
|
169
|
+
.attr("height", 25)
|
|
170
|
+
.style("fill", "url(#linear-gradient)");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//create tick marks
|
|
174
|
+
// range varies the size of the axis
|
|
175
|
+
const xLeg = scaleLinear().domain([min, max]).range([10, 158]);
|
|
176
|
+
const yLeg = scaleLinear().domain([min, max]).range([10, 127]);
|
|
93
177
|
|
|
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
|
-
.attr("transform", "translate(15, 55)")
|
|
121
|
-
.style("font-size", "10px")
|
|
122
|
-
.style("font-weight", "700")
|
|
123
|
-
.call(axisLeg);
|
|
178
|
+
const horizontalAxisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
|
|
179
|
+
var VerticalAxisLeg = axisRight(yLeg).tickSize(24).tickValues(colorScale.domain());
|
|
180
|
+
|
|
181
|
+
|
|
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
|
+
} else {
|
|
192
|
+
svgLegend
|
|
193
|
+
.attr("class", "axis")
|
|
194
|
+
.append("g")
|
|
195
|
+
.attr("transform", "translate(25, 20)")
|
|
196
|
+
.style("font-size", "10px")
|
|
197
|
+
.style("font-weight", "700")
|
|
198
|
+
.call(VerticalAxisLeg);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
console.error(error);
|
|
203
|
+
}
|
|
124
204
|
}
|
|
125
205
|
|
|
126
206
|
return (
|
|
@@ -131,7 +211,11 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
131
211
|
top: position ? position[1] : ' ',
|
|
132
212
|
}}
|
|
133
213
|
>
|
|
134
|
-
<div id="legend" ref={divRef}
|
|
214
|
+
<div id="legend" ref={divRef}
|
|
215
|
+
style={{
|
|
216
|
+
width: horizontal ? "220px" : "100px",
|
|
217
|
+
height: horizontal ? "165px" : "150px",
|
|
218
|
+
}}></div>
|
|
135
219
|
</div>
|
|
136
220
|
);
|
|
137
221
|
};
|
|
@@ -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 } 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,8 +25,14 @@ 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
|
+
let testColor: ItemColor[] = [];
|
|
34
|
+
let testName: string[] = [];
|
|
35
|
+
|
|
29
36
|
React.useEffect(() => {
|
|
30
37
|
if (divRef.current) {
|
|
31
38
|
discreteLegend();
|
|
@@ -34,72 +41,122 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
|
|
|
34
41
|
select(divRef.current).select("div").remove();
|
|
35
42
|
select(divRef.current).select("svg").remove();
|
|
36
43
|
};
|
|
37
|
-
}, [discreteData, colorName, colorTables, horizontal]);
|
|
44
|
+
}, [discreteData, colorName, colorTables, horizontal, updateLegend]);
|
|
45
|
+
|
|
38
46
|
async function discreteLegend() {
|
|
39
|
-
const itemName: string[] = [];
|
|
40
|
-
const itemColor: ItemColor[] = [];
|
|
41
47
|
let dataSet;
|
|
48
|
+
let discreteFlag = false
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
try {
|
|
51
|
+
// fix for dash wrapper
|
|
52
|
+
if (typeof colorTables === "string") {
|
|
53
|
+
let res = await fetch(colorTables);
|
|
54
|
+
dataSet = await res.json()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let colorsArray = typeof colorTables === "string" ?
|
|
58
|
+
colorTableData(colorName, dataSet)
|
|
59
|
+
:
|
|
60
|
+
colorTableData(colorName, colorTables);
|
|
47
61
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (matchedColorsArrays)
|
|
61
|
-
itemColor.push({
|
|
62
|
-
color: RGBToHex(matchedColorsArrays),
|
|
62
|
+
// Main discrete legend
|
|
63
|
+
if(!updateLegend) {
|
|
64
|
+
Object.keys(discreteData).forEach((key) => {
|
|
65
|
+
//eslint-disable-next-line
|
|
66
|
+
let code = (discreteData as { [key: string]: any })[key][1]
|
|
67
|
+
//compare the first value in colorarray(colortable) and code from discreteData
|
|
68
|
+
const matchedColorsArrays = colorsArray.find((value: number[]) => {
|
|
69
|
+
return value[0] == code;
|
|
70
|
+
});
|
|
71
|
+
if (matchedColorsArrays)
|
|
72
|
+
itemColor.push({color: RGBToHex(matchedColorsArrays)});
|
|
73
|
+
itemName.push(key);
|
|
63
74
|
});
|
|
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
|
-
|
|
75
|
+
discreteFlag = false
|
|
76
|
+
}
|
|
77
|
+
// Discrete legend using Colortable colors
|
|
78
|
+
else if (updateLegend && updateLegend.color) {
|
|
79
|
+
// Object.keys(discreteData).forEach((key) => {
|
|
80
|
+
// //eslint-disable-next-line
|
|
81
|
+
// let code = (discreteData as { [key: string]: any })[key][1]
|
|
82
|
+
// //compare the first value in colorarray(colortable) and code from discreteData
|
|
83
|
+
// const matchedColorsArrays = updateLegend.color.find((value: number[]) => {
|
|
84
|
+
// return value[0] == code;
|
|
85
|
+
// });
|
|
86
|
+
// if (matchedColorsArrays) {
|
|
87
|
+
// testColor.push({color: RGBToHex(matchedColorsArrays)});
|
|
88
|
+
// testName.push(key);
|
|
89
|
+
// }
|
|
90
|
+
|
|
91
|
+
// });
|
|
92
|
+
|
|
93
|
+
//let color = updateLegend;
|
|
94
|
+
updateLegend.color.forEach((key: any) => {
|
|
95
|
+
testColor.push({color: RGBToHex(key)});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
itemColor = testColor
|
|
99
|
+
itemName = testName
|
|
100
|
+
discreteFlag = true
|
|
101
|
+
}
|
|
102
|
+
// Discrete legend using d3 colors
|
|
103
|
+
else {
|
|
104
|
+
updateLegend.colorsObject.forEach((key: any) => {
|
|
105
|
+
itemColor.push({color: key});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
itemColor = itemColor
|
|
109
|
+
itemName = updateLegend.legendColorName
|
|
110
|
+
discreteFlag = true
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//const ordinalValues = scaleOrdinal().domain(itemName);
|
|
115
|
+
const colorLegend = discreteLegendUtil(itemColor, discreteFlag)
|
|
116
|
+
const legendLength = itemColor.length;
|
|
117
|
+
const calcLegendHeight = 22 * legendLength + 4 * legendLength;
|
|
118
|
+
const selectedLegend = select(divRef.current);
|
|
119
|
+
selectedLegend
|
|
120
|
+
.append("div")
|
|
121
|
+
.text(dataObjectName)
|
|
122
|
+
.attr("y", 10)
|
|
123
|
+
.style("margin-bottom", "5px")
|
|
124
|
+
if (horizontal && !discreteFlag) selectedLegend.style("height", 150 + "px");
|
|
125
|
+
const svgLegend = selectedLegend
|
|
126
|
+
.style("margin-right", "41px")
|
|
127
|
+
.style("margin-top", "5px")
|
|
128
|
+
.append("svg")
|
|
129
|
+
.call(colorLegend);
|
|
130
|
+
if (colorLegend && !horizontal) {
|
|
131
|
+
svgLegend
|
|
132
|
+
.attr("height", calcLegendHeight + "px")
|
|
133
|
+
.attr("width", 220 + "px");
|
|
134
|
+
} else if (!discreteFlag && horizontal) {
|
|
135
|
+
svgLegend
|
|
136
|
+
.style("transform", "rotate(90deg)")
|
|
137
|
+
.attr("height", calcLegendHeight + "px")
|
|
138
|
+
.attr("width", calcLegendHeight + "px");
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
|
|
142
|
+
var totalRect;
|
|
143
|
+
if (updateLegend.color) {
|
|
144
|
+
totalRect = updateLegend.color.length
|
|
145
|
+
} else {
|
|
146
|
+
totalRect = updateLegend.colorsObject.length
|
|
147
|
+
}
|
|
148
|
+
svgLegend.attr("viewBox", `0 0 ${totalRect} 2`)
|
|
149
|
+
.attr("preserveAspectRatio", "none")
|
|
150
|
+
.style("font-size", ".5")
|
|
151
|
+
.attr("height", "50px")
|
|
152
|
+
.attr("width", "150px");
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error(error);
|
|
101
157
|
}
|
|
102
158
|
}
|
|
159
|
+
|
|
103
160
|
return (
|
|
104
161
|
<div
|
|
105
162
|
style={{
|
|
@@ -127,6 +184,16 @@ export function colorTableData(
|
|
|
127
184
|
return colorTableData.length > 0 ? colorTableData[0].colors : [];
|
|
128
185
|
}
|
|
129
186
|
|
|
187
|
+
export function RGBToHex(rgb: number[]) {
|
|
188
|
+
let r = rgb[1].toString(16),
|
|
189
|
+
g = rgb[2].toString(16),
|
|
190
|
+
b = rgb[3].toString(16);
|
|
191
|
+
if (r.length == 1) r = "0" + r;
|
|
192
|
+
if (g.length == 1) g = "0" + g;
|
|
193
|
+
if (b.length == 1) b = "0" + b;
|
|
194
|
+
return "#" + r + g + b;
|
|
195
|
+
}
|
|
196
|
+
|
|
130
197
|
DiscreteColorLegend.defaultProps = {
|
|
131
198
|
position: [5, 10],
|
|
132
199
|
};
|
|
@@ -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);
|