@emerson-eps/color-tables 0.2.5 → 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/dist/component/ColorSelector/ColorSelectorAccordion.js +2 -2
- package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +2 -2
- package/dist/component/ColorSelector/ColorSelectorComponent.js +8 -3
- package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorWrapper.d.ts +2 -2
- package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -1
- package/dist/component/Legend/ColorLegend.d.ts +6 -3
- package/dist/component/Legend/ColorLegend.js +10 -2
- package/dist/component/Legend/ColorLegend.js.map +1 -1
- package/dist/component/Legend/ContinuousLegend.js +12 -15
- package/dist/component/Legend/ContinuousLegend.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.js +58 -53
- package/dist/component/Legend/DiscreteLegend.js.map +1 -1
- package/dist/component/Utils/discreteLegend.d.ts +1 -1
- package/dist/component/Utils/discreteLegend.js +120 -64
- package/dist/component/Utils/discreteLegend.js.map +1 -1
- package/package.json +1 -1
- package/src/component/ColorSelector/ColorSelectorAccordion.tsx +2 -2
- package/src/component/ColorSelector/ColorSelectorComponent.tsx +19 -14
- package/src/component/ColorSelector/ColorSelectorWrapper.tsx +5 -5
- package/src/component/Legend/ColorLegend.tsx +14 -4
- package/src/component/Legend/ContinuousLegend.tsx +50 -55
- package/src/component/Legend/DiscreteLegend.tsx +117 -79
- package/src/component/Utils/discreteLegend.ts +125 -75
|
@@ -1,91 +1,147 @@
|
|
|
1
1
|
// eslint-disable-next-line
|
|
2
|
-
export default function discreteLegendUtil(itemColor, isSelectorLegend) {
|
|
3
|
-
var cellWidth = 22;
|
|
4
|
-
var cellHeight = 22;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
//let legendValues: ItemColor[] = [];
|
|
2
|
+
export default function discreteLegendUtil(itemColor, isSelectorLegend, horizontal) {
|
|
3
|
+
// var cellWidth = 22;
|
|
4
|
+
// var cellHeight = 22;
|
|
5
|
+
// if (isSelectorLegend) {
|
|
6
|
+
// cellWidth = 25;
|
|
7
|
+
// cellHeight = 22;
|
|
8
|
+
// }
|
|
9
|
+
var legendValues = [];
|
|
11
10
|
// eslint-disable-next-line
|
|
12
11
|
function legend(g) {
|
|
13
12
|
function drawLegend() {
|
|
14
13
|
// Code to fill the color
|
|
15
14
|
// Styling for color selector legend
|
|
16
|
-
if (isSelectorLegend) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
//if (isSelectorLegend) {
|
|
16
|
+
g.selectAll("g.legendCells")
|
|
17
|
+
.data(itemColor)
|
|
18
|
+
.enter()
|
|
19
|
+
.append("g")
|
|
20
|
+
.append("rect")
|
|
21
|
+
.attr("class", "rectLabel")
|
|
22
|
+
.style("cursor", "pointer")
|
|
23
|
+
.style("pointer-events", "all");
|
|
24
|
+
g.selectAll("rect")
|
|
25
|
+
.attr("height", 1)
|
|
26
|
+
.attr("width", 1)
|
|
27
|
+
.style("fill", function (d) {
|
|
28
|
+
return d["color"];
|
|
29
|
+
});
|
|
30
|
+
if (horizontal && !isSelectorLegend) {
|
|
22
31
|
g.selectAll("rect")
|
|
23
32
|
.attr("x", function (d, i) {
|
|
24
33
|
console.log(d);
|
|
25
34
|
return i;
|
|
26
35
|
})
|
|
27
|
-
.attr("y", 0)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//.attr("x", cellWidth + cellPadding)
|
|
40
|
-
//.attr("y", 5 + cellHeight / 2)
|
|
36
|
+
.attr("y", 0);
|
|
37
|
+
}
|
|
38
|
+
else if (!horizontal && !isSelectorLegend) {
|
|
39
|
+
g.selectAll("rect")
|
|
40
|
+
.attr("y", function (d, i) {
|
|
41
|
+
console.log(d);
|
|
42
|
+
return i;
|
|
43
|
+
})
|
|
44
|
+
.attr("x", 0);
|
|
45
|
+
}
|
|
46
|
+
else if (horizontal == true && isSelectorLegend) {
|
|
47
|
+
g.selectAll("rect")
|
|
41
48
|
.attr("x", function (d, i) {
|
|
42
49
|
console.log(d);
|
|
43
|
-
return i
|
|
50
|
+
return i;
|
|
44
51
|
})
|
|
45
|
-
.attr("y",
|
|
46
|
-
|
|
52
|
+
.attr("y", 0);
|
|
53
|
+
}
|
|
54
|
+
else if (horizontal == false && isSelectorLegend) {
|
|
55
|
+
g.selectAll("rect")
|
|
56
|
+
.attr("y", function (d, i) {
|
|
47
57
|
console.log(d);
|
|
48
58
|
return i;
|
|
49
|
-
})
|
|
59
|
+
})
|
|
60
|
+
.attr("x", 0);
|
|
50
61
|
}
|
|
51
|
-
// styling for main legend
|
|
52
62
|
else {
|
|
53
|
-
g.selectAll("
|
|
54
|
-
.
|
|
55
|
-
.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
60
|
-
// Alighment of cell in straight line
|
|
61
|
-
g.selectAll("g.legendCells").attr("transform", function (_d, i) {
|
|
62
|
-
return ("translate(0," + i * (cellHeight + cellPadding) + ")"
|
|
63
|
-
//"translate(0," + i + ")"
|
|
64
|
-
);
|
|
65
|
-
});
|
|
63
|
+
g.selectAll("rect")
|
|
64
|
+
.attr("x", function (d, i) {
|
|
65
|
+
console.log(d);
|
|
66
|
+
return i;
|
|
67
|
+
})
|
|
68
|
+
.attr("y", 0);
|
|
66
69
|
}
|
|
70
|
+
// Display the labels for legend
|
|
71
|
+
// g.selectAll("g")
|
|
72
|
+
// .style("background", "grey")
|
|
73
|
+
// .append("text")
|
|
74
|
+
// .attr("class", "breakLabels")
|
|
75
|
+
// .style("font-size", "0.4")
|
|
76
|
+
// //.attr("x", cellWidth + cellPadding)
|
|
77
|
+
// //.attr("y", 5 + cellHeight / 2)
|
|
78
|
+
// .attr("x", function (d: any, i: any) {
|
|
79
|
+
// //console.log(d)
|
|
80
|
+
// return i + "." + 25
|
|
81
|
+
// })
|
|
82
|
+
// .attr("y", 1.5)
|
|
83
|
+
// .text(function (d: any, i: any) {
|
|
84
|
+
// //console.log(d)
|
|
85
|
+
// return i;
|
|
86
|
+
// })
|
|
87
|
+
//}
|
|
88
|
+
// styling for main legend
|
|
89
|
+
// else {
|
|
90
|
+
// itemColor.forEach((item, index) => {
|
|
91
|
+
// legendValues[index].color = item.color;
|
|
92
|
+
// });
|
|
93
|
+
// g.selectAll("g.legendCells")
|
|
94
|
+
// .append("text")
|
|
95
|
+
// .attr("class", "breakLabels")
|
|
96
|
+
// .style("fill", "#6F6F6F")
|
|
97
|
+
// .attr("x", cellWidth + cellPadding)
|
|
98
|
+
// .attr("y", 5 + cellHeight / 2)
|
|
99
|
+
// .text(function (d: Record<string, unknown>, i:any) {
|
|
100
|
+
// return d['label'];
|
|
101
|
+
// });
|
|
102
|
+
// g.selectAll("g.legendCells")
|
|
103
|
+
// .style("cursor", "pointer")
|
|
104
|
+
// .append("rect")
|
|
105
|
+
// .attr("height", cellHeight)
|
|
106
|
+
// .attr("width", cellWidth)
|
|
107
|
+
// .style("fill", function (d: Record<string, unknown>) {
|
|
108
|
+
// //console.log('d', d)
|
|
109
|
+
// return d["color"];
|
|
110
|
+
// })
|
|
111
|
+
// // Alighment of cell in straight line
|
|
112
|
+
// g.selectAll("g.legendCells").attr(
|
|
113
|
+
// "transform",
|
|
114
|
+
// function (_d: Record<string, unknown>, i: number) {
|
|
115
|
+
// return (
|
|
116
|
+
// "translate(0," + i * (cellHeight + cellPadding) + ")"
|
|
117
|
+
// //"translate(0," + i + ")"
|
|
118
|
+
// );
|
|
119
|
+
// }
|
|
120
|
+
// );
|
|
121
|
+
// }
|
|
67
122
|
}
|
|
68
123
|
// display the discrete legend
|
|
69
|
-
if (!isSelectorLegend) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
124
|
+
// if (!isSelectorLegend) {
|
|
125
|
+
// // console.log('itemcolor', itemColor)
|
|
126
|
+
// g.selectAll("g.legendCells")
|
|
127
|
+
// .data(legendValues)
|
|
128
|
+
// .enter()
|
|
129
|
+
// .append("g")
|
|
130
|
+
// .attr("class", "legendCells")
|
|
131
|
+
// }
|
|
76
132
|
drawLegend();
|
|
77
133
|
}
|
|
78
134
|
// eslint-disable-next-line
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
135
|
+
legend.inputScale = function (newScale) {
|
|
136
|
+
// eslint-disable-next-line
|
|
137
|
+
var scale = {};
|
|
138
|
+
scale = newScale;
|
|
139
|
+
scale.domain().forEach(function (el) {
|
|
140
|
+
var cellObject = { color: scale(el), label: el };
|
|
141
|
+
legendValues.push(cellObject);
|
|
142
|
+
});
|
|
143
|
+
return this;
|
|
144
|
+
};
|
|
89
145
|
return legend;
|
|
90
146
|
}
|
|
91
147
|
//# sourceMappingURL=discreteLegend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discreteLegend.js","sourceRoot":"","sources":["../../../src/component/Utils/discreteLegend.ts"],"names":[],"mappings":"AAIA,2BAA2B;AAC3B,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,SAAsB,EAAE,gBAA0B
|
|
1
|
+
{"version":3,"file":"discreteLegend.js","sourceRoot":"","sources":["../../../src/component/Utils/discreteLegend.ts"],"names":[],"mappings":"AAIA,2BAA2B;AAC3B,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,SAAsB,EAAE,gBAA0B,EAAE,UAAgB;IAC3G,sBAAsB;IACtB,uBAAuB;IAEvB,0BAA0B;IAC1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mCAAmC;YACnC,0BAA0B;YAC1B,wCAAwC;YACxC,oCAAoC;YACpC,8CAA8C;YAC9C,yCAAyC;YACzC,+DAA+D;YAC/D,iCAAiC;YACjC,cAAc;YACd,mCAAmC;YACnC,kCAAkC;YAClC,0BAA0B;YAC1B,sCAAsC;YACtC,oCAAoC;YACpC,iEAAiE;YACjE,oCAAoC;YACpC,iCAAiC;YACjC,aAAa;YAEb,4CAA4C;YAC5C,yCAAyC;YACzC,uBAAuB;YACvB,8DAA8D;YAC9D,uBAAuB;YACvB,uEAAuE;YACvE,4CAA4C;YAC5C,iBAAiB;YACjB,YAAY;YACZ,SAAS;YACT,IAAI;QACR,CAAC;QAED,8BAA8B;QAC9B,2BAA2B;QAC3B,4CAA4C;QAC5C,mCAAmC;QACnC,0BAA0B;QAC1B,eAAe;QACf,mBAAmB;QACnB,oCAAoC;QACpC,IAAI;QAEJ,UAAU,EAAE,CAAC;IACjB,CAAC;IACD,2BAA2B;IAC3B,MAAM,CAAC,UAAU,GAAG,UAAU,QAAa;QACvC,2BAA2B;QAC3B,IAAI,KAAK,GAAQ,EAAE,CAAC;QACpB,KAAK,GAAG,QAAQ,CAAC;QAEjB,KAAK,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,UAAU,EAAO;YACpC,IAAM,UAAU,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;YACnD,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -7,8 +7,8 @@ export const ColorSelectorAccordion = (props: any) => {
|
|
|
7
7
|
<div className="Container" style={{width: "316px",
|
|
8
8
|
position: "absolute",
|
|
9
9
|
zIndex: 1,
|
|
10
|
-
top:
|
|
11
|
-
right: 5,
|
|
10
|
+
top: props.isHorizontal ? 100 : 30,
|
|
11
|
+
right: props.isHorizontal ? 5 : 165,
|
|
12
12
|
}}>
|
|
13
13
|
<Accordion >
|
|
14
14
|
<Accordion.Item isExpanded>
|
|
@@ -8,7 +8,7 @@ import { colorTablesArray, colorTablesObj } from "../ColorTableTypes";
|
|
|
8
8
|
import discreteLegendUtil from "../Utils/discreteLegend";
|
|
9
9
|
import { color } from "d3-color";
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
declare type legendProps = {
|
|
12
12
|
position: number[];
|
|
13
13
|
colorsObject?: any;
|
|
14
14
|
legendColor?: any;
|
|
@@ -20,7 +20,7 @@ interface legendProps {
|
|
|
20
20
|
getColorMapname?: any | null;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
declare type ItemColor = {
|
|
24
24
|
color: string;
|
|
25
25
|
offset?: number;
|
|
26
26
|
}
|
|
@@ -41,11 +41,16 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
|
|
|
41
41
|
// create an array of steps based on the color scale
|
|
42
42
|
// returns an array of evenly-spaced numbers. Returns the integers from zero to the specified end minus one.
|
|
43
43
|
// d3.range(start, stop, step)
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
let data: any;
|
|
45
|
+
var extent: any
|
|
46
|
+
if (legendColor) {
|
|
47
|
+
data = range(10).map((d) => ({
|
|
48
|
+
color: legendColor(d / 10),
|
|
49
|
+
value: d,
|
|
50
|
+
}));
|
|
51
|
+
// get the array's min and max value
|
|
52
|
+
extent = d3.extent(data, (d: any) => d?.value);
|
|
53
|
+
}
|
|
49
54
|
|
|
50
55
|
const handleChange = React.useCallback(() => {
|
|
51
56
|
// continous legend with colortable colors
|
|
@@ -54,11 +59,11 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
|
|
|
54
59
|
}
|
|
55
60
|
// continous legend with d3 colors
|
|
56
61
|
else if (data && !useContColorTable) {
|
|
57
|
-
|
|
62
|
+
const arrayData: any = []
|
|
58
63
|
data.forEach((colorsObject: any) => {
|
|
59
64
|
arrayData.push([0 + "." + colorsObject.value, color(colorsObject.color)?.rgb().r, color(colorsObject.color)?.rgb().g, color(colorsObject.color)?.rgb().b])
|
|
60
65
|
});
|
|
61
|
-
colorScaleData(arrayData, true);
|
|
66
|
+
colorScaleData({ arrayData, legendColorName }, true);
|
|
62
67
|
}
|
|
63
68
|
// discrete legend with colortable colors
|
|
64
69
|
else if (colorsObject && Object.keys(colorsObject).length > 0 && useDiscColorTable) {
|
|
@@ -123,7 +128,7 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
|
|
|
123
128
|
.style("height", "30px")
|
|
124
129
|
|
|
125
130
|
const defs = svgLegend.append("defs");
|
|
126
|
-
|
|
131
|
+
const currentIndex = "linear-gradient-" + valueIndex;
|
|
127
132
|
// append a linearGradient element to the defs and give it a unique id
|
|
128
133
|
const linearGradient = defs
|
|
129
134
|
.append("linearGradient")
|
|
@@ -182,7 +187,7 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
|
|
|
182
187
|
.style("height", "50px")
|
|
183
188
|
|
|
184
189
|
const defs = svgLegend.append("defs");
|
|
185
|
-
|
|
190
|
+
const currentIndex = "linear-gradient-" + valueIndex;
|
|
186
191
|
// append a linearGradient element to the defs and give it a unique id
|
|
187
192
|
const linearGradient = defs
|
|
188
193
|
.append("linearGradient")
|
|
@@ -196,8 +201,8 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
|
|
|
196
201
|
linearGradient.selectAll("stop")
|
|
197
202
|
.data(data)
|
|
198
203
|
.enter().append("stop")
|
|
199
|
-
.attr("offset", d => ((d.value - extent[0]) / (extent[1] - extent[0]) * 100) + "%")
|
|
200
|
-
.attr("stop-color", d => d.color);
|
|
204
|
+
.attr("offset", (d: any) => ((d.value - extent[0]) / (extent[1] - extent[0]) * 100) + "%")
|
|
205
|
+
.attr("stop-color", (d: any) => d.color);
|
|
201
206
|
|
|
202
207
|
// append title
|
|
203
208
|
svgLegend
|
|
@@ -277,7 +282,7 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
|
|
|
277
282
|
itemName.push(key);
|
|
278
283
|
});
|
|
279
284
|
//const ordinalValues = scaleOrdinal(colorsObject).domain(itemName);
|
|
280
|
-
|
|
285
|
+
const count = itemName.length
|
|
281
286
|
const discreteLegend = discreteLegendUtil(itemColor, true);
|
|
282
287
|
select("svg").append("g").attr("transform", "translate(50,70)").attr("class", "legend").call(discreteLegend);
|
|
283
288
|
const selectedLegend = select(divRef.current);
|
|
@@ -9,14 +9,14 @@ const continuosD3ColorData: any = [];
|
|
|
9
9
|
const discreteColorData: any = [];
|
|
10
10
|
const discreteD3ColorData: any = [];
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
declare type legendProps = {
|
|
13
13
|
useColorTableColors: boolean,
|
|
14
14
|
useD3Colors: boolean,
|
|
15
15
|
colorScaleObject: any
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
// Continuous legend using color table data
|
|
19
|
-
|
|
19
|
+
const colorTableContinuousData = colorTables.filter((element: any) => {
|
|
20
20
|
return element.discrete == false;
|
|
21
21
|
});
|
|
22
22
|
|
|
@@ -25,7 +25,7 @@ colorTableContinuousData.forEach((element: any) => {
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
// Continuous legend using d3 data
|
|
28
|
-
|
|
28
|
+
const d3continuousData = d3ColorScales.filter((element: any) => {
|
|
29
29
|
return element.discrete == false;
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -34,7 +34,7 @@ d3continuousData.forEach((element: any) => {
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
// Discrete legend using color table data
|
|
37
|
-
|
|
37
|
+
const discreteData = colorTables.filter((element: any) => {
|
|
38
38
|
return element.discrete == true;
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -43,7 +43,7 @@ discreteData.forEach((element: any) => {
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
// Discrete legend using d3 data
|
|
46
|
-
|
|
46
|
+
const d3discreteData = d3ColorScales.filter((element: any) => {
|
|
47
47
|
return element.discrete == true;
|
|
48
48
|
});
|
|
49
49
|
|
|
@@ -4,7 +4,7 @@ import { ContinuousLegend } from "./ContinuousLegend";
|
|
|
4
4
|
import {useCallback} from "react";
|
|
5
5
|
import { ColorSelectorAccordion } from "../ColorSelector/ColorSelectorAccordion";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
declare type ColorLegendProps = {
|
|
8
8
|
colorTables: any;
|
|
9
9
|
min: number;
|
|
10
10
|
max: number;
|
|
@@ -12,7 +12,8 @@ interface ColorLegendProps {
|
|
|
12
12
|
position?: number[] | null;
|
|
13
13
|
colorName: string;
|
|
14
14
|
horizontal?: boolean | null;
|
|
15
|
-
discreteData:
|
|
15
|
+
discreteData: { objects: Record<string, [number[], number]> };
|
|
16
|
+
getColorMapname?: any;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
// Todo: Adapt it for other layers too
|
|
@@ -24,7 +25,8 @@ const ColorLegend: React.FC<ColorLegendProps> = ({
|
|
|
24
25
|
max,
|
|
25
26
|
dataObjectName,
|
|
26
27
|
colorName,
|
|
27
|
-
discreteData
|
|
28
|
+
discreteData,
|
|
29
|
+
getColorMapname
|
|
28
30
|
}: ColorLegendProps) => {
|
|
29
31
|
|
|
30
32
|
const [isToggled, setIsToggled] = React.useState(false);
|
|
@@ -37,6 +39,14 @@ const ColorLegend: React.FC<ColorLegendProps> = ({
|
|
|
37
39
|
|
|
38
40
|
// Get new colorscale from colorselector and update legend
|
|
39
41
|
const colorScaleObject = React.useCallback((data: any, value: any) => {
|
|
42
|
+
// update color map layer
|
|
43
|
+
if (data.name && getColorMapname) {
|
|
44
|
+
getColorMapname(data.name);
|
|
45
|
+
}
|
|
46
|
+
// d3 color name
|
|
47
|
+
else if (getColorMapname) {
|
|
48
|
+
getColorMapname(data.legendColorName);
|
|
49
|
+
}
|
|
40
50
|
setUpdateLegendColor(data);
|
|
41
51
|
setIsCont(value);
|
|
42
52
|
}, []);
|
|
@@ -70,7 +80,7 @@ const ColorLegend: React.FC<ColorLegendProps> = ({
|
|
|
70
80
|
</div>
|
|
71
81
|
<div>
|
|
72
82
|
{isToggled && (
|
|
73
|
-
<ColorSelectorAccordion colorScaleObject={colorScaleObject} />
|
|
83
|
+
<ColorSelectorAccordion colorScaleObject={colorScaleObject} isHorizontal={horizontal} />
|
|
74
84
|
)}
|
|
75
85
|
</div>
|
|
76
86
|
</div>
|
|
@@ -49,7 +49,7 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
49
49
|
try {
|
|
50
50
|
// fix for dash wrapper
|
|
51
51
|
if (typeof colorTables === "string") {
|
|
52
|
-
|
|
52
|
+
const res = await fetch(colorTables);
|
|
53
53
|
dataSet = await res.json()
|
|
54
54
|
}
|
|
55
55
|
//Return the matched colors array from color.tables.json file
|
|
@@ -58,8 +58,6 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
58
58
|
:
|
|
59
59
|
colorsArray(colorName, colorTables);
|
|
60
60
|
|
|
61
|
-
//let legendColors = colorsArray(colorName, colorTables);
|
|
62
|
-
|
|
63
61
|
// Update color of legend based on color selector scales
|
|
64
62
|
// data is passed on click upon color scales
|
|
65
63
|
if (updateLegend) {
|
|
@@ -68,8 +66,8 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
68
66
|
legendColors = updateLegend.color;
|
|
69
67
|
}
|
|
70
68
|
// legend using d3 data
|
|
71
|
-
else if (updateLegend.
|
|
72
|
-
legendColors = updateLegend
|
|
69
|
+
else if (updateLegend.arrayData) {
|
|
70
|
+
legendColors = updateLegend.arrayData;
|
|
73
71
|
}
|
|
74
72
|
}
|
|
75
73
|
// main continuous legend
|
|
@@ -84,7 +82,7 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
84
82
|
color: RGBToHex(value).color,
|
|
85
83
|
});
|
|
86
84
|
});
|
|
87
|
-
|
|
85
|
+
|
|
88
86
|
const colorScale = scaleSequential().domain([min, max]);
|
|
89
87
|
// append a defs (for definition) element to your SVG
|
|
90
88
|
const svgLegend = select(divRef.current)
|
|
@@ -100,31 +98,29 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
100
98
|
// .style("transform", "rotate(270deg)")
|
|
101
99
|
// .style("margin-top", "80px");
|
|
102
100
|
.attr("width", "100")
|
|
103
|
-
.attr("height", "
|
|
101
|
+
.attr("height", "190");
|
|
104
102
|
linearGradient = defs
|
|
105
103
|
.append("linearGradient")
|
|
106
104
|
.attr("id", "linear-gradient")
|
|
107
105
|
.attr("x1", "0%")
|
|
108
|
-
.attr("x2", "0%")
|
|
106
|
+
.attr("x2", "0%")
|
|
109
107
|
.attr("y1", "0%")
|
|
110
|
-
.attr("y2", "100%");
|
|
111
|
-
}
|
|
108
|
+
.attr("y2", "100%"); //since it's a vertical linear gradient
|
|
109
|
+
}
|
|
112
110
|
// horizontal legend
|
|
113
111
|
else {
|
|
114
|
-
svgLegend
|
|
115
|
-
|
|
116
|
-
.attr("height", "165")
|
|
117
|
-
|
|
112
|
+
svgLegend.attr("width", "200").attr("height", "90");
|
|
113
|
+
|
|
118
114
|
// append a linearGradient element to the defs and give it a unique id
|
|
119
115
|
linearGradient = defs
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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%");
|
|
126
122
|
}
|
|
127
|
-
|
|
123
|
+
|
|
128
124
|
// append multiple color stops by using D3's data/enter step
|
|
129
125
|
linearGradient
|
|
130
126
|
.selectAll("stop")
|
|
@@ -146,7 +142,7 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
146
142
|
.attr("y", 20)
|
|
147
143
|
.style("text-anchor", "left")
|
|
148
144
|
.text(dataObjectName);
|
|
149
|
-
|
|
145
|
+
|
|
150
146
|
// vertical legend
|
|
151
147
|
if (!horizontal) {
|
|
152
148
|
// draw the rectangle and fill with gradient
|
|
@@ -162,43 +158,45 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
162
158
|
else {
|
|
163
159
|
// draw the rectangle and fill with gradient
|
|
164
160
|
svgLegend
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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)");
|
|
171
167
|
}
|
|
172
168
|
|
|
173
|
-
//create tick marks
|
|
169
|
+
// create tick marks
|
|
174
170
|
// range varies the size of the axis
|
|
175
171
|
const xLeg = scaleLinear().domain([min, max]).range([10, 158]);
|
|
176
|
-
const yLeg = scaleLinear().domain([min, max]).range([10,
|
|
177
|
-
|
|
178
|
-
const horizontalAxisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
|
|
179
|
-
var VerticalAxisLeg = axisRight(yLeg).tickSize(24).tickValues(colorScale.domain());
|
|
172
|
+
const yLeg = scaleLinear().domain([min, max]).range([10, 158]);
|
|
180
173
|
|
|
174
|
+
const horizontalAxisLeg = axisBottom(xLeg).tickValues(
|
|
175
|
+
colorScale.domain()
|
|
176
|
+
);
|
|
177
|
+
const VerticalAxisLeg = axisRight(yLeg)
|
|
178
|
+
.tickSize(24)
|
|
179
|
+
.tickValues(colorScale.domain());
|
|
181
180
|
|
|
182
181
|
if (horizontal) {
|
|
183
182
|
svgLegend
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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);
|
|
191
190
|
} else {
|
|
192
191
|
svgLegend
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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);
|
|
199
198
|
}
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
199
|
+
} catch (error) {
|
|
202
200
|
console.error(error);
|
|
203
201
|
}
|
|
204
202
|
}
|
|
@@ -207,15 +205,12 @@ export const ContinuousLegend: React.FC<legendProps> = ({
|
|
|
207
205
|
<div
|
|
208
206
|
style={{
|
|
209
207
|
position: "absolute",
|
|
210
|
-
right: position ? position[0] :
|
|
211
|
-
top: position ? position[1] :
|
|
208
|
+
right: position ? position[0] : " ",
|
|
209
|
+
top: position ? position[1] : " ",
|
|
210
|
+
zIndex: 999,
|
|
212
211
|
}}
|
|
213
212
|
>
|
|
214
|
-
<div id="legend" ref={divRef}
|
|
215
|
-
style={{
|
|
216
|
-
width: horizontal ? "220px" : "100px",
|
|
217
|
-
height: horizontal ? "165px" : "150px",
|
|
218
|
-
}}></div>
|
|
213
|
+
<div id="legend" ref={divRef}></div>
|
|
219
214
|
</div>
|
|
220
215
|
);
|
|
221
216
|
};
|