@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,228 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useRef } from "react";
|
|
3
|
-
import { RGBToHex } from "../Utils/continousLegend";
|
|
4
|
-
import { d3ColorScales } from "../Utils/d3ColorScale";
|
|
5
|
-
import * as d3 from "d3";
|
|
6
|
-
import { scaleOrdinal, select } from "d3";
|
|
7
|
-
import discreteLegendUtil from "../Utils/discreteLegend";
|
|
8
|
-
export const LegendComponent = ({ position, colorsObject, legendColor, legendColorName, useContColorTable, useDiscColorTable, valueIndex, }) => {
|
|
9
|
-
const divRef = useRef(null);
|
|
10
|
-
React.useEffect(() => {
|
|
11
|
-
// continuous legend using color table colors
|
|
12
|
-
if (useContColorTable == true && divRef.current) {
|
|
13
|
-
contColortableLegend();
|
|
14
|
-
return function cleanup() {
|
|
15
|
-
d3.select(divRef.current).select("svg").remove();
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
// discrete legend using color table colors
|
|
19
|
-
if (useDiscColorTable == true && divRef.current) {
|
|
20
|
-
discColorTableLegend();
|
|
21
|
-
return function cleanup() {
|
|
22
|
-
select(divRef.current).select("div").remove();
|
|
23
|
-
select(divRef.current).select("svg").remove();
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
// discrete legend using d3 colors
|
|
27
|
-
if (useDiscColorTable == false && divRef.current) {
|
|
28
|
-
discD3legend();
|
|
29
|
-
return function cleanup() {
|
|
30
|
-
select(divRef.current).select("div").remove();
|
|
31
|
-
select(divRef.current).select("svg").remove();
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
// continuous legend using d3 colors
|
|
35
|
-
else if (useContColorTable == false && divRef.current) {
|
|
36
|
-
contD3Legend();
|
|
37
|
-
return function cleanup() {
|
|
38
|
-
d3.select(divRef.current).select("svg").remove();
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}, [useContColorTable]);
|
|
42
|
-
// continuous legend using color table colors (linear gradiend code)
|
|
43
|
-
function contColortableLegend() {
|
|
44
|
-
const itemColor = [];
|
|
45
|
-
colorsObject.color.forEach((value) => {
|
|
46
|
-
// return the color and offset needed to draw the legend
|
|
47
|
-
itemColor.push({
|
|
48
|
-
offset: RGBToHex(value).offset,
|
|
49
|
-
color: RGBToHex(value).color,
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
// append a defs (for definition) element to your SVG
|
|
53
|
-
const svgLegend = d3.select(divRef.current)
|
|
54
|
-
.append("svg")
|
|
55
|
-
.style("height", "50px")
|
|
56
|
-
.style("display", "flex");
|
|
57
|
-
const defs = svgLegend.append("defs");
|
|
58
|
-
let currentIndex = "linear-gradient-" + valueIndex;
|
|
59
|
-
// append a linearGradient element to the defs and give it a unique id
|
|
60
|
-
const linearGradient = defs
|
|
61
|
-
.append("linearGradient")
|
|
62
|
-
.attr("id", currentIndex)
|
|
63
|
-
.attr("x1", "0%")
|
|
64
|
-
.attr("x2", "100%") //since it's a horizontal linear gradient
|
|
65
|
-
.attr("y1", "0%")
|
|
66
|
-
.attr("y2", "0%");
|
|
67
|
-
// append multiple color stops by using D3's data/enter step
|
|
68
|
-
linearGradient
|
|
69
|
-
.selectAll("stop")
|
|
70
|
-
.data(itemColor)
|
|
71
|
-
.enter()
|
|
72
|
-
.append("stop")
|
|
73
|
-
.attr("offset", function (data) {
|
|
74
|
-
return data.offset + "%";
|
|
75
|
-
})
|
|
76
|
-
.attr("stop-color", function (data) {
|
|
77
|
-
return data.color;
|
|
78
|
-
});
|
|
79
|
-
// append title
|
|
80
|
-
svgLegend
|
|
81
|
-
.append("text")
|
|
82
|
-
.attr("class", "legendTitle")
|
|
83
|
-
.attr("x", 0)
|
|
84
|
-
.attr("y", 43)
|
|
85
|
-
.style("text-anchor", "left")
|
|
86
|
-
.text(colorsObject.name);
|
|
87
|
-
// draw the rectangle and fill with gradient
|
|
88
|
-
svgLegend
|
|
89
|
-
.append("rect")
|
|
90
|
-
.attr("x", 180)
|
|
91
|
-
.attr("y", 30)
|
|
92
|
-
.attr("width", 150)
|
|
93
|
-
.attr("height", 25)
|
|
94
|
-
.style("fill", "url(#" + currentIndex + ")");
|
|
95
|
-
}
|
|
96
|
-
// continuous legend using d3 colors (linear gradiend code)
|
|
97
|
-
function contD3Legend() {
|
|
98
|
-
const itemColor = [];
|
|
99
|
-
d3ColorScales.forEach((value) => {
|
|
100
|
-
// return the color and offset needed to draw the legend
|
|
101
|
-
itemColor.push(value.colors);
|
|
102
|
-
});
|
|
103
|
-
// create an array of steps based on the color scale
|
|
104
|
-
// returns an array of evenly-spaced numbers. Returns the integers from zero to the specified end minus one.
|
|
105
|
-
// d3.range(start, stop, step)
|
|
106
|
-
var data = d3.range(10).map(d => ({ color: legendColor(d / 10), value: d }));
|
|
107
|
-
// get the array's min and max value
|
|
108
|
-
var extent = d3.extent(data, d => d.value);
|
|
109
|
-
// append a defs (for definition) element to your SVG
|
|
110
|
-
const svgLegend = d3.select(divRef.current)
|
|
111
|
-
.append("svg")
|
|
112
|
-
.style("height", "50px")
|
|
113
|
-
.style("display", "flex");
|
|
114
|
-
const defs = svgLegend.append("defs");
|
|
115
|
-
let currentIndex = "linear-gradient-" + valueIndex;
|
|
116
|
-
// append a linearGradient element to the defs and give it a unique id
|
|
117
|
-
const linearGradient = defs
|
|
118
|
-
.append("linearGradient")
|
|
119
|
-
.attr("id", currentIndex)
|
|
120
|
-
.attr("x1", "0%")
|
|
121
|
-
.attr("x2", "100%") //since it's a horizontal linear gradient
|
|
122
|
-
.attr("y1", "0%")
|
|
123
|
-
.attr("y2", "0%");
|
|
124
|
-
// append multiple color stops by using D3's data/enter step
|
|
125
|
-
linearGradient.selectAll("stop")
|
|
126
|
-
.data(data)
|
|
127
|
-
.enter().append("stop")
|
|
128
|
-
.attr("offset", d => ((d.value - extent[0]) / (extent[1] - extent[0]) * 100) + "%")
|
|
129
|
-
.attr("stop-color", d => d.color);
|
|
130
|
-
// append title
|
|
131
|
-
svgLegend
|
|
132
|
-
.append("text")
|
|
133
|
-
.attr("class", "legendTitle")
|
|
134
|
-
.attr("x", 0)
|
|
135
|
-
.attr("y", 43)
|
|
136
|
-
.style("text-anchor", "left")
|
|
137
|
-
.text(legendColorName);
|
|
138
|
-
// draw the rectangle and fill with gradient
|
|
139
|
-
svgLegend
|
|
140
|
-
.append("rect")
|
|
141
|
-
.attr("x", 180)
|
|
142
|
-
.attr("y", 30)
|
|
143
|
-
.attr("width", 150)
|
|
144
|
-
.attr("height", 25)
|
|
145
|
-
.style("fill", "url(#" + currentIndex + ")");
|
|
146
|
-
}
|
|
147
|
-
// discrete legend using color table colors
|
|
148
|
-
function discColorTableLegend() {
|
|
149
|
-
const itemColor = [];
|
|
150
|
-
const itemName = [];
|
|
151
|
-
colorsObject.color.forEach((element, key) => {
|
|
152
|
-
itemColor.push({ color: RGBToHex(element) });
|
|
153
|
-
itemName.push(key);
|
|
154
|
-
});
|
|
155
|
-
function RGBToHex(rgb) {
|
|
156
|
-
let r = rgb[1].toString(16), g = rgb[2].toString(16), b = rgb[3].toString(16);
|
|
157
|
-
if (r.length == 1)
|
|
158
|
-
r = "0" + r;
|
|
159
|
-
if (g.length == 1)
|
|
160
|
-
g = "0" + g;
|
|
161
|
-
if (b.length == 1)
|
|
162
|
-
b = "0" + b;
|
|
163
|
-
return "#" + r + g + b;
|
|
164
|
-
}
|
|
165
|
-
const ordinalValues = scaleOrdinal().domain(itemName);
|
|
166
|
-
const colorLegend = discreteLegendUtil(itemColor, "ColorSelector").inputScale(ordinalValues);
|
|
167
|
-
select("svg").append("g").attr("transform", "translate(50,70)").attr("class", "legend").call(colorLegend);
|
|
168
|
-
//const calcLegendHeight = 22 * itemColor.length + 4 * itemColor.length;
|
|
169
|
-
const selectedLegend = select(divRef.current);
|
|
170
|
-
selectedLegend
|
|
171
|
-
.append("text")
|
|
172
|
-
.text(legendColorName)
|
|
173
|
-
.attr("y", 7)
|
|
174
|
-
.style("float", "left")
|
|
175
|
-
.style("width", "30%")
|
|
176
|
-
.style("margin", "10px 0px");
|
|
177
|
-
selectedLegend
|
|
178
|
-
.append("svg")
|
|
179
|
-
.style("margin-top", "13px")
|
|
180
|
-
.style("margin-right", "103px")
|
|
181
|
-
.style("float", "right")
|
|
182
|
-
// .style("width", "60%")
|
|
183
|
-
.style("height", "25px")
|
|
184
|
-
.call(colorLegend);
|
|
185
|
-
}
|
|
186
|
-
// discrete legend using d3 colors
|
|
187
|
-
function discD3legend() {
|
|
188
|
-
const itemName = [];
|
|
189
|
-
const itemColor = [];
|
|
190
|
-
colorsObject.forEach((element, key) => {
|
|
191
|
-
itemColor.push({ color: element });
|
|
192
|
-
itemName.push(key);
|
|
193
|
-
});
|
|
194
|
-
const ordinalValues = scaleOrdinal(colorsObject).domain(itemName);
|
|
195
|
-
const discreteLegend = discreteLegendUtil(itemColor, "ColorSelector").inputScale(ordinalValues);
|
|
196
|
-
select("svg").append("g").attr("transform", "translate(50,70)").attr("class", "legend").call(discreteLegend);
|
|
197
|
-
const selectedLegend = select(divRef.current);
|
|
198
|
-
selectedLegend
|
|
199
|
-
.append("text")
|
|
200
|
-
.text(legendColorName)
|
|
201
|
-
.attr("y", 7)
|
|
202
|
-
.style("float", "left")
|
|
203
|
-
.style("width", "30%")
|
|
204
|
-
.style("margin", "10px 0px");
|
|
205
|
-
selectedLegend
|
|
206
|
-
.append("svg")
|
|
207
|
-
.style("margin-top", "13px")
|
|
208
|
-
.style("margin-right", "103px")
|
|
209
|
-
.style("float", "right")
|
|
210
|
-
// .style("width", "60%")
|
|
211
|
-
.style("height", "25px")
|
|
212
|
-
.call(discreteLegend);
|
|
213
|
-
}
|
|
214
|
-
return (React.createElement("div", { style: {
|
|
215
|
-
right: position[0],
|
|
216
|
-
top: position[1],
|
|
217
|
-
borderRadius: "5px",
|
|
218
|
-
height: "35px",
|
|
219
|
-
marginTop: "15px"
|
|
220
|
-
} },
|
|
221
|
-
React.createElement("div", { id: "legend", ref: divRef })));
|
|
222
|
-
};
|
|
223
|
-
// Based on name return the colors array from color.tables.json file
|
|
224
|
-
export function colorTableData(colorName, colorTables) {
|
|
225
|
-
const colorTableData = colorTables.filter((value) => value.name.toLowerCase() == colorName.toLowerCase());
|
|
226
|
-
return colorTableData.length > 0 ? colorTableData[0].colors : [];
|
|
227
|
-
}
|
|
228
|
-
//# sourceMappingURL=legendComponent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legendComponent.js","sourceRoot":"","sources":["../../../src/component/ColorSelector/legendComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE1C,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AAiBzD,MAAM,CAAC,MAAM,eAAe,GAA0B,CAAC,EACnD,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,GACA,EAAE,EAAE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yB;aACxB,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;aACvB,IAAI,CAAC,cAAc,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,CACH,6BACI,KAAK,EAAE;YACH,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;YAClB,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;YAChB,YAAY,EAAE,KAAK;YACnB,MAAM,EAAE,MAAM;YACd,SAAS,EAAE,MAAM;SACpB;QAED,6BAAK,EAAE,EAAC,QAAQ,EAAC,GAAG,EAAE,MAAM,GAAQ,CAClC,CACT,CAAC;AACN,CAAC,CAAC;AAEF,oEAAoE;AACpE,MAAM,UAAU,cAAc,CAC1B,SAAiB,EACjB,WAA6B;IAE7B,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,CACrC,CAAC,KAAqB,EAAE,EAAE,CACtB,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,SAAS,CAAC,WAAW,EAAE,CAC1D,CAAC;IACF,OAAO,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;AACrE,CAAC"}
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { useRef } from "react";
|
|
3
|
-
import { RGBToHex } from "../Utils/continousLegend";
|
|
4
|
-
import {d3ColorScales} from "../Utils/d3ColorScale"
|
|
5
|
-
import * as d3 from "d3";
|
|
6
|
-
import { scaleOrdinal, select } from "d3";
|
|
7
|
-
import { colorTablesArray, colorTablesObj } from "../ColorTableTypes";
|
|
8
|
-
import discreteLegendUtil from "../Utils/discreteLegend";
|
|
9
|
-
|
|
10
|
-
interface legendProps {
|
|
11
|
-
position: number[];
|
|
12
|
-
colorsObject?: any;
|
|
13
|
-
legendColor?: any;
|
|
14
|
-
legendColorName: string;
|
|
15
|
-
useContColorTable?: boolean;
|
|
16
|
-
useDiscColorTable?: boolean;
|
|
17
|
-
valueIndex?: any;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface ItemColor {
|
|
21
|
-
color: string;
|
|
22
|
-
offset?: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const LegendComponent: React.FC<legendProps> = ({
|
|
26
|
-
position,
|
|
27
|
-
colorsObject,
|
|
28
|
-
legendColor,
|
|
29
|
-
legendColorName,
|
|
30
|
-
useContColorTable,
|
|
31
|
-
useDiscColorTable,
|
|
32
|
-
valueIndex,
|
|
33
|
-
}: legendProps) => {
|
|
34
|
-
|
|
35
|
-
const divRef = useRef<HTMLDivElement>(null);
|
|
36
|
-
|
|
37
|
-
React.useEffect(() => {
|
|
38
|
-
// continuous legend using color table colors
|
|
39
|
-
if (useContColorTable == true && divRef.current) {
|
|
40
|
-
contColortableLegend();
|
|
41
|
-
return function cleanup() {
|
|
42
|
-
d3.select(divRef.current).select("svg").remove();
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
// discrete legend using color table colors
|
|
46
|
-
if (useDiscColorTable == true && divRef.current) {
|
|
47
|
-
discColorTableLegend();
|
|
48
|
-
return function cleanup() {
|
|
49
|
-
select(divRef.current).select("div").remove();
|
|
50
|
-
select(divRef.current).select("svg").remove();
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
// discrete legend using d3 colors
|
|
54
|
-
if (useDiscColorTable == false && divRef.current) {
|
|
55
|
-
discD3legend();
|
|
56
|
-
return function cleanup() {
|
|
57
|
-
select(divRef.current).select("div").remove();
|
|
58
|
-
select(divRef.current).select("svg").remove();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// continuous legend using d3 colors
|
|
62
|
-
else if (useContColorTable == false && divRef.current) {
|
|
63
|
-
contD3Legend();
|
|
64
|
-
return function cleanup() {
|
|
65
|
-
d3.select(divRef.current).select("svg").remove();
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}, [useContColorTable]);
|
|
69
|
-
|
|
70
|
-
// continuous legend using color table colors (linear gradiend code)
|
|
71
|
-
function contColortableLegend() {
|
|
72
|
-
const itemColor: ItemColor[] = [];
|
|
73
|
-
|
|
74
|
-
colorsObject.color.forEach((value: [number, number, number, number]) => {
|
|
75
|
-
// return the color and offset needed to draw the legend
|
|
76
|
-
itemColor.push({
|
|
77
|
-
offset: RGBToHex(value).offset,
|
|
78
|
-
color: RGBToHex(value).color,
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// append a defs (for definition) element to your SVG
|
|
83
|
-
const svgLegend = d3.select(divRef.current)
|
|
84
|
-
.append("svg")
|
|
85
|
-
.style("height", "50px")
|
|
86
|
-
.style("display", "flex")
|
|
87
|
-
|
|
88
|
-
const defs = svgLegend.append("defs");
|
|
89
|
-
let currentIndex = "linear-gradient-" + valueIndex;
|
|
90
|
-
// append a linearGradient element to the defs and give it a unique id
|
|
91
|
-
const linearGradient = defs
|
|
92
|
-
.append("linearGradient")
|
|
93
|
-
.attr("id", currentIndex)
|
|
94
|
-
.attr("x1", "0%")
|
|
95
|
-
.attr("x2", "100%") //since it's a horizontal linear gradient
|
|
96
|
-
.attr("y1", "0%")
|
|
97
|
-
.attr("y2", "0%");
|
|
98
|
-
// append multiple color stops by using D3's data/enter step
|
|
99
|
-
|
|
100
|
-
linearGradient
|
|
101
|
-
.selectAll("stop")
|
|
102
|
-
.data(itemColor)
|
|
103
|
-
.enter()
|
|
104
|
-
.append("stop")
|
|
105
|
-
.attr("offset", function (data) {
|
|
106
|
-
return data.offset + "%";
|
|
107
|
-
})
|
|
108
|
-
.attr("stop-color", function (data) {
|
|
109
|
-
return data.color;
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// append title
|
|
113
|
-
svgLegend
|
|
114
|
-
.append("text")
|
|
115
|
-
.attr("class", "legendTitle")
|
|
116
|
-
.attr("x", 0)
|
|
117
|
-
.attr("y", 43)
|
|
118
|
-
.style("text-anchor", "left")
|
|
119
|
-
.text(colorsObject.name);
|
|
120
|
-
|
|
121
|
-
// draw the rectangle and fill with gradient
|
|
122
|
-
svgLegend
|
|
123
|
-
.append("rect")
|
|
124
|
-
.attr("x", 180)
|
|
125
|
-
.attr("y", 30)
|
|
126
|
-
.attr("width", 150)
|
|
127
|
-
.attr("height", 25)
|
|
128
|
-
.style("fill", "url(#"+currentIndex+")");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// continuous legend using d3 colors (linear gradiend code)
|
|
132
|
-
function contD3Legend() {
|
|
133
|
-
const itemColor: any = [];
|
|
134
|
-
|
|
135
|
-
d3ColorScales.forEach((value: any) => {
|
|
136
|
-
// return the color and offset needed to draw the legend
|
|
137
|
-
itemColor.push(value.colors);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
// create an array of steps based on the color scale
|
|
141
|
-
// returns an array of evenly-spaced numbers. Returns the integers from zero to the specified end minus one.
|
|
142
|
-
// d3.range(start, stop, step)
|
|
143
|
-
var data = d3.range(10).map(d=> ({color:legendColor(d/10), value:d}))
|
|
144
|
-
// get the array's min and max value
|
|
145
|
-
var extent: any = d3.extent(data, d => d.value);
|
|
146
|
-
|
|
147
|
-
// append a defs (for definition) element to your SVG
|
|
148
|
-
const svgLegend = d3.select(divRef.current)
|
|
149
|
-
.append("svg")
|
|
150
|
-
.style("height", "50px")
|
|
151
|
-
.style("display", "flex")
|
|
152
|
-
|
|
153
|
-
const defs = svgLegend.append("defs");
|
|
154
|
-
let currentIndex = "linear-gradient-" + valueIndex;
|
|
155
|
-
// append a linearGradient element to the defs and give it a unique id
|
|
156
|
-
const linearGradient = defs
|
|
157
|
-
.append("linearGradient")
|
|
158
|
-
.attr("id", currentIndex)
|
|
159
|
-
.attr("x1", "0%")
|
|
160
|
-
.attr("x2", "100%") //since it's a horizontal linear gradient
|
|
161
|
-
.attr("y1", "0%")
|
|
162
|
-
.attr("y2", "0%");
|
|
163
|
-
|
|
164
|
-
// append multiple color stops by using D3's data/enter step
|
|
165
|
-
linearGradient.selectAll("stop")
|
|
166
|
-
.data(data)
|
|
167
|
-
.enter().append("stop")
|
|
168
|
-
.attr("offset", d => ((d.value - extent[0]) / (extent[1] - extent[0]) * 100) + "%")
|
|
169
|
-
.attr("stop-color", d => d.color);
|
|
170
|
-
|
|
171
|
-
// append title
|
|
172
|
-
svgLegend
|
|
173
|
-
.append("text")
|
|
174
|
-
.attr("class", "legendTitle")
|
|
175
|
-
.attr("x", 0)
|
|
176
|
-
.attr("y", 43)
|
|
177
|
-
.style("text-anchor", "left")
|
|
178
|
-
.text(legendColorName);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// draw the rectangle and fill with gradient
|
|
182
|
-
svgLegend
|
|
183
|
-
.append("rect")
|
|
184
|
-
.attr("x", 180)
|
|
185
|
-
.attr("y", 30)
|
|
186
|
-
.attr("width", 150)
|
|
187
|
-
.attr("height", 25)
|
|
188
|
-
.style("fill", "url(#"+currentIndex+")");
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// discrete legend using color table colors
|
|
192
|
-
function discColorTableLegend() {
|
|
193
|
-
const itemColor: ItemColor[] = [];
|
|
194
|
-
const itemName: any = [];
|
|
195
|
-
|
|
196
|
-
colorsObject.color.forEach((element: any, key: any) => {
|
|
197
|
-
itemColor.push({color: RGBToHex(element)});
|
|
198
|
-
itemName.push(key);
|
|
199
|
-
})
|
|
200
|
-
|
|
201
|
-
function RGBToHex(rgb: number[]) {
|
|
202
|
-
let r = rgb[1].toString(16),
|
|
203
|
-
g = rgb[2].toString(16),
|
|
204
|
-
b = rgb[3].toString(16);
|
|
205
|
-
if (r.length == 1) r = "0" + r;
|
|
206
|
-
if (g.length == 1) g = "0" + g;
|
|
207
|
-
if (b.length == 1) b = "0" + b;
|
|
208
|
-
return "#" + r + g + b;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const ordinalValues = scaleOrdinal().domain(itemName);
|
|
212
|
-
const colorLegend = discreteLegendUtil(itemColor, "ColorSelector").inputScale(ordinalValues);
|
|
213
|
-
select("svg").append("g").attr("transform", "translate(50,70)").attr("class", "legend").call(colorLegend);
|
|
214
|
-
//const calcLegendHeight = 22 * itemColor.length + 4 * itemColor.length;
|
|
215
|
-
const selectedLegend = select(divRef.current);
|
|
216
|
-
selectedLegend
|
|
217
|
-
.append("text")
|
|
218
|
-
.text(legendColorName)
|
|
219
|
-
.attr("y", 7)
|
|
220
|
-
.style("float", "left")
|
|
221
|
-
.style("width", "30%")
|
|
222
|
-
.style("margin", "10px 0px");
|
|
223
|
-
selectedLegend
|
|
224
|
-
.append("svg")
|
|
225
|
-
.style("margin-top", "13px")
|
|
226
|
-
.style("margin-right", "103px")
|
|
227
|
-
.style("float", "right")
|
|
228
|
-
// .style("width", "60%")
|
|
229
|
-
.style("height", "25px")
|
|
230
|
-
.call(colorLegend);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// discrete legend using d3 colors
|
|
234
|
-
function discD3legend() {
|
|
235
|
-
const itemName: any = [];
|
|
236
|
-
const itemColor: any = [];
|
|
237
|
-
|
|
238
|
-
colorsObject.forEach((element: any, key: any) => {
|
|
239
|
-
itemColor.push({color: element});
|
|
240
|
-
itemName.push(key);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
const ordinalValues = scaleOrdinal(colorsObject).domain(itemName);
|
|
244
|
-
const discreteLegend = discreteLegendUtil(itemColor, "ColorSelector").inputScale(ordinalValues);
|
|
245
|
-
select("svg").append("g").attr("transform", "translate(50,70)").attr("class", "legend").call(discreteLegend);
|
|
246
|
-
const selectedLegend = select(divRef.current);
|
|
247
|
-
selectedLegend
|
|
248
|
-
.append("text")
|
|
249
|
-
.text(legendColorName)
|
|
250
|
-
.attr("y", 7)
|
|
251
|
-
.style("float", "left")
|
|
252
|
-
.style("width", "30%")
|
|
253
|
-
.style("margin", "10px 0px");
|
|
254
|
-
selectedLegend
|
|
255
|
-
.append("svg")
|
|
256
|
-
.style("margin-top", "13px")
|
|
257
|
-
.style("margin-right", "103px")
|
|
258
|
-
.style("float", "right")
|
|
259
|
-
// .style("width", "60%")
|
|
260
|
-
.style("height", "25px")
|
|
261
|
-
.call(discreteLegend);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return (
|
|
265
|
-
<div
|
|
266
|
-
style={{
|
|
267
|
-
right: position[0],
|
|
268
|
-
top: position[1],
|
|
269
|
-
borderRadius: "5px",
|
|
270
|
-
height: "35px",
|
|
271
|
-
marginTop: "15px"
|
|
272
|
-
}}
|
|
273
|
-
>
|
|
274
|
-
<div id="legend" ref={divRef}></div>
|
|
275
|
-
</div>
|
|
276
|
-
);
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
// Based on name return the colors array from color.tables.json file
|
|
280
|
-
export function colorTableData(
|
|
281
|
-
colorName: string,
|
|
282
|
-
colorTables: colorTablesArray
|
|
283
|
-
): [number, number, number, number][] {
|
|
284
|
-
const colorTableData = colorTables.filter(
|
|
285
|
-
(value: colorTablesObj) =>
|
|
286
|
-
value.name.toLowerCase() == colorName.toLowerCase()
|
|
287
|
-
);
|
|
288
|
-
return colorTableData.length > 0 ? colorTableData[0].colors : [];
|
|
289
|
-
}
|