@emerson-eps/color-tables 0.0.3 → 0.1.0
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/color-tables.json +12 -12
- package/package.json +1 -1
- package/react-app/.storybook/main.js +11 -0
- package/react-app/.storybook/preview.js +9 -0
- package/react-app/README.md +70 -0
- package/react-app/package-lock.json +21781 -0
- package/react-app/package.json +51 -0
- package/react-app/public/favicon.ico +0 -0
- package/react-app/public/index.html +43 -0
- package/react-app/public/logo192.png +0 -0
- package/react-app/public/logo512.png +0 -0
- package/react-app/public/manifest.json +25 -0
- package/react-app/public/robots.txt +3 -0
- package/react-app/src/App.css +38 -0
- package/react-app/src/App.js +25 -0
- package/react-app/src/App.test.js +8 -0
- package/react-app/src/component/ColorTableTypes.ts +6 -0
- package/react-app/src/component/Legend/ContinuousLegend.tsx +131 -0
- package/react-app/src/component/Legend/DiscreteLegend.tsx +126 -0
- package/react-app/src/component/Utils/continousLegend.ts +81 -0
- package/react-app/src/component/Utils/discreteLegend.ts +69 -0
- package/react-app/src/component/WelllayerTemplateTypes.ts +15 -0
- package/react-app/src/component/color-tables.json +189 -0
- package/react-app/src/component/welllayer_template.json +89 -0
- package/react-app/src/index.css +13 -0
- package/react-app/src/index.js +17 -0
- package/react-app/src/logo.svg +1 -0
- package/react-app/src/reportWebVitals.js +13 -0
- package/react-app/src/setupTests.js +5 -0
- package/react-app/src/stories/ColorLegends/ContinousLgends/MD.stories.jsx +31 -0
- package/react-app/src/stories/ColorLegends/ContinousLgends/NTG.stories.jsx +31 -0
- package/react-app/src/stories/ColorLegends/ContinousLgends/PermTot.stories.jsx +31 -0
- package/react-app/src/stories/ColorLegends/ContinousLgends/Permeability.stories.jsx +31 -0
- package/react-app/src/stories/ColorLegends/ContinousLgends/PoroTot.stories.jsx +31 -0
- package/react-app/src/stories/ColorLegends/ContinousLgends/Porosity.stories.jsx +31 -0
- package/react-app/src/stories/ColorLegends/ContinousLgends/SW.stories.jsx +31 -0
- package/react-app/src/stories/ColorLegends/DiscreteLegends/Facies.stories.jsx +41 -0
- package/react-app/src/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.jsx +41 -0
- package/react-app/src/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.jsx +33 -0
- package/react-app/src/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.jsx +33 -0
- package/react-app/src/stories/ColorLegends/DiscreteLegends/RDE.stories.jsx +36 -0
- package/react-app/src/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.jsx +47 -0
- package/react-app/src/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.jsx +36 -0
- package/react-app/src/stories/ColorLegends/DiscreteLegends/Zonelog.stories.jsx +48 -0
- package/react-app/src/stories/assets/code-brackets.svg +1 -0
- package/react-app/src/stories/assets/colors.svg +1 -0
- package/react-app/src/stories/assets/comments.svg +1 -0
- package/react-app/src/stories/assets/direction.svg +1 -0
- package/react-app/src/stories/assets/flow.svg +1 -0
- package/react-app/src/stories/assets/plugin.svg +1 -0
- package/react-app/src/stories/assets/repo.svg +1 -0
- package/react-app/src/stories/assets/stackalt.svg +1 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-app",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@testing-library/jest-dom": "^5.16.1",
|
|
7
|
+
"@testing-library/react": "^11.2.7",
|
|
8
|
+
"@testing-library/user-event": "^12.8.3",
|
|
9
|
+
"d3": "^7.2.0",
|
|
10
|
+
"d3-color": "^3.0.1",
|
|
11
|
+
"d3-interpolate": "^3.0.1",
|
|
12
|
+
"react": "^17.0.2",
|
|
13
|
+
"react-dom": "^17.0.2",
|
|
14
|
+
"react-scripts": "4.0.3",
|
|
15
|
+
"web-vitals": "^1.1.2"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"start": "react-scripts start",
|
|
19
|
+
"build": "react-scripts build",
|
|
20
|
+
"test": "react-scripts test",
|
|
21
|
+
"eject": "react-scripts eject",
|
|
22
|
+
"storybook": "start-storybook -p 6006",
|
|
23
|
+
"build-storybook": "build-storybook"
|
|
24
|
+
},
|
|
25
|
+
"eslintConfig": {
|
|
26
|
+
"extends": [
|
|
27
|
+
"react-app",
|
|
28
|
+
"react-app/jest"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"browserslist": {
|
|
32
|
+
"production": [
|
|
33
|
+
">0.2%",
|
|
34
|
+
"not dead",
|
|
35
|
+
"not op_mini all"
|
|
36
|
+
],
|
|
37
|
+
"development": [
|
|
38
|
+
"last 1 chrome version",
|
|
39
|
+
"last 1 firefox version",
|
|
40
|
+
"last 1 safari version"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@babel/core": "^7.16.0",
|
|
45
|
+
"@storybook/addon-actions": "^6.4.9",
|
|
46
|
+
"@storybook/addon-essentials": "^6.4.9",
|
|
47
|
+
"@storybook/addon-links": "^6.4.9",
|
|
48
|
+
"@storybook/react": "^6.4.9",
|
|
49
|
+
"babel-loader": "^8.2.3"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
|
+
<meta name="theme-color" content="#000000" />
|
|
8
|
+
<meta
|
|
9
|
+
name="description"
|
|
10
|
+
content="Web site created using create-react-app"
|
|
11
|
+
/>
|
|
12
|
+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
|
13
|
+
<!--
|
|
14
|
+
manifest.json provides metadata used when your web app is installed on a
|
|
15
|
+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
|
16
|
+
-->
|
|
17
|
+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
|
18
|
+
<!--
|
|
19
|
+
Notice the use of %PUBLIC_URL% in the tags above.
|
|
20
|
+
It will be replaced with the URL of the `public` folder during the build.
|
|
21
|
+
Only files inside the `public` folder can be referenced from the HTML.
|
|
22
|
+
|
|
23
|
+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
|
24
|
+
work correctly both with client-side routing and a non-root public URL.
|
|
25
|
+
Learn how to configure a non-root public URL by running `npm run build`.
|
|
26
|
+
-->
|
|
27
|
+
<title>React App</title>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<noscript>You need to enable JavaScript to run this app.</noscript>
|
|
31
|
+
<div id="root"></div>
|
|
32
|
+
<!--
|
|
33
|
+
This HTML file is a template.
|
|
34
|
+
If you open it directly in the browser, you will see an empty page.
|
|
35
|
+
|
|
36
|
+
You can add webfonts, meta tags, or analytics to this file.
|
|
37
|
+
The build step will place the bundled scripts into the <body> tag.
|
|
38
|
+
|
|
39
|
+
To begin the development, run `npm start` or `yarn start`.
|
|
40
|
+
To create a production bundle, use `npm run build` or `yarn build`.
|
|
41
|
+
-->
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"short_name": "React App",
|
|
3
|
+
"name": "Create React App Sample",
|
|
4
|
+
"icons": [
|
|
5
|
+
{
|
|
6
|
+
"src": "favicon.ico",
|
|
7
|
+
"sizes": "64x64 32x32 24x24 16x16",
|
|
8
|
+
"type": "image/x-icon"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"src": "logo192.png",
|
|
12
|
+
"type": "image/png",
|
|
13
|
+
"sizes": "192x192"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"src": "logo512.png",
|
|
17
|
+
"type": "image/png",
|
|
18
|
+
"sizes": "512x512"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"start_url": ".",
|
|
22
|
+
"display": "standalone",
|
|
23
|
+
"theme_color": "#000000",
|
|
24
|
+
"background_color": "#ffffff"
|
|
25
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
.App {
|
|
2
|
+
text-align: center;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.App-logo {
|
|
6
|
+
height: 40vmin;
|
|
7
|
+
pointer-events: none;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
11
|
+
.App-logo {
|
|
12
|
+
animation: App-logo-spin infinite 20s linear;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.App-header {
|
|
17
|
+
background-color: #282c34;
|
|
18
|
+
min-height: 100vh;
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
align-items: center;
|
|
22
|
+
justify-content: center;
|
|
23
|
+
font-size: calc(10px + 2vmin);
|
|
24
|
+
color: white;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.App-link {
|
|
28
|
+
color: #61dafb;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@keyframes App-logo-spin {
|
|
32
|
+
from {
|
|
33
|
+
transform: rotate(0deg);
|
|
34
|
+
}
|
|
35
|
+
to {
|
|
36
|
+
transform: rotate(360deg);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import logo from './logo.svg';
|
|
2
|
+
import './App.css';
|
|
3
|
+
|
|
4
|
+
function App() {
|
|
5
|
+
return (
|
|
6
|
+
<div className="App">
|
|
7
|
+
<header className="App-header">
|
|
8
|
+
<img src={logo} className="App-logo" alt="logo" />
|
|
9
|
+
<p>
|
|
10
|
+
Edit <code>src/App.js</code> and save to reload.
|
|
11
|
+
</p>
|
|
12
|
+
<a
|
|
13
|
+
className="App-link"
|
|
14
|
+
href="https://reactjs.org"
|
|
15
|
+
target="_blank"
|
|
16
|
+
rel="noopener noreferrer"
|
|
17
|
+
>
|
|
18
|
+
Learn React
|
|
19
|
+
</a>
|
|
20
|
+
</header>
|
|
21
|
+
</div>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default App;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { RGBToHex, colorsArray } from "../Utils/continousLegend";
|
|
3
|
+
import { select, scaleLinear, scaleSequential, axisBottom } from "d3";
|
|
4
|
+
import { templateArray } from "../WelllayerTemplateTypes";
|
|
5
|
+
import { colorTablesArray } from "../ColorTableTypes";
|
|
6
|
+
|
|
7
|
+
interface legendProps {
|
|
8
|
+
min: number;
|
|
9
|
+
max: number;
|
|
10
|
+
dataObjectName: string;
|
|
11
|
+
position: number[];
|
|
12
|
+
name: string;
|
|
13
|
+
template: templateArray;
|
|
14
|
+
colorTables: colorTablesArray;
|
|
15
|
+
horizontal: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ItemColor {
|
|
19
|
+
color: string;
|
|
20
|
+
offset: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ContinuousLegend: React.FC<legendProps> = ({
|
|
24
|
+
min,
|
|
25
|
+
max,
|
|
26
|
+
dataObjectName,
|
|
27
|
+
position,
|
|
28
|
+
name,
|
|
29
|
+
template,
|
|
30
|
+
colorTables,
|
|
31
|
+
horizontal,
|
|
32
|
+
}: legendProps) => {
|
|
33
|
+
React.useEffect(() => {
|
|
34
|
+
continuousLegend("#legend");
|
|
35
|
+
}, [min, max, template, colorTables, horizontal]);
|
|
36
|
+
|
|
37
|
+
function continuousLegend(selected_id: string) {
|
|
38
|
+
const itemColor: ItemColor[] = [];
|
|
39
|
+
// Return the matched colors array from color.tables.json file
|
|
40
|
+
const colorTableColors = colorsArray(name, template, colorTables);
|
|
41
|
+
colorTableColors.forEach((value: [number, number, number, number]) => {
|
|
42
|
+
// return the color and offset needed to draw the legend
|
|
43
|
+
itemColor.push({
|
|
44
|
+
offset: RGBToHex(value).offset,
|
|
45
|
+
color: RGBToHex(value).color,
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
select(selected_id).select("svg").remove();
|
|
49
|
+
const colorScale = scaleSequential().domain([min, max]);
|
|
50
|
+
// append a defs (for definition) element to your SVG
|
|
51
|
+
const svgLegend = select(selected_id)
|
|
52
|
+
.append("svg")
|
|
53
|
+
.style("background-color", "#ffffffcc")
|
|
54
|
+
.style("border-radius", "5px");
|
|
55
|
+
if (!horizontal) {
|
|
56
|
+
svgLegend
|
|
57
|
+
.style("transform", "rotate(270deg)")
|
|
58
|
+
.style("margin-top", "80px");
|
|
59
|
+
}
|
|
60
|
+
const defs = svgLegend.append("defs");
|
|
61
|
+
// append a linearGradient element to the defs and give it a unique id
|
|
62
|
+
const linearGradient = defs
|
|
63
|
+
.append("linearGradient")
|
|
64
|
+
.attr("id", "linear-gradient")
|
|
65
|
+
.attr("x1", "0%")
|
|
66
|
+
.attr("x2", "100%") //since it's a horizontal linear gradient
|
|
67
|
+
.attr("y1", "0%")
|
|
68
|
+
.attr("y2", "0%");
|
|
69
|
+
// append multiple color stops by using D3's data/enter step
|
|
70
|
+
linearGradient
|
|
71
|
+
.selectAll("stop")
|
|
72
|
+
.data(itemColor)
|
|
73
|
+
.enter()
|
|
74
|
+
.append("stop")
|
|
75
|
+
.attr("offset", function (data) {
|
|
76
|
+
return data.offset + "%";
|
|
77
|
+
})
|
|
78
|
+
.attr("stop-color", function (data) {
|
|
79
|
+
return data.color;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// append title
|
|
83
|
+
svgLegend
|
|
84
|
+
.append("text")
|
|
85
|
+
.attr("class", "legendTitle")
|
|
86
|
+
.attr("x", 25)
|
|
87
|
+
.attr("y", 20)
|
|
88
|
+
.style("text-anchor", "left")
|
|
89
|
+
.text(dataObjectName);
|
|
90
|
+
|
|
91
|
+
// draw the rectangle and fill with gradient
|
|
92
|
+
svgLegend
|
|
93
|
+
.append("rect")
|
|
94
|
+
.attr("x", 25)
|
|
95
|
+
.attr("y", 30)
|
|
96
|
+
.attr("width", 250)
|
|
97
|
+
.attr("height", 25)
|
|
98
|
+
.style("fill", "url(#linear-gradient)");
|
|
99
|
+
|
|
100
|
+
//create tick marks
|
|
101
|
+
const xLeg = scaleLinear().domain([min, max]).range([10, 258]);
|
|
102
|
+
|
|
103
|
+
const axisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
|
|
104
|
+
|
|
105
|
+
svgLegend
|
|
106
|
+
.attr("class", "axis")
|
|
107
|
+
.append("g")
|
|
108
|
+
.attr("transform", "translate(15, 55)")
|
|
109
|
+
.style("font-size", "10px")
|
|
110
|
+
.style("font-weight", "700")
|
|
111
|
+
.call(axisLeg);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<div
|
|
116
|
+
style={{
|
|
117
|
+
position: "absolute",
|
|
118
|
+
right: position[0],
|
|
119
|
+
top: position[1],
|
|
120
|
+
}}
|
|
121
|
+
>
|
|
122
|
+
<div id="legend"></div>
|
|
123
|
+
</div>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
ContinuousLegend.defaultProps = {
|
|
128
|
+
position: [5, 10],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export default ContinuousLegend;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import legendUtil from "../Utils/discreteLegend";
|
|
3
|
+
import { scaleOrdinal, select } from "d3";
|
|
4
|
+
import { templateArray, propertiesObj } from "../WelllayerTemplateTypes";
|
|
5
|
+
import { colorTablesArray, colorTablesObj } from "../ColorTableTypes";
|
|
6
|
+
|
|
7
|
+
interface ItemColor {
|
|
8
|
+
color: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface colorLegendProps {
|
|
12
|
+
discreteData: { objects: Record<string, [number[], number]> };
|
|
13
|
+
dataObjectName: string;
|
|
14
|
+
name: string;
|
|
15
|
+
position: number[];
|
|
16
|
+
template: templateArray;
|
|
17
|
+
colorTables: colorTablesArray;
|
|
18
|
+
horizontal: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const DiscreteColorLegend: React.FC<colorLegendProps> = ({
|
|
22
|
+
discreteData,
|
|
23
|
+
name,
|
|
24
|
+
dataObjectName,
|
|
25
|
+
position,
|
|
26
|
+
template,
|
|
27
|
+
colorTables,
|
|
28
|
+
horizontal,
|
|
29
|
+
}: colorLegendProps) => {
|
|
30
|
+
React.useEffect(() => {
|
|
31
|
+
discreteLegend("#legend");
|
|
32
|
+
}, [discreteData, template, colorTables, horizontal]);
|
|
33
|
+
function discreteLegend(legend: string) {
|
|
34
|
+
const itemName: string[] = [];
|
|
35
|
+
const itemColor: ItemColor[] = [];
|
|
36
|
+
const colorsArray: [number, number, number, number][] = colorTableData(
|
|
37
|
+
name,
|
|
38
|
+
template,
|
|
39
|
+
colorTables
|
|
40
|
+
);
|
|
41
|
+
Object.keys(discreteData).forEach((key) => {
|
|
42
|
+
// eslint-disable-next-line
|
|
43
|
+
let code = (discreteData as { [key: string]: any })[key][1]
|
|
44
|
+
// compare the first value in colorarray(colortable) and code from discreteData
|
|
45
|
+
const matchedColorsArrays = colorsArray.find((value: number[]) => {
|
|
46
|
+
return value[0] == code;
|
|
47
|
+
});
|
|
48
|
+
if (matchedColorsArrays)
|
|
49
|
+
itemColor.push({
|
|
50
|
+
color: RGBToHex(matchedColorsArrays),
|
|
51
|
+
});
|
|
52
|
+
itemName.push(key);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
function RGBToHex(rgb: number[]) {
|
|
56
|
+
let r = rgb[1].toString(16),
|
|
57
|
+
g = rgb[2].toString(16),
|
|
58
|
+
b = rgb[3].toString(16);
|
|
59
|
+
if (r.length == 1) r = "0" + r;
|
|
60
|
+
if (g.length == 1) g = "0" + g;
|
|
61
|
+
if (b.length == 1) b = "0" + b;
|
|
62
|
+
return "#" + r + g + b;
|
|
63
|
+
}
|
|
64
|
+
const ordinalValues = scaleOrdinal().domain(itemName);
|
|
65
|
+
const colorLegend = legendUtil(itemColor).inputScale(ordinalValues);
|
|
66
|
+
select(legend).select("svg").remove();
|
|
67
|
+
const legendLength = itemColor.length;
|
|
68
|
+
const calcLegendHeight = 22 * legendLength + 4 * legendLength;
|
|
69
|
+
const selectedLegend = select(legend);
|
|
70
|
+
if (!horizontal) selectedLegend.style("height", 150 + "px");
|
|
71
|
+
const svgLegend = selectedLegend
|
|
72
|
+
.append("svg")
|
|
73
|
+
.style("margin", "10px 10px")
|
|
74
|
+
.call(colorLegend);
|
|
75
|
+
if (colorLegend && horizontal) {
|
|
76
|
+
svgLegend
|
|
77
|
+
.attr("height", calcLegendHeight + "px")
|
|
78
|
+
.attr("width", 220 + "px");
|
|
79
|
+
} else {
|
|
80
|
+
svgLegend
|
|
81
|
+
.style("transform", "rotate(90deg)")
|
|
82
|
+
.attr("width", calcLegendHeight + "px")
|
|
83
|
+
.attr("height", calcLegendHeight + "px");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return (
|
|
87
|
+
<div
|
|
88
|
+
style={{
|
|
89
|
+
position: "absolute",
|
|
90
|
+
right: position[0],
|
|
91
|
+
top: position[1],
|
|
92
|
+
backgroundColor: "#ffffffcc",
|
|
93
|
+
borderRadius: "5px",
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<label style={{ color: "#6F6F6F", margin: "10px 10px" }}>
|
|
97
|
+
{dataObjectName}
|
|
98
|
+
</label>
|
|
99
|
+
<div id="legend"></div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// Based on name return the colors array from color.tables.json file
|
|
105
|
+
export function colorTableData(
|
|
106
|
+
name: string,
|
|
107
|
+
template: templateArray,
|
|
108
|
+
colorTables: colorTablesArray
|
|
109
|
+
): [number, number, number, number][] {
|
|
110
|
+
const properties = template[0]["properties"];
|
|
111
|
+
const propertiesData = properties.filter(
|
|
112
|
+
(value: propertiesObj) => value.objectName == name
|
|
113
|
+
);
|
|
114
|
+
const colorTableData = colorTables.filter(
|
|
115
|
+
(value: colorTablesObj) =>
|
|
116
|
+
value.name.toLowerCase() ==
|
|
117
|
+
propertiesData[0].colorTable.toLowerCase()
|
|
118
|
+
);
|
|
119
|
+
return colorTableData[0].colors;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
DiscreteColorLegend.defaultProps = {
|
|
123
|
+
position: [5, 10],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export default DiscreteColorLegend;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { color } from "d3-color";
|
|
2
|
+
import { interpolateRgb } from "d3-interpolate";
|
|
3
|
+
import {
|
|
4
|
+
colorTablesArray,
|
|
5
|
+
colorTablesObj,
|
|
6
|
+
} from "../ColorTableTypes";
|
|
7
|
+
import {
|
|
8
|
+
templateArray,
|
|
9
|
+
propertiesObj,
|
|
10
|
+
} from "../WelllayerTemplateTypes";
|
|
11
|
+
|
|
12
|
+
// Based on objectName return the colors array from color.tables.json file
|
|
13
|
+
export function colorsArray(
|
|
14
|
+
objectName: string,
|
|
15
|
+
template: templateArray,
|
|
16
|
+
colorTables: colorTablesArray
|
|
17
|
+
): [number, number, number, number][] {
|
|
18
|
+
const properties = template[0]["properties"];
|
|
19
|
+
const propertiesData = properties.filter(
|
|
20
|
+
(value: propertiesObj) => value.objectName == objectName
|
|
21
|
+
);
|
|
22
|
+
const colorTableData = colorTables.filter(
|
|
23
|
+
(value: colorTablesObj) =>
|
|
24
|
+
value.name.toLowerCase() ==
|
|
25
|
+
propertiesData[0].colorTable.toLowerCase()
|
|
26
|
+
);
|
|
27
|
+
return colorTableData[0].colors;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// return the colors based on the point
|
|
31
|
+
export function rgbValues(
|
|
32
|
+
objectName: string,
|
|
33
|
+
point: number,
|
|
34
|
+
template: templateArray,
|
|
35
|
+
colorTables: colorTablesArray
|
|
36
|
+
): number[] | { r: number; g: number; b: number; opacity: number } | undefined {
|
|
37
|
+
const colorTableColors = colorsArray(objectName, template, colorTables);
|
|
38
|
+
// compare the point and first value from colorTableColors
|
|
39
|
+
const colorArrays = colorTableColors.find(
|
|
40
|
+
(value: [number, number, number, number]) => {
|
|
41
|
+
return point == value[0];
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// if point and value in color table matches then return particular colors
|
|
46
|
+
if (colorArrays) {
|
|
47
|
+
return colorArrays.slice(1);
|
|
48
|
+
}
|
|
49
|
+
// if no match then need to do interpolation
|
|
50
|
+
else {
|
|
51
|
+
// Get index of first match of colortable point greater than point
|
|
52
|
+
const index = colorTableColors.findIndex((value: number[]) => {
|
|
53
|
+
return value[0] > point;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const firstColorArray = colorTableColors[index - 1];
|
|
57
|
+
const secondColorArray = colorTableColors[index];
|
|
58
|
+
|
|
59
|
+
if ((firstColorArray || secondColorArray) != undefined) {
|
|
60
|
+
const interpolatedValues = interpolateRgb(
|
|
61
|
+
RGBToHex(firstColorArray).color,
|
|
62
|
+
RGBToHex(secondColorArray).color
|
|
63
|
+
)(point);
|
|
64
|
+
return color(interpolatedValues)?.rgb();
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// return the hex color code and offset
|
|
71
|
+
export function RGBToHex(rgb: number[]): { color: string; offset: number } {
|
|
72
|
+
let r = Math.round(rgb[1]).toString(16),
|
|
73
|
+
g = Math.round(rgb[2]).toString(16),
|
|
74
|
+
b = Math.round(rgb[3]).toString(16);
|
|
75
|
+
if (r.length == 1) r = "0" + r;
|
|
76
|
+
if (g.length == 1) g = "0" + g;
|
|
77
|
+
if (b.length == 1) b = "0" + b;
|
|
78
|
+
const offset = rgb[0] * 100.0;
|
|
79
|
+
|
|
80
|
+
return { color: "#" + r + g + b, offset: offset };
|
|
81
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
interface ItemColor {
|
|
2
|
+
color: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
export default function legendUtil(itemColor: ItemColor[]): any {
|
|
7
|
+
let legendValues: ItemColor[] = [];
|
|
8
|
+
const cellWidth = 22;
|
|
9
|
+
const cellHeight = 22;
|
|
10
|
+
const cellPadding = 4;
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line
|
|
13
|
+
function legend(g: any) {
|
|
14
|
+
function drawLegend() {
|
|
15
|
+
itemColor.forEach((item, index) => {
|
|
16
|
+
legendValues[index].color = item.color;
|
|
17
|
+
});
|
|
18
|
+
// Code to fill the color
|
|
19
|
+
g.selectAll("g.legendCells")
|
|
20
|
+
.append("rect")
|
|
21
|
+
.attr("height", cellHeight)
|
|
22
|
+
.attr("width", cellWidth)
|
|
23
|
+
.style("stroke", "black")
|
|
24
|
+
.style("stroke-width", "1px")
|
|
25
|
+
.style("fill", function (d: Record<string, unknown>) {
|
|
26
|
+
return d["color"];
|
|
27
|
+
});
|
|
28
|
+
// Display the label
|
|
29
|
+
g.selectAll("g.legendCells")
|
|
30
|
+
.append("text")
|
|
31
|
+
.attr("class", "breakLabels")
|
|
32
|
+
.style("fill", "#6F6F6F")
|
|
33
|
+
.attr("x", cellWidth + cellPadding)
|
|
34
|
+
.attr("y", 5 + cellHeight / 2)
|
|
35
|
+
.text(function (d: Record<string, unknown>) {
|
|
36
|
+
return d["label"];
|
|
37
|
+
});
|
|
38
|
+
// Alighment of cell in straight line
|
|
39
|
+
g.selectAll("g.legendCells").attr(
|
|
40
|
+
"transform",
|
|
41
|
+
function (_d: Record<string, unknown>, i: number) {
|
|
42
|
+
return (
|
|
43
|
+
"translate(0," + i * (cellHeight + cellPadding) + ")"
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
// display the discrete legend
|
|
49
|
+
g.selectAll("g.legendCells")
|
|
50
|
+
.data(legendValues)
|
|
51
|
+
.enter()
|
|
52
|
+
.append("g")
|
|
53
|
+
.attr("class", "legendCells");
|
|
54
|
+
drawLegend();
|
|
55
|
+
}
|
|
56
|
+
// eslint-disable-next-line
|
|
57
|
+
legend.inputScale = function (newScale: any) {
|
|
58
|
+
// eslint-disable-next-line
|
|
59
|
+
let scale: any = {};
|
|
60
|
+
scale = newScale;
|
|
61
|
+
legendValues = [];
|
|
62
|
+
scale.domain().forEach(function (el: string) {
|
|
63
|
+
const cellObject = { color: scale(el), label: el };
|
|
64
|
+
legendValues.push(cellObject);
|
|
65
|
+
});
|
|
66
|
+
return this;
|
|
67
|
+
};
|
|
68
|
+
return legend;
|
|
69
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface propertiesObj {
|
|
2
|
+
objectName: string;
|
|
3
|
+
colorTable: string;
|
|
4
|
+
context: string;
|
|
5
|
+
colorInterpolation: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type propertiesArr = Array<propertiesObj>;
|
|
9
|
+
|
|
10
|
+
interface template {
|
|
11
|
+
name: string;
|
|
12
|
+
properties: propertiesArr;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type templateArray = Array<template>;
|