@emerson-eps/color-tables 0.2.11 → 0.2.14
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/dist/component/ColorSelector/ColorSelectorAccordion.js +2 -2
- package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +1 -2
- package/dist/component/ColorSelector/ColorSelectorComponent.js +7 -7
- package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorWrapper.d.ts +6 -2
- package/dist/component/ColorSelector/ColorSelectorWrapper.js +10 -10
- package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -1
- package/dist/component/Legend/ColorLegend.js +13 -5
- package/dist/component/Legend/ColorLegend.js.map +1 -1
- package/dist/component/Legend/ContinuousLegend.d.ts +1 -1
- package/dist/component/Legend/ContinuousLegend.js +18 -4
- package/dist/component/Legend/ContinuousLegend.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.d.ts +1 -1
- package/dist/component/Legend/DiscreteLegend.js +25 -16
- package/dist/component/Legend/DiscreteLegend.js.map +1 -1
- package/dist/component/Utils/continousLegend.d.ts +2 -2
- package/dist/component/Utils/continousLegend.js.map +1 -1
- package/dist/component/Utils/discreteLegend.js +14 -27
- package/dist/component/Utils/discreteLegend.js.map +1 -1
- package/dist/component/{Utils/ColorTableTypes.d.ts → colorTableTypes.d.ts} +0 -0
- package/dist/component/colorTableTypes.js +2 -0
- package/dist/component/colorTableTypes.js.map +1 -0
- package/dist/index.d.ts +2 -4
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/.storybook/main.js +0 -11
- package/.storybook/preview.js +0 -9
- package/.vscode/settings.json +0 -3
- package/dist/component/Utils/ColorTableTypes.js +0 -2
- package/dist/component/Utils/ColorTableTypes.js.map +0 -1
- package/dist/stories/ColorLegends/ColorSelector/Selector.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js +0 -11
- package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js +0 -38
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js +0 -38
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js +0 -38
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js +0 -38
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js +0 -38
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js +0 -38
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js +0 -38
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js +0 -47
- package/dist/stories/ColorLegends/DiscreteLegends/Facies.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js +0 -47
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js +0 -39
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js +0 -39
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js +0 -42
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js +0 -53
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js +0 -42
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js +0 -52
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js.map +0 -1
- package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js +0 -52
- package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js.map +0 -1
- package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js +0 -38
- package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js.map +0 -1
- package/dist/stories/ColorLegends/SingleComponent/Single.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/SingleComponent/Single.stories.js +0 -58
- package/dist/stories/ColorLegends/SingleComponent/Single.stories.js.map +0 -1
- package/src/component/ColorSelector/ColorSelectorAccordion.tsx +0 -54
- package/src/component/ColorSelector/ColorSelectorComponent.tsx +0 -312
- package/src/component/ColorSelector/ColorSelectorWrapper.tsx +0 -119
- package/src/component/Legend/ColorLegend.tsx +0 -89
- package/src/component/Legend/ContinuousLegend.tsx +0 -220
- package/src/component/Legend/DiscreteLegend.tsx +0 -195
- package/src/component/Utils/ColorTableTypes.ts +0 -6
- package/src/component/Utils/continousLegend.ts +0 -73
- package/src/component/Utils/d3ColorScale.ts +0 -84
- package/src/component/Utils/discreteLegend.ts +0 -84
- package/src/component/color-tables.json +0 -203
- package/src/custom.d.ts +0 -1
- package/src/index.ts +0 -26
- package/src/stories/ColorLegends/ColorSelector/Selector.stories.jsx +0 -12
- package/src/stories/ColorLegends/ContinousLegends/MD.stories.jsx +0 -29
- package/src/stories/ColorLegends/ContinousLegends/NTG.stories.jsx +0 -29
- package/src/stories/ColorLegends/ContinousLegends/PermTot.stories.jsx +0 -29
- package/src/stories/ColorLegends/ContinousLegends/Permeability.stories.jsx +0 -29
- package/src/stories/ColorLegends/ContinousLegends/PoroTot.stories.jsx +0 -29
- package/src/stories/ColorLegends/ContinousLegends/Porosity.stories.jsx +0 -29
- package/src/stories/ColorLegends/ContinousLegends/SW.stories.jsx +0 -29
- package/src/stories/ColorLegends/DiscreteLegends/Facies.stories.jsx +0 -39
- package/src/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.jsx +0 -39
- package/src/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.jsx +0 -31
- package/src/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.jsx +0 -31
- package/src/stories/ColorLegends/DiscreteLegends/RDE.stories.jsx +0 -34
- package/src/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.jsx +0 -45
- package/src/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.jsx +0 -34
- package/src/stories/ColorLegends/DiscreteLegends/Zonelog.stories.jsx +0 -46
- package/src/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.jsx +0 -44
- package/src/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.jsx +0 -30
- package/src/stories/ColorLegends/SingleComponent/Single.stories.jsx +0 -51
- package/tsconfig.json +0 -23
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useRef } from "react";
|
|
3
|
-
import { RGBToHex, colorsArray } from "../Utils/continousLegend";
|
|
4
|
-
import { select, scaleLinear, scaleSequential, axisBottom, axisRight } from "d3";
|
|
5
|
-
import { colorTablesArray } from "../Utils/ColorTableTypes";
|
|
6
|
-
|
|
7
|
-
declare type legendProps = {
|
|
8
|
-
min: number;
|
|
9
|
-
max: number;
|
|
10
|
-
dataObjectName: string;
|
|
11
|
-
position?: number[] | null;
|
|
12
|
-
colorName: string;
|
|
13
|
-
colorTables: colorTablesArray | string;
|
|
14
|
-
horizontal?: boolean | null;
|
|
15
|
-
updateLegend?: any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
declare type ItemColor = {
|
|
19
|
-
color: string;
|
|
20
|
-
offset: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const ContinuousLegend: React.FC<legendProps> = ({
|
|
24
|
-
min,
|
|
25
|
-
max,
|
|
26
|
-
dataObjectName,
|
|
27
|
-
position,
|
|
28
|
-
colorName,
|
|
29
|
-
colorTables,
|
|
30
|
-
horizontal,
|
|
31
|
-
updateLegend,
|
|
32
|
-
}: legendProps) => {
|
|
33
|
-
const divRef = useRef<HTMLDivElement>(null);
|
|
34
|
-
|
|
35
|
-
React.useEffect(() => {
|
|
36
|
-
if (divRef.current) {
|
|
37
|
-
continuousLegend();
|
|
38
|
-
};
|
|
39
|
-
return function cleanup() {
|
|
40
|
-
select(divRef.current).select("div").remove();
|
|
41
|
-
select(divRef.current).select("svg").remove();
|
|
42
|
-
};
|
|
43
|
-
}, [min, max, colorName, colorTables, horizontal, updateLegend]);
|
|
44
|
-
|
|
45
|
-
async function continuousLegend() {
|
|
46
|
-
const itemColor: ItemColor[] = [];
|
|
47
|
-
let dataSet;
|
|
48
|
-
|
|
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
|
-
});
|
|
84
|
-
});
|
|
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
|
|
138
|
-
svgLegend
|
|
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
|
-
}
|
|
168
|
-
|
|
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
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return (
|
|
205
|
-
<div
|
|
206
|
-
style={{
|
|
207
|
-
position: "absolute",
|
|
208
|
-
right: position ? position[0] : " ",
|
|
209
|
-
top: position ? position[1] : " ",
|
|
210
|
-
zIndex: 999,
|
|
211
|
-
}}
|
|
212
|
-
>
|
|
213
|
-
<div id="legend" ref={divRef}></div>
|
|
214
|
-
</div>
|
|
215
|
-
);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
ContinuousLegend.defaultProps = {
|
|
219
|
-
position: [5, 10],
|
|
220
|
-
};
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useRef } from "react";
|
|
3
|
-
import discreteLegendUtil from "../Utils/discreteLegend";
|
|
4
|
-
import { select, scaleOrdinal } from "d3";
|
|
5
|
-
import { colorTablesArray } from "../Utils/ColorTableTypes";
|
|
6
|
-
import { colorsArray } from "../Utils/continousLegend"
|
|
7
|
-
|
|
8
|
-
declare type ItemColor = {
|
|
9
|
-
color: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
declare type colorLegendProps = {
|
|
13
|
-
discreteData: { objects: Record<string, [number[], number]> };
|
|
14
|
-
dataObjectName: string;
|
|
15
|
-
position?: number[] | null;
|
|
16
|
-
colorName: string;
|
|
17
|
-
colorTables: colorTablesArray | string;
|
|
18
|
-
horizontal?: boolean | null;
|
|
19
|
-
updateLegend?: any
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
|
|
23
|
-
discreteData,
|
|
24
|
-
dataObjectName,
|
|
25
|
-
position,
|
|
26
|
-
colorName,
|
|
27
|
-
colorTables,
|
|
28
|
-
horizontal,
|
|
29
|
-
updateLegend,
|
|
30
|
-
}: colorLegendProps) => {
|
|
31
|
-
const divRef = useRef<HTMLDivElement>(null);
|
|
32
|
-
let itemName: string[] = [];
|
|
33
|
-
let itemColor: ItemColor[] = [];
|
|
34
|
-
const testColor: ItemColor[] = [];
|
|
35
|
-
const testName: string[] = [];
|
|
36
|
-
|
|
37
|
-
React.useEffect(() => {
|
|
38
|
-
if (divRef.current) {
|
|
39
|
-
select(divRef.current).select("div").remove();
|
|
40
|
-
select(divRef.current).select("svg").remove();
|
|
41
|
-
discreteLegend();
|
|
42
|
-
}
|
|
43
|
-
return function cleanup() {
|
|
44
|
-
select(divRef.current).select("div").remove();
|
|
45
|
-
select(divRef.current).select("svg").remove();
|
|
46
|
-
};
|
|
47
|
-
}, [discreteData, colorName, colorTables, horizontal, updateLegend]);
|
|
48
|
-
|
|
49
|
-
async function discreteLegend() {
|
|
50
|
-
let dataSet;
|
|
51
|
-
let useSelectorLegend = false;
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
// fix for dash wrapper
|
|
55
|
-
if (typeof colorTables === "string") {
|
|
56
|
-
const res = await fetch(colorTables);
|
|
57
|
-
dataSet = await res.json();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const arrayOfColors =
|
|
61
|
-
typeof colorTables === "string"
|
|
62
|
-
? colorsArray(colorName, dataSet)
|
|
63
|
-
: colorsArray(colorName, colorTables);
|
|
64
|
-
|
|
65
|
-
// Main discrete legend
|
|
66
|
-
if (!updateLegend || updateLegend.length == 0) {
|
|
67
|
-
Object.keys(discreteData).forEach((key) => {
|
|
68
|
-
//eslint-disable-next-line
|
|
69
|
-
let code = (discreteData as { [key: string]: any })[key][1]
|
|
70
|
-
//compare the first value in colorarray(colortable) and code from discreteData
|
|
71
|
-
const matchedColorsArrays = arrayOfColors.find(
|
|
72
|
-
(value: number[]) => {
|
|
73
|
-
return value[0] == code;
|
|
74
|
-
}
|
|
75
|
-
);
|
|
76
|
-
if (matchedColorsArrays)
|
|
77
|
-
itemColor.push({
|
|
78
|
-
color: RGBToHex(matchedColorsArrays),
|
|
79
|
-
});
|
|
80
|
-
itemName.push(key);
|
|
81
|
-
});
|
|
82
|
-
useSelectorLegend = false;
|
|
83
|
-
}
|
|
84
|
-
// Discrete legend using Colortable colors
|
|
85
|
-
else if (updateLegend?.color) {
|
|
86
|
-
updateLegend.color.forEach((key: any) => {
|
|
87
|
-
testColor.push({ color: RGBToHex(key) });
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
itemColor = testColor;
|
|
91
|
-
itemName = testName;
|
|
92
|
-
useSelectorLegend = true;
|
|
93
|
-
}
|
|
94
|
-
// Discrete legend using d3 colors
|
|
95
|
-
else if (updateLegend?.colorsObject) {
|
|
96
|
-
updateLegend.colorsObject.forEach((key: any) => {
|
|
97
|
-
itemColor.push({ color: key });
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
//itemColor = itemColor;
|
|
101
|
-
itemName = updateLegend.legendColorName;
|
|
102
|
-
useSelectorLegend = true;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const ordinalValues = scaleOrdinal().domain(itemName);
|
|
106
|
-
const colorLegend = discreteLegendUtil(
|
|
107
|
-
itemColor,
|
|
108
|
-
useSelectorLegend,
|
|
109
|
-
horizontal
|
|
110
|
-
)
|
|
111
|
-
.inputScale(ordinalValues);
|
|
112
|
-
const currentDiv = select(divRef.current);
|
|
113
|
-
let totalRect;
|
|
114
|
-
|
|
115
|
-
// append the title
|
|
116
|
-
currentDiv
|
|
117
|
-
.append("div")
|
|
118
|
-
.text(dataObjectName)
|
|
119
|
-
.style("color", "grey")
|
|
120
|
-
.attr("y", 10)
|
|
121
|
-
.style("margin-bottom", "5px");
|
|
122
|
-
|
|
123
|
-
// Append svg to the div
|
|
124
|
-
const svgLegend = currentDiv
|
|
125
|
-
.style("margin", "5px")
|
|
126
|
-
.append("svg")
|
|
127
|
-
.call(colorLegend);
|
|
128
|
-
|
|
129
|
-
// Style for main horizontal legend
|
|
130
|
-
if (!useSelectorLegend) {
|
|
131
|
-
totalRect = itemColor.length;
|
|
132
|
-
}
|
|
133
|
-
// Style for color selector legend
|
|
134
|
-
else {
|
|
135
|
-
// calculate width for legend using colortable colors
|
|
136
|
-
if (updateLegend?.color) {
|
|
137
|
-
totalRect = updateLegend.color.length;
|
|
138
|
-
}
|
|
139
|
-
// calculate width for legend using d3 colors
|
|
140
|
-
else {
|
|
141
|
-
totalRect = updateLegend.colorsObject.length;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (horizontal) {
|
|
146
|
-
svgLegend
|
|
147
|
-
.attr("viewBox", `0 0 ${totalRect} 2`)
|
|
148
|
-
.attr("preserveAspectRatio", "none")
|
|
149
|
-
.style("font-size", ".4")
|
|
150
|
-
.attr("height", "50px")
|
|
151
|
-
.attr("width", "150px");
|
|
152
|
-
}
|
|
153
|
-
// vertical legend
|
|
154
|
-
else if (!horizontal) {
|
|
155
|
-
svgLegend
|
|
156
|
-
.attr("viewBox", `0 0 4 ${totalRect}`)
|
|
157
|
-
.attr("preserveAspectRatio", "none")
|
|
158
|
-
.style("font-size", ".4")
|
|
159
|
-
.attr("height", "150px")
|
|
160
|
-
.attr("width", "100px");
|
|
161
|
-
}
|
|
162
|
-
} catch (error) {
|
|
163
|
-
console.error(error);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return (
|
|
168
|
-
<div
|
|
169
|
-
style={{
|
|
170
|
-
position: "absolute",
|
|
171
|
-
right: position ? position[0] : " ",
|
|
172
|
-
top: position ? position[1] : " ",
|
|
173
|
-
backgroundColor: "#ffffffcc",
|
|
174
|
-
borderRadius: "5px",
|
|
175
|
-
zIndex: "999 !important",
|
|
176
|
-
}}
|
|
177
|
-
>
|
|
178
|
-
<div id="legend" ref={divRef}></div>
|
|
179
|
-
</div>
|
|
180
|
-
);
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export function RGBToHex(rgb: number[]) {
|
|
184
|
-
let r = rgb[1].toString(16),
|
|
185
|
-
g = rgb[2].toString(16),
|
|
186
|
-
b = rgb[3].toString(16);
|
|
187
|
-
if (r.length == 1) r = "0" + r;
|
|
188
|
-
if (g.length == 1) g = "0" + g;
|
|
189
|
-
if (b.length == 1) b = "0" + b;
|
|
190
|
-
return "#" + r + g + b;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
DiscreteColorLegend.defaultProps = {
|
|
194
|
-
position: [5, 10],
|
|
195
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { color } from "d3-color";
|
|
2
|
-
import { interpolateRgb } from "d3-interpolate";
|
|
3
|
-
import {
|
|
4
|
-
colorTablesArray,
|
|
5
|
-
colorTablesObj,
|
|
6
|
-
} from "../Utils/ColorTableTypes";
|
|
7
|
-
|
|
8
|
-
// Based on objectName return the colors array from color.tables.json file
|
|
9
|
-
export function colorsArray(
|
|
10
|
-
colorName: string,
|
|
11
|
-
colorTables: colorTablesArray
|
|
12
|
-
): [number, number, number, number][] {
|
|
13
|
-
const colorTableData = colorTables.filter(
|
|
14
|
-
(value: colorTablesObj) =>
|
|
15
|
-
value.name.toLowerCase() == colorName.toLowerCase()
|
|
16
|
-
);
|
|
17
|
-
return colorTableData.length > 0 ? colorTableData[0].colors : [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// return the colors based on the point
|
|
21
|
-
export function rgbValues(
|
|
22
|
-
point: number,
|
|
23
|
-
colorName: string,
|
|
24
|
-
colorTables: colorTablesArray
|
|
25
|
-
): number[] | { r: number; g: number; b: number; opacity: number } | undefined {
|
|
26
|
-
const colorTableColors = colorsArray(colorName, colorTables);
|
|
27
|
-
// compare the point and first value from colorTableColors
|
|
28
|
-
const colorArrays = colorTableColors.find(
|
|
29
|
-
(value: [number, number, number, number]) => {
|
|
30
|
-
return point == value[0];
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
// if point and value in color table matches then return particular colors
|
|
35
|
-
if (colorArrays) {
|
|
36
|
-
return colorArrays.slice(1);
|
|
37
|
-
}
|
|
38
|
-
// if no match then need to do interpolation
|
|
39
|
-
else {
|
|
40
|
-
// Get index of first match of colortable point greater than point
|
|
41
|
-
const index = colorTableColors.findIndex((value: number[]) => {
|
|
42
|
-
return value[0] > point;
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const firstColorArray = colorTableColors[index - 1];
|
|
46
|
-
const secondColorArray = colorTableColors[index];
|
|
47
|
-
|
|
48
|
-
if ((firstColorArray || secondColorArray) != undefined) {
|
|
49
|
-
const t0 = firstColorArray[0];
|
|
50
|
-
const t1 = secondColorArray[0];
|
|
51
|
-
const t = (point - t0) / (t1 - t0); // t = 0.0 gives first color, t = 1.0 gives second color.
|
|
52
|
-
const interpolatedValues = interpolateRgb(
|
|
53
|
-
RGBToHex(firstColorArray).color,
|
|
54
|
-
RGBToHex(secondColorArray).color
|
|
55
|
-
)(t);
|
|
56
|
-
return color(interpolatedValues)?.rgb();
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// return the hex color code and offset
|
|
63
|
-
export function RGBToHex(rgb: number[]) {
|
|
64
|
-
let r = Math.round(rgb[1]).toString(16),
|
|
65
|
-
g = Math.round(rgb[2]).toString(16),
|
|
66
|
-
b = Math.round(rgb[3]).toString(16);
|
|
67
|
-
if (r.length == 1) r = "0" + r;
|
|
68
|
-
if (g.length == 1) g = "0" + g;
|
|
69
|
-
if (b.length == 1) b = "0" + b;
|
|
70
|
-
const offset = rgb[0] * 100.0;
|
|
71
|
-
|
|
72
|
-
return { color: "#" + r + g + b, offset: offset };
|
|
73
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as d3 from "d3";
|
|
2
|
-
|
|
3
|
-
export const d3ColorScales = [
|
|
4
|
-
{
|
|
5
|
-
"name": "Spectral",
|
|
6
|
-
"discrete": false,
|
|
7
|
-
"colors": d3.interpolateSpectral
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"name": "RdYlBu",
|
|
11
|
-
"discrete": false,
|
|
12
|
-
"colors": d3.interpolateRdYlBu
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
"name": "Warm",
|
|
16
|
-
"discrete": false,
|
|
17
|
-
"colors": d3.interpolateWarm
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"name": "Cool",
|
|
21
|
-
"discrete": false,
|
|
22
|
-
"colors": d3.interpolateCool
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"name": "Viridis",
|
|
26
|
-
"discrete": false,
|
|
27
|
-
"colors": d3.interpolateViridis
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
"name": "Inferno",
|
|
31
|
-
"discrete": false,
|
|
32
|
-
"colors": d3.interpolateInferno
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
"name": "Accent",
|
|
36
|
-
"discrete": true,
|
|
37
|
-
"colors": d3.schemeAccent
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"name": "Dark2",
|
|
41
|
-
"discrete": true,
|
|
42
|
-
"colors": d3.schemeDark2
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"name": "Paired",
|
|
46
|
-
"discrete": true,
|
|
47
|
-
"colors": d3.schemePaired
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"name": "Pastel1",
|
|
51
|
-
"discrete": true,
|
|
52
|
-
"colors": d3.schemePastel1
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"name": "Pastel2",
|
|
56
|
-
"discrete": true,
|
|
57
|
-
"colors": d3.schemePastel2
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"name": "Set1",
|
|
61
|
-
"discrete": true,
|
|
62
|
-
"colors": d3.schemeSet1
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
"name": "Set2",
|
|
66
|
-
"discrete": true,
|
|
67
|
-
"colors": d3.schemeSet3
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"name": "Set3",
|
|
71
|
-
"discrete": true,
|
|
72
|
-
"colors": d3.schemeSet3
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"name": "Tableau10",
|
|
76
|
-
"discrete": true,
|
|
77
|
-
"colors": d3.schemeTableau10
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
"name": "Category10",
|
|
81
|
-
"discrete": true,
|
|
82
|
-
"colors": d3.schemeCategory10
|
|
83
|
-
},
|
|
84
|
-
]
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
declare type ItemColor = {
|
|
2
|
-
color: any;
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
// eslint-disable-next-line
|
|
6
|
-
export default function discreteLegendUtil(itemColor: ItemColor[], isSelectorLegend?: boolean, horizontal?: any): any {
|
|
7
|
-
const legendValues: ItemColor[] = [];
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line
|
|
10
|
-
function legend(g: any) {
|
|
11
|
-
function drawLegend() {
|
|
12
|
-
// Code to fill the color
|
|
13
|
-
// Styling for color selector legend
|
|
14
|
-
//if (isSelectorLegend) {
|
|
15
|
-
g.selectAll("g.legendCells")
|
|
16
|
-
.data(itemColor)
|
|
17
|
-
.enter()
|
|
18
|
-
.append("g")
|
|
19
|
-
.append("rect")
|
|
20
|
-
.attr("class", "rectLabel")
|
|
21
|
-
.style("cursor", "pointer")
|
|
22
|
-
.style("pointer-events", "all");
|
|
23
|
-
g.selectAll("rect")
|
|
24
|
-
.attr("height", 1)
|
|
25
|
-
.attr("width", 1)
|
|
26
|
-
.style("fill", function (d: Record<string, unknown>) {
|
|
27
|
-
return d["color"];
|
|
28
|
-
});
|
|
29
|
-
if (horizontal && !isSelectorLegend) {
|
|
30
|
-
g.selectAll("rect")
|
|
31
|
-
.attr("x", function (d: number, i: number) {
|
|
32
|
-
// temporary workaround to ignore typescript error (d value as unused)
|
|
33
|
-
if (i) return i;
|
|
34
|
-
else if (d) return null;
|
|
35
|
-
})
|
|
36
|
-
.attr("y", 0);
|
|
37
|
-
} else if (!horizontal && !isSelectorLegend) {
|
|
38
|
-
g.selectAll("rect")
|
|
39
|
-
.attr("y", function (d: number, i: number) {
|
|
40
|
-
if (i) return i;
|
|
41
|
-
else if (d) return null;
|
|
42
|
-
})
|
|
43
|
-
.attr("x", 0);
|
|
44
|
-
} else if (horizontal == true && isSelectorLegend) {
|
|
45
|
-
g.selectAll("rect")
|
|
46
|
-
.attr("x", function (d: number, i: number) {
|
|
47
|
-
if (i) return i;
|
|
48
|
-
else if (d) return null;
|
|
49
|
-
})
|
|
50
|
-
.attr("y", 0);
|
|
51
|
-
} else if (horizontal == false && isSelectorLegend) {
|
|
52
|
-
g.selectAll("rect")
|
|
53
|
-
.attr("y", function (d: number, i: number) {
|
|
54
|
-
if (i) return i;
|
|
55
|
-
else if (d) return null;
|
|
56
|
-
})
|
|
57
|
-
.attr("x", 0);
|
|
58
|
-
} else {
|
|
59
|
-
g.selectAll("rect")
|
|
60
|
-
.attr("x", function (d: number, i: number) {
|
|
61
|
-
if (i) return i;
|
|
62
|
-
else if (d) return null;
|
|
63
|
-
})
|
|
64
|
-
.attr("y", 0);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
drawLegend();
|
|
69
|
-
}
|
|
70
|
-
// eslint-disable-next-line
|
|
71
|
-
legend.inputScale = function (newScale: any) {
|
|
72
|
-
// eslint-disable-next-line
|
|
73
|
-
let scale: any = {};
|
|
74
|
-
scale = newScale;
|
|
75
|
-
|
|
76
|
-
scale.domain().forEach(function (el: any) {
|
|
77
|
-
const cellObject = { color: scale(el), label: el };
|
|
78
|
-
legendValues.push(cellObject);
|
|
79
|
-
});
|
|
80
|
-
return this;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
return legend;
|
|
84
|
-
}
|