@emerson-eps/color-tables 0.2.0 → 0.2.1
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/ColorSelectorComponent.js +32 -6
- package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
- package/dist/component/ColorSelector/ColorTableSelectorWrapper.js +3 -5
- package/dist/component/ColorSelector/ColorTableSelectorWrapper.js.map +1 -1
- package/dist/component/ColorSelector/legendComponent.d.ts +14 -0
- package/dist/component/ColorSelector/legendComponent.js +228 -0
- package/dist/component/ColorSelector/legendComponent.js.map +1 -0
- package/dist/component/Utils/d3ColorScale.d.ts +6 -3
- package/dist/component/Utils/d3ColorScale.js +51 -5
- package/dist/component/Utils/d3ColorScale.js.map +1 -1
- package/dist/component/Utils/discreteLegend.d.ts +2 -2
- package/dist/component/Utils/discreteLegend.js +26 -15
- package/dist/component/Utils/discreteLegend.js.map +1 -1
- package/package.json +1 -1
- package/src/component/ColorSelector/ColorSelectorComponent.tsx +55 -14
- package/src/component/ColorSelector/ColorTableSelectorWrapper.tsx +4 -6
- package/src/component/ColorSelector/legendComponent.tsx +289 -0
- package/src/component/Utils/d3ColorScale.ts +52 -7
- package/src/component/Utils/discreteLegend.ts +34 -23
- package/tsconfig.json +1 -1
- package/dist/component/Legend/legendContinous.d.ts +0 -11
- package/dist/component/Legend/legendContinous.js +0 -132
- package/dist/component/Legend/legendContinous.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLgends/MD.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLgends/MD.stories.js +0 -29
- package/dist/stories/ColorLegends/ContinousLgends/MD.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLgends/NTG.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLgends/NTG.stories.js +0 -29
- package/dist/stories/ColorLegends/ContinousLgends/NTG.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLgends/PermTot.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLgends/PermTot.stories.js +0 -29
- package/dist/stories/ColorLegends/ContinousLgends/PermTot.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLgends/Permeability.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLgends/Permeability.stories.js +0 -29
- package/dist/stories/ColorLegends/ContinousLgends/Permeability.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLgends/PoroTot.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLgends/PoroTot.stories.js +0 -29
- package/dist/stories/ColorLegends/ContinousLgends/PoroTot.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLgends/Porosity.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLgends/Porosity.stories.js +0 -29
- package/dist/stories/ColorLegends/ContinousLgends/Porosity.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLgends/SW.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLgends/SW.stories.js +0 -29
- package/dist/stories/ColorLegends/ContinousLgends/SW.stories.js.map +0 -1
- package/src/component/Legend/legendContinous.tsx +0 -175
- package/src/stories/ColorLegends/ContinousLgends/MD.stories.jsx +0 -31
- package/src/stories/ColorLegends/ContinousLgends/NTG.stories.jsx +0 -31
- package/src/stories/ColorLegends/ContinousLgends/PermTot.stories.jsx +0 -31
- package/src/stories/ColorLegends/ContinousLgends/Permeability.stories.jsx +0 -31
- package/src/stories/ColorLegends/ContinousLgends/PoroTot.stories.jsx +0 -31
- package/src/stories/ColorLegends/ContinousLgends/Porosity.stories.jsx +0 -31
- package/src/stories/ColorLegends/ContinousLgends/SW.stories.jsx +0 -31
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { LegendContinous } from "../Legend/legendContinous";
|
|
3
2
|
import * as colorTables from "../color-tables.json";
|
|
4
|
-
import {
|
|
3
|
+
import {d3ColorScales} from "../Utils/d3ColorScale"
|
|
4
|
+
import {LegendComponent} from "./legendComponent";
|
|
5
5
|
|
|
6
6
|
const position = [16, 206];
|
|
7
7
|
const continuosColorData: any = []
|
|
8
8
|
const continuosD3ColorData: any = []
|
|
9
|
+
const discreteColorData: any = []
|
|
10
|
+
const discreteD3ColorData: any = []
|
|
9
11
|
|
|
10
12
|
interface legendProps {
|
|
11
13
|
useColorTableColors: boolean
|
|
@@ -22,7 +24,7 @@ colorTableContinuousData.forEach((element: any) => {
|
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
// code is for d3 continuous data
|
|
25
|
-
var d3continuousData =
|
|
27
|
+
var d3continuousData = d3ColorScales.filter((element: any) => {
|
|
26
28
|
return element.discrete == false;
|
|
27
29
|
});
|
|
28
30
|
|
|
@@ -30,39 +32,78 @@ d3continuousData.forEach((element: any) => {
|
|
|
30
32
|
continuosD3ColorData.push({color: element.colors, name: element.name})
|
|
31
33
|
});
|
|
32
34
|
|
|
35
|
+
// code is for color table discrete data
|
|
36
|
+
var discreteData = colorTables.filter((element: any) => {
|
|
37
|
+
return element.discrete == true;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
discreteData.forEach((element: any) => {
|
|
41
|
+
discreteColorData.push({color: element.colors, name: element.name})
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// code is for color table d3 discrete data
|
|
45
|
+
var d3discreteData = d3ColorScales.filter((element: any) => {
|
|
46
|
+
return element.discrete == true;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
d3discreteData.forEach((element: any) => {
|
|
50
|
+
discreteD3ColorData.push({color: element.colors, name: element.name})
|
|
51
|
+
});
|
|
52
|
+
|
|
33
53
|
export const ColorSelector: React.FC<legendProps> = ({
|
|
34
54
|
useColorTableColors,
|
|
35
55
|
useD3Colors,
|
|
36
56
|
}: legendProps) => {
|
|
37
57
|
let continuousLegend;
|
|
58
|
+
let discreteLegend;
|
|
59
|
+
|
|
38
60
|
if (useColorTableColors) {
|
|
39
61
|
continuousLegend = continuosColorData.map((value: any, key: any) => {
|
|
40
|
-
return <
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
62
|
+
return <div>
|
|
63
|
+
<LegendComponent
|
|
64
|
+
position={position + key}
|
|
65
|
+
colorsObject={value}
|
|
66
|
+
legendColor={''}
|
|
67
|
+
legendColorName={''}
|
|
68
|
+
useContColorTable={true}
|
|
69
|
+
valueIndex={key}
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
discreteLegend = discreteColorData.map((val: any, key: any) => {
|
|
75
|
+
return <LegendComponent
|
|
76
|
+
legendColorName={val.name}
|
|
77
|
+
position={position}
|
|
78
|
+
colorsObject={discreteColorData[key]}
|
|
79
|
+
useDiscColorTable={true} />
|
|
48
80
|
});
|
|
49
81
|
}
|
|
50
82
|
if (useD3Colors) {
|
|
51
83
|
continuousLegend = continuosD3ColorData.map((val: any, key: any) => {
|
|
52
|
-
return <
|
|
84
|
+
return <LegendComponent
|
|
53
85
|
position={position + key}
|
|
54
|
-
|
|
86
|
+
colorsObject={{}}
|
|
55
87
|
legendColor={val.color}
|
|
56
88
|
legendColorName={val.name}
|
|
57
89
|
useContColorTable={false}
|
|
58
90
|
valueIndex={key + "0"}
|
|
59
91
|
/>
|
|
60
92
|
});
|
|
93
|
+
|
|
94
|
+
discreteLegend = d3discreteData.map((val: any) => {
|
|
95
|
+
return <LegendComponent
|
|
96
|
+
legendColorName={val.name}
|
|
97
|
+
position={position}
|
|
98
|
+
colorsObject={val.colors}
|
|
99
|
+
useDiscColorTable={false} />
|
|
100
|
+
});
|
|
61
101
|
}
|
|
62
102
|
|
|
63
103
|
return (
|
|
64
104
|
<div>
|
|
65
|
-
{continuousLegend}
|
|
105
|
+
{continuousLegend}
|
|
106
|
+
{discreteLegend}
|
|
66
107
|
</div>
|
|
67
108
|
);
|
|
68
109
|
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Accordion } from "@equinor/eds-core-react";
|
|
3
|
-
import {ColorSelector} from "./ColorSelectorComponent";
|
|
3
|
+
import { ColorSelector } from "./ColorSelectorComponent";
|
|
4
4
|
|
|
5
5
|
export const ColorSelectorWrapper = () => {
|
|
6
|
-
// export const ColorSelector: React.FC<legendProps> = ({
|
|
7
|
-
// }: legendProps) => {
|
|
8
6
|
return (
|
|
9
|
-
<div style={{width: "
|
|
7
|
+
<div style={{width: "650px"}}>
|
|
10
8
|
<Accordion >
|
|
11
9
|
<Accordion.Item>
|
|
12
10
|
<Accordion.Header>
|
|
@@ -19,7 +17,7 @@ export const ColorSelectorWrapper = () => {
|
|
|
19
17
|
Geologic Color Scale
|
|
20
18
|
</Accordion.Header>
|
|
21
19
|
<Accordion.Panel>
|
|
22
|
-
<ColorSelector useColorTableColors={true} useD3Colors={false}
|
|
20
|
+
<ColorSelector useColorTableColors={true} useD3Colors={false}/>
|
|
23
21
|
</Accordion.Panel>
|
|
24
22
|
</Accordion.Item>
|
|
25
23
|
</Accordion>
|
|
@@ -29,7 +27,7 @@ export const ColorSelectorWrapper = () => {
|
|
|
29
27
|
D3 Color Scale
|
|
30
28
|
</Accordion.Header>
|
|
31
29
|
<Accordion.Panel>
|
|
32
|
-
<ColorSelector useColorTableColors={false} useD3Colors={true}
|
|
30
|
+
<ColorSelector useColorTableColors={false} useD3Colors={true}/>
|
|
33
31
|
</Accordion.Panel>
|
|
34
32
|
</Accordion.Item>
|
|
35
33
|
</Accordion>
|
|
@@ -0,0 +1,289 @@
|
|
|
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
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as d3 from "d3";
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const d3ColorScales = [
|
|
4
4
|
{
|
|
5
5
|
"name": "Spectral",
|
|
6
6
|
"discrete": false,
|
|
@@ -31,9 +31,54 @@ export const colorScalesCont = [
|
|
|
31
31
|
"discrete": false,
|
|
32
32
|
"colors": d3.interpolateInferno
|
|
33
33
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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,12 +1,12 @@
|
|
|
1
1
|
declare type ItemColor = {
|
|
2
|
-
color:
|
|
2
|
+
color: any;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line
|
|
6
|
-
export default function
|
|
6
|
+
export default function discreteLegendUtil(itemColor: ItemColor[], ColorSelector?: string): any {
|
|
7
7
|
let legendValues: ItemColor[] = [];
|
|
8
8
|
const cellWidth = 22;
|
|
9
|
-
const cellHeight = 22;
|
|
9
|
+
const cellHeight: any = 22;
|
|
10
10
|
const cellPadding = 4;
|
|
11
11
|
|
|
12
12
|
// eslint-disable-next-line
|
|
@@ -20,30 +20,41 @@ export default function legendUtil(itemColor: ItemColor[]): any {
|
|
|
20
20
|
.append("rect")
|
|
21
21
|
.attr("height", cellHeight)
|
|
22
22
|
.attr("width", cellWidth)
|
|
23
|
-
.style("stroke", "black")
|
|
24
|
-
.style("stroke-width", "1px")
|
|
25
23
|
.style("fill", function (d: Record<string, unknown>) {
|
|
26
24
|
return d["color"];
|
|
27
25
|
});
|
|
26
|
+
if (!ColorSelector) {
|
|
27
|
+
g.selectAll("g.legendCells.rect").style("stroke", "black").style("stroke-width", "1px")
|
|
28
|
+
}
|
|
28
29
|
// Display the label
|
|
29
|
-
|
|
30
|
-
.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
if (!ColorSelector) {
|
|
31
|
+
g.selectAll("g.legendCells")
|
|
32
|
+
.append("text")
|
|
33
|
+
.attr("class", "breakLabels")
|
|
34
|
+
.style("fill", "#6F6F6F")
|
|
35
|
+
.attr("x", cellWidth + cellPadding)
|
|
36
|
+
.attr("y", 5 + cellHeight / 2)
|
|
37
|
+
.text(function (d: Record<string, unknown>) {
|
|
38
|
+
return d["label"];
|
|
39
|
+
});
|
|
40
|
+
}
|
|
38
41
|
// Alighment of cell in straight line
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
if (!ColorSelector) {
|
|
43
|
+
g.selectAll("g.legendCells").attr(
|
|
44
|
+
"transform",
|
|
45
|
+
function (_d: Record<string, unknown>, i: number) {
|
|
46
|
+
return (
|
|
47
|
+
"translate(0," + i * (cellHeight + cellPadding) + ")"
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (ColorSelector) {
|
|
53
|
+
g.selectAll("g.legendCells")
|
|
54
|
+
.attr("transform", function(d: any) {
|
|
55
|
+
return "translate(" + (d.label * cellWidth) + ",0)" }
|
|
56
|
+
);
|
|
57
|
+
}
|
|
47
58
|
}
|
|
48
59
|
// display the discrete legend
|
|
49
60
|
g.selectAll("g.legendCells")
|
|
@@ -66,4 +77,4 @@ export default function legendUtil(itemColor: ItemColor[]): any {
|
|
|
66
77
|
return this;
|
|
67
78
|
};
|
|
68
79
|
return legend;
|
|
69
|
-
}
|
|
80
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
interface legendProps {
|
|
3
|
-
position?: number[] | null;
|
|
4
|
-
colorArray: any;
|
|
5
|
-
legendColor: any;
|
|
6
|
-
legendColorName: string;
|
|
7
|
-
useContColorTable: boolean;
|
|
8
|
-
valueIndex: any;
|
|
9
|
-
}
|
|
10
|
-
export declare const LegendContinous: React.FC<legendProps>;
|
|
11
|
-
export {};
|