@emerson-eps/color-tables 0.2.5 → 0.2.8
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/dist/index.d.ts +8 -5
- package/dist/index.js +7 -4
- package/dist/index.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
- package/src/index.ts +22 -5
- package/tsconfig.json +2 -2
|
@@ -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,kB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|
|
1
|
+
import { ContinuousLegend } from './component/Legend/ContinuousLegend';
|
|
2
|
+
import { colorsArray, rgbValues, RGBToHex } from './component/Utils/continousLegend';
|
|
3
|
+
import { colorTableData, DiscreteColorLegend } from './component/Legend/DiscreteLegend';
|
|
4
|
+
import { colorTablesObj, colorTablesArray } from './component/ColorTableTypes';
|
|
5
|
+
import { ColorSelectorAccordion } from './component/ColorSelector/ColorSelectorAccordion';
|
|
6
|
+
import { ColorSelectorComponent } from './component/ColorSelector/ColorSelectorComponent';
|
|
7
|
+
import { ColorSelectorWrapper } from './component/ColorSelector/ColorSelectorWrapper';
|
|
5
8
|
import * as colorTables from './component/color-tables.json';
|
|
6
|
-
export
|
|
9
|
+
export { ContinuousLegend, colorsArray, rgbValues, RGBToHex, colorTableData, DiscreteColorLegend, colorTablesObj, colorTablesArray, ColorSelectorAccordion, ColorSelectorComponent, ColorSelectorWrapper, colorTables, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { ContinuousLegend } from './component/Legend/ContinuousLegend';
|
|
2
|
+
import { colorsArray, rgbValues, RGBToHex } from './component/Utils/continousLegend';
|
|
3
|
+
import { colorTableData, DiscreteColorLegend } from './component/Legend/DiscreteLegend';
|
|
4
|
+
import { ColorSelectorAccordion } from './component/ColorSelector/ColorSelectorAccordion';
|
|
5
|
+
import { ColorSelectorComponent } from './component/ColorSelector/ColorSelectorComponent';
|
|
6
|
+
import { ColorSelectorWrapper } from './component/ColorSelector/ColorSelectorWrapper';
|
|
4
7
|
import * as colorTables from './component/color-tables.json';
|
|
5
|
-
export
|
|
8
|
+
export { ContinuousLegend, colorsArray, rgbValues, RGBToHex, colorTableData, DiscreteColorLegend, ColorSelectorAccordion, ColorSelectorComponent, ColorSelectorWrapper, colorTables, };
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExF,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExF,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EACH,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,QAAQ,EACR,cAAc,EACd,mBAAmB,EAGnB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,WAAW,GACd,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>
|