@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,10 +1,12 @@
|
|
|
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
|
const position = [16, 206];
|
|
6
6
|
const continuosColorData = [];
|
|
7
7
|
const continuosD3ColorData = [];
|
|
8
|
+
const discreteColorData = [];
|
|
9
|
+
const discreteD3ColorData = [];
|
|
8
10
|
// code is for color table continuous data
|
|
9
11
|
var colorTableContinuousData = colorTables.filter((element) => {
|
|
10
12
|
return element.discrete == false;
|
|
@@ -13,24 +15,48 @@ colorTableContinuousData.forEach((element) => {
|
|
|
13
15
|
continuosColorData.push({ color: element.colors, name: element.name });
|
|
14
16
|
});
|
|
15
17
|
// code is for d3 continuous data
|
|
16
|
-
var d3continuousData =
|
|
18
|
+
var d3continuousData = d3ColorScales.filter((element) => {
|
|
17
19
|
return element.discrete == false;
|
|
18
20
|
});
|
|
19
21
|
d3continuousData.forEach((element) => {
|
|
20
22
|
continuosD3ColorData.push({ color: element.colors, name: element.name });
|
|
21
23
|
});
|
|
24
|
+
// code is for color table discrete data
|
|
25
|
+
var discreteData = colorTables.filter((element) => {
|
|
26
|
+
return element.discrete == true;
|
|
27
|
+
});
|
|
28
|
+
discreteData.forEach((element) => {
|
|
29
|
+
discreteColorData.push({ color: element.colors, name: element.name });
|
|
30
|
+
});
|
|
31
|
+
// code is for color table d3 discrete data
|
|
32
|
+
var d3discreteData = d3ColorScales.filter((element) => {
|
|
33
|
+
return element.discrete == true;
|
|
34
|
+
});
|
|
35
|
+
d3discreteData.forEach((element) => {
|
|
36
|
+
discreteD3ColorData.push({ color: element.colors, name: element.name });
|
|
37
|
+
});
|
|
22
38
|
export const ColorSelector = ({ useColorTableColors, useD3Colors, }) => {
|
|
23
39
|
let continuousLegend;
|
|
40
|
+
let discreteLegend;
|
|
24
41
|
if (useColorTableColors) {
|
|
25
42
|
continuousLegend = continuosColorData.map((value, key) => {
|
|
26
|
-
return React.createElement(
|
|
43
|
+
return React.createElement("div", null,
|
|
44
|
+
React.createElement(LegendComponent, { position: position + key, colorsObject: value, legendColor: '', legendColorName: '', useContColorTable: true, valueIndex: key }));
|
|
45
|
+
});
|
|
46
|
+
discreteLegend = discreteColorData.map((val, key) => {
|
|
47
|
+
return React.createElement(LegendComponent, { legendColorName: val.name, position: position, colorsObject: discreteColorData[key], useDiscColorTable: true });
|
|
27
48
|
});
|
|
28
49
|
}
|
|
29
50
|
if (useD3Colors) {
|
|
30
51
|
continuousLegend = continuosD3ColorData.map((val, key) => {
|
|
31
|
-
return React.createElement(
|
|
52
|
+
return React.createElement(LegendComponent, { position: position + key, colorsObject: {}, legendColor: val.color, legendColorName: val.name, useContColorTable: false, valueIndex: key + "0" });
|
|
53
|
+
});
|
|
54
|
+
discreteLegend = d3discreteData.map((val) => {
|
|
55
|
+
return React.createElement(LegendComponent, { legendColorName: val.name, position: position, colorsObject: val.colors, useDiscColorTable: false });
|
|
32
56
|
});
|
|
33
57
|
}
|
|
34
|
-
return (React.createElement("div", null,
|
|
58
|
+
return (React.createElement("div", null,
|
|
59
|
+
continuousLegend,
|
|
60
|
+
discreteLegend));
|
|
35
61
|
};
|
|
36
62
|
//# sourceMappingURL=ColorSelectorComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorSelectorComponent.js","sourceRoot":"","sources":["../../../src/component/ColorSelector/ColorSelectorComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,
|
|
1
|
+
{"version":3,"file":"ColorSelectorComponent.js","sourceRoot":"","sources":["../../../src/component/ColorSelector/ColorSelectorComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,WAAW,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AA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EAAE,GAAQ,EAAE,EAAE;YAC/D,OAAO,oBAAC,eAAe,IACX,QAAQ,EAAE,QAAQ,GAAG,GAAG,EACxB,YAAY,EAAE,EAAE,EAChB,WAAW,EAAE,GAAG,CAAC,KAAK,EACtB,eAAe,EAAE,GAAG,CAAC,IAAI,EACzB,iBAAiB,EAAE,KAAK,EACxB,UAAU,EAAE,GAAG,GAAG,GAAG,GAC/B,CAAA;QACN,CAAC,CAAC,CAAC;QAEH,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,GAAQ,EAAE,EAAE;YAC7C,OAAO,oBAAC,eAAe,IACX,eAAe,EAAE,GAAG,CAAC,IAAI,EACzB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,GAAG,CAAC,MAAM,EACxB,iBAAiB,EAAE,KAAK,GAAI,CAAA;QAC5C,CAAC,CAAC,CAAC;KACN;IAED,OAAO,CACH;QACK,gBAAgB;QAChB,cAAc,CACb,CACT,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -2,9 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { Accordion } from "@equinor/eds-core-react";
|
|
3
3
|
import { ColorSelector } from "./ColorSelectorComponent";
|
|
4
4
|
export const ColorSelectorWrapper = () => {
|
|
5
|
-
|
|
6
|
-
// }: legendProps) => {
|
|
7
|
-
return (React.createElement("div", { style: { width: "450px" } },
|
|
5
|
+
return (React.createElement("div", { style: { width: "650px" } },
|
|
8
6
|
React.createElement(Accordion, null,
|
|
9
7
|
React.createElement(Accordion.Item, null,
|
|
10
8
|
React.createElement(Accordion.Header, null, "Color Scales"),
|
|
@@ -13,12 +11,12 @@ export const ColorSelectorWrapper = () => {
|
|
|
13
11
|
React.createElement(Accordion.Item, null,
|
|
14
12
|
React.createElement(Accordion.Header, null, "Geologic Color Scale"),
|
|
15
13
|
React.createElement(Accordion.Panel, null,
|
|
16
|
-
React.createElement(ColorSelector, { useColorTableColors: true, useD3Colors: false
|
|
14
|
+
React.createElement(ColorSelector, { useColorTableColors: true, useD3Colors: false })))),
|
|
17
15
|
React.createElement(Accordion, null,
|
|
18
16
|
React.createElement(Accordion.Item, null,
|
|
19
17
|
React.createElement(Accordion.Header, null, "D3 Color Scale"),
|
|
20
18
|
React.createElement(Accordion.Panel, null,
|
|
21
|
-
React.createElement(ColorSelector, { useColorTableColors: false, useD3Colors: true
|
|
19
|
+
React.createElement(ColorSelector, { useColorTableColors: false, useD3Colors: true })))),
|
|
22
20
|
React.createElement(Accordion, null,
|
|
23
21
|
React.createElement(Accordion.Item, null,
|
|
24
22
|
React.createElement(Accordion.Header, null, "Custom Color Scale"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorTableSelectorWrapper.js","sourceRoot":"","sources":["../../../src/component/ColorSelector/ColorTableSelectorWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAG,MAAM,yBAAyB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"ColorTableSelectorWrapper.js","sourceRoot":"","sources":["../../../src/component/ColorSelector/ColorTableSelectorWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAG,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACrC,OAAO,CACH,6BAAK,KAAK,EAAE,EAAC,KAAK,EAAE,OAAO,EAAC;QACxB,oBAAC,SAAS;YACN,oBAAC,SAAS,CAAC,IAAI;gBACX,oBAAC,SAAS,CAAC,MAAM,uBAEE;gBACnB,oBAAC,SAAS,CAAC,KAAK;oBACZ,oBAAC,SAAS;wBACN,oBAAC,SAAS,CAAC,IAAI;4BACX,oBAAC,SAAS,CAAC,MAAM,+BAEE;4BACnB,oBAAC,SAAS,CAAC,KAAK;gCACZ,oBAAC,aAAa,IAAC,mBAAmB,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,GAAG,CACjD,CACL,CACT;oBACZ,oBAAC,SAAS;wBACN,oBAAC,SAAS,CAAC,IAAI;4BACX,oBAAC,SAAS,CAAC,MAAM,yBAEE;4BACnB,oBAAC,SAAS,CAAC,KAAK;gCACZ,oBAAC,aAAa,IAAC,mBAAmB,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,GAAG,CACjD,CACL,CACT;oBACZ,oBAAC,SAAS;wBACN,oBAAC,SAAS,CAAC,IAAI;4BACX,oBAAC,SAAS,CAAC,MAAM,6BAEE;4BACnB,oBAAC,SAAS,CAAC,KAAK,yBAEE,CACL,CACT,CACE,CACL,CACT,CACV,CACT,CAAC;AACN,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { colorTablesArray } from "../ColorTableTypes";
|
|
3
|
+
interface legendProps {
|
|
4
|
+
position: number[];
|
|
5
|
+
colorsObject?: any;
|
|
6
|
+
legendColor?: any;
|
|
7
|
+
legendColorName: string;
|
|
8
|
+
useContColorTable?: boolean;
|
|
9
|
+
useDiscColorTable?: boolean;
|
|
10
|
+
valueIndex?: any;
|
|
11
|
+
}
|
|
12
|
+
export declare const LegendComponent: React.FC<legendProps>;
|
|
13
|
+
export declare function colorTableData(colorName: string, colorTables: colorTablesArray): [number, number, number, number][];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,228 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legendComponent.js","sourceRoot":"","sources":["../../../src/component/ColorSelector/legendComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,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-1,7 +1,10 @@
|
|
|
1
1
|
import * as d3 from "d3";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const d3ColorScales: ({
|
|
3
3
|
name: string;
|
|
4
4
|
discrete: boolean;
|
|
5
5
|
colors: typeof d3.interpolateSpectral;
|
|
6
|
-
}
|
|
7
|
-
|
|
6
|
+
} | {
|
|
7
|
+
name: string;
|
|
8
|
+
discrete: boolean;
|
|
9
|
+
colors: readonly string[];
|
|
10
|
+
})[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as d3 from "d3";
|
|
2
|
-
export const
|
|
2
|
+
export const d3ColorScales = [
|
|
3
3
|
{
|
|
4
4
|
"name": "Spectral",
|
|
5
5
|
"discrete": false,
|
|
@@ -30,9 +30,55 @@ export const colorScalesCont = [
|
|
|
30
30
|
"discrete": false,
|
|
31
31
|
"colors": d3.interpolateInferno
|
|
32
32
|
},
|
|
33
|
+
{
|
|
34
|
+
"name": "Accent",
|
|
35
|
+
"discrete": true,
|
|
36
|
+
"colors": d3.schemeAccent
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "Dark2",
|
|
40
|
+
"discrete": true,
|
|
41
|
+
"colors": d3.schemeDark2
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "Paired",
|
|
45
|
+
"discrete": true,
|
|
46
|
+
"colors": d3.schemePaired
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"name": "Pastel1",
|
|
50
|
+
"discrete": true,
|
|
51
|
+
"colors": d3.schemePastel1
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "Pastel2",
|
|
55
|
+
"discrete": true,
|
|
56
|
+
"colors": d3.schemePastel2
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "Set1",
|
|
60
|
+
"discrete": true,
|
|
61
|
+
"colors": d3.schemeSet1
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "Set2",
|
|
65
|
+
"discrete": true,
|
|
66
|
+
"colors": d3.schemeSet3
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "Set3",
|
|
70
|
+
"discrete": true,
|
|
71
|
+
"colors": d3.schemeSet3
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "Tableau10",
|
|
75
|
+
"discrete": true,
|
|
76
|
+
"colors": d3.schemeTableau10
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"name": "Category10",
|
|
80
|
+
"discrete": true,
|
|
81
|
+
"colors": d3.schemeCategory10
|
|
82
|
+
},
|
|
33
83
|
];
|
|
34
|
-
export function interpolatorContinuous() {
|
|
35
|
-
return d3.scaleSequential(d3.interpolateInferno);
|
|
36
|
-
}
|
|
37
|
-
;
|
|
38
84
|
//# sourceMappingURL=d3ColorScale.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"d3ColorScale.js","sourceRoot":"","sources":["../../../src/component/Utils/d3ColorScale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"d3ColorScale.js","sourceRoot":"","sources":["../../../src/component/Utils/d3ColorScale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B;QACE,MAAM,EAAE,UAAU;QAClB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,EAAE,CAAC,mBAAmB;KACjC;IACD;QACE,MAAM,EAAE,QAAQ;QAChB,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,EAAE,CAAC,iBAAiB;KAC/B;IACD;QACE,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,EAAE,CAAC,eAAe;KAC7B;IACD;QACE,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,EAAE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able-next-line
|
|
2
|
-
export default function
|
|
2
|
+
export default function discreteLegendUtil(itemColor, ColorSelector) {
|
|
3
3
|
let legendValues = [];
|
|
4
4
|
const cellWidth = 22;
|
|
5
5
|
const cellHeight = 22;
|
|
@@ -15,25 +15,36 @@ export default function legendUtil(itemColor) {
|
|
|
15
15
|
.append("rect")
|
|
16
16
|
.attr("height", cellHeight)
|
|
17
17
|
.attr("width", cellWidth)
|
|
18
|
-
.style("stroke", "black")
|
|
19
|
-
.style("stroke-width", "1px")
|
|
20
18
|
.style("fill", function (d) {
|
|
21
19
|
return d["color"];
|
|
22
20
|
});
|
|
21
|
+
if (!ColorSelector) {
|
|
22
|
+
g.selectAll("g.legendCells.rect").style("stroke", "black").style("stroke-width", "1px");
|
|
23
|
+
}
|
|
23
24
|
// Display the label
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
if (!ColorSelector) {
|
|
26
|
+
g.selectAll("g.legendCells")
|
|
27
|
+
.append("text")
|
|
28
|
+
.attr("class", "breakLabels")
|
|
29
|
+
.style("fill", "#6F6F6F")
|
|
30
|
+
.attr("x", cellWidth + cellPadding)
|
|
31
|
+
.attr("y", 5 + cellHeight / 2)
|
|
32
|
+
.text(function (d) {
|
|
33
|
+
return d["label"];
|
|
34
|
+
});
|
|
35
|
+
}
|
|
33
36
|
// Alighment of cell in straight line
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
if (!ColorSelector) {
|
|
38
|
+
g.selectAll("g.legendCells").attr("transform", function (_d, i) {
|
|
39
|
+
return ("translate(0," + i * (cellHeight + cellPadding) + ")");
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (ColorSelector) {
|
|
43
|
+
g.selectAll("g.legendCells")
|
|
44
|
+
.attr("transform", function (d) {
|
|
45
|
+
return "translate(" + (d.label * cellWidth) + ",0)";
|
|
46
|
+
});
|
|
47
|
+
}
|
|
37
48
|
}
|
|
38
49
|
// display the discrete legend
|
|
39
50
|
g.selectAll("g.legendCells")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discreteLegend.js","sourceRoot":"","sources":["../../../src/component/Utils/discreteLegend.ts"],"names":[],"mappings":"AAIA,2BAA2B;AAC3B,MAAM,CAAC,OAAO,UAAU,
|
|
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,aAAsB;IACrF,IAAI,YAAY,GAAgB,EAAE,CAAC;IACnC,MAAM,SAAS,GAAG,EAAE,CAAC;IACrB,MAAM,UAAU,GAAQ,EAAE,CAAC;IAC3B,MAAM,WAAW,GAAG,CAAC,CAAC;IAEtB,2BAA2B;IAC3B,SAAS,MAAM,CAAC,CAAM;QAClB,SAAS,UAAU;YACf,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;gBAC9B,YAAY,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;YAC3C,CAAC,CAAC,CAAC;YACH,yBAAyB;YACzB,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC;iBACvB,MAAM,CAAC,MAAM,CAAC;iBACd,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;iBAC1B,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;iBACxB,KAAK,CAAC,MAAM,EAAE,UAAU,CAA0B;gBAC/C,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;YACP,IAAI,CAAC,aAAa,EAAE;gBAChB,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE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