@emerson-eps/color-tables 0.1.20 → 0.2.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.
Files changed (60) hide show
  1. package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +7 -0
  2. package/dist/component/ColorSelector/ColorSelectorComponent.js +36 -0
  3. package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -0
  4. package/dist/component/ColorSelector/ColorTableSelectorWrapper.d.ts +2 -0
  5. package/dist/component/ColorSelector/ColorTableSelectorWrapper.js +27 -0
  6. package/dist/component/ColorSelector/ColorTableSelectorWrapper.js.map +1 -0
  7. package/dist/component/ColorTableTypes.d.ts +1 -1
  8. package/dist/component/Legend/ContinuousLegend.d.ts +2 -2
  9. package/dist/component/Legend/ContinuousLegend.js +14 -7
  10. package/dist/component/Legend/ContinuousLegend.js.map +1 -1
  11. package/dist/component/Legend/DiscreteLegend.d.ts +2 -2
  12. package/dist/component/Legend/DiscreteLegend.js +16 -10
  13. package/dist/component/Legend/DiscreteLegend.js.map +1 -1
  14. package/dist/component/Legend/legendContinous.d.ts +11 -0
  15. package/dist/component/Legend/legendContinous.js +132 -0
  16. package/dist/component/Legend/legendContinous.js.map +1 -0
  17. package/dist/component/Utils/d3ColorScale.d.ts +7 -0
  18. package/dist/component/Utils/d3ColorScale.js +38 -0
  19. package/dist/component/Utils/d3ColorScale.js.map +1 -0
  20. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.d.ts +7 -0
  21. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js +11 -0
  22. package/dist/stories/ColorLegends/ColorSelector/Selector.stories.js.map +1 -0
  23. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.d.ts +7 -0
  24. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js +27 -0
  25. package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +1 -0
  26. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.d.ts +7 -0
  27. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js +27 -0
  28. package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +1 -0
  29. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.d.ts +7 -0
  30. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js +27 -0
  31. package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +1 -0
  32. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.d.ts +7 -0
  33. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js +27 -0
  34. package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +1 -0
  35. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.d.ts +7 -0
  36. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js +27 -0
  37. package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +1 -0
  38. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.d.ts +7 -0
  39. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js +27 -0
  40. package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +1 -0
  41. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.d.ts +7 -0
  42. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js +27 -0
  43. package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +1 -0
  44. package/package.json +13 -11
  45. package/src/component/ColorSelector/ColorSelectorComponent.tsx +68 -0
  46. package/src/component/ColorSelector/ColorTableSelectorWrapper.tsx +51 -0
  47. package/src/component/ColorTableTypes.ts +1 -1
  48. package/src/component/Legend/ContinuousLegend.tsx +15 -9
  49. package/src/component/Legend/DiscreteLegend.tsx +18 -12
  50. package/src/component/Legend/legendContinous.tsx +175 -0
  51. package/src/component/Utils/d3ColorScale.ts +39 -0
  52. package/src/stories/ColorLegends/ColorSelector/Selector.stories.jsx +12 -0
  53. package/src/stories/ColorLegends/ContinousLegends/MD.stories.jsx +29 -0
  54. package/src/stories/ColorLegends/ContinousLegends/NTG.stories.jsx +29 -0
  55. package/src/stories/ColorLegends/ContinousLegends/PermTot.stories.jsx +29 -0
  56. package/src/stories/ColorLegends/ContinousLegends/Permeability.stories.jsx +29 -0
  57. package/src/stories/ColorLegends/ContinousLegends/PoroTot.stories.jsx +29 -0
  58. package/src/stories/ColorLegends/ContinousLegends/Porosity.stories.jsx +29 -0
  59. package/src/stories/ColorLegends/ContinousLegends/SW.stories.jsx +29 -0
  60. package/tsconfig.json +0 -2
@@ -0,0 +1,175 @@
1
+ import * as React from "react";
2
+ import { useRef } from "react";
3
+ import { RGBToHex } from "../Utils/continousLegend";
4
+ import {colorScalesCont} from "../Utils/d3ColorScale"
5
+ import * as d3 from "d3";
6
+
7
+ interface legendProps {
8
+ position?: number[] | null;
9
+ colorArray: any;
10
+ legendColor: any;
11
+ legendColorName: string;
12
+ useContColorTable: boolean;
13
+ valueIndex: any;
14
+ }
15
+
16
+ interface ItemColor {
17
+ color: string;
18
+ offset: number;
19
+ }
20
+
21
+ export const LegendContinous: React.FC<legendProps> = ({
22
+ position,
23
+ colorArray,
24
+ legendColor,
25
+ legendColorName,
26
+ useContColorTable,
27
+ valueIndex,
28
+ }: legendProps) => {
29
+ const divRef = useRef<HTMLDivElement>(null);
30
+ React.useEffect(() => {
31
+ // colortable colors
32
+ if (useContColorTable == true && divRef.current) {
33
+ colortableLegend()
34
+ }
35
+ // d3 colors
36
+ else if (useContColorTable == false && divRef.current) {
37
+ d3colorLegend(colorScalesCont)
38
+ }
39
+ return function cleanup() {
40
+ d3.select(divRef.current).select("svg").remove();
41
+ };
42
+ }, [useContColorTable]);
43
+
44
+ function colortableLegend() {
45
+ const itemColor: ItemColor[] = [];
46
+ colorArray.color.forEach((value: [number, number, number, number]) => {
47
+ // return the color and offset needed to draw the legend
48
+ itemColor.push({
49
+ offset: RGBToHex(value).offset,
50
+ color: RGBToHex(value).color,
51
+ });
52
+ });
53
+
54
+ // append a defs (for definition) element to your SVG
55
+ const svgLegend = d3.select(divRef.current)
56
+ .append("svg")
57
+ .style("height", "50px")
58
+ .style("display", "flex")
59
+
60
+ const defs = svgLegend.append("defs");
61
+ let currentIndex = "linear-gradient-" + valueIndex;
62
+ // append a linearGradient element to the defs and give it a unique id
63
+ const linearGradient = defs
64
+ .append("linearGradient")
65
+ .attr("id", currentIndex)
66
+ .attr("x1", "0%")
67
+ .attr("x2", "100%") //since it's a horizontal linear gradient
68
+ .attr("y1", "0%")
69
+ .attr("y2", "0%");
70
+ // append multiple color stops by using D3's data/enter step
71
+
72
+ linearGradient
73
+ .selectAll("stop")
74
+ .data(itemColor)
75
+ .enter()
76
+ .append("stop")
77
+ .attr("offset", function (data) {
78
+ return data.offset + "%";
79
+ })
80
+ .attr("stop-color", function (data) {
81
+ return data.color;
82
+ });
83
+
84
+ // append title
85
+ svgLegend
86
+ .append("text")
87
+ .attr("class", "legendTitle")
88
+ .attr("x", 0)
89
+ .attr("y", 43)
90
+ .style("text-anchor", "left")
91
+ .text(colorArray.name);
92
+
93
+ // draw the rectangle and fill with gradient
94
+ svgLegend
95
+ .append("rect")
96
+ .attr("x", 180)
97
+ .attr("y", 30)
98
+ .attr("width", 150)
99
+ .attr("height", 25)
100
+ .style("fill", "url(#"+currentIndex+")");
101
+ }
102
+
103
+ // continuous legend using d3 color scale (linear gradiend code)
104
+ function d3colorLegend(colorscale: any) {
105
+
106
+ const itemColor: any = [];
107
+
108
+ colorscale.forEach((value: any) => {
109
+ // return the color and offset needed to draw the legend
110
+ itemColor.push(value.colors);
111
+ });
112
+
113
+ // create an array of steps based on the color scale
114
+ // returns an array of evenly-spaced numbers. Returns the integers from zero to the specified end minus one.
115
+ // d3.range(start, stop, step)
116
+ var data = d3.range(10).map(d=> ({color:legendColor(d/10), value:d}))
117
+ // get the array's min and max value
118
+ var extent: any = d3.extent(data, d => d.value);
119
+
120
+ // append a defs (for definition) element to your SVG
121
+ const svgLegend = d3.select(divRef.current)
122
+ .append("svg")
123
+ .style("height", "50px")
124
+ .style("display", "flex")
125
+
126
+ const defs = svgLegend.append("defs");
127
+ let currentIndex = "linear-gradient-" + valueIndex;
128
+ // append a linearGradient element to the defs and give it a unique id
129
+ const linearGradient = defs
130
+ .append("linearGradient")
131
+ .attr("id", currentIndex)
132
+ .attr("x1", "0%")
133
+ .attr("x2", "100%") //since it's a horizontal linear gradient
134
+ .attr("y1", "0%")
135
+ .attr("y2", "0%");
136
+
137
+ // append multiple color stops by using D3's data/enter step
138
+ linearGradient.selectAll("stop")
139
+ .data(data)
140
+ .enter().append("stop")
141
+ .attr("offset", d => ((d.value - extent[0]) / (extent[1] - extent[0]) * 100) + "%")
142
+ .attr("stop-color", d => d.color);
143
+
144
+ // append title
145
+ svgLegend
146
+ .append("text")
147
+ .attr("class", "legendTitle")
148
+ .attr("x", 0)
149
+ .attr("y", 43)
150
+ .style("text-anchor", "left")
151
+ .text(legendColorName);
152
+
153
+ // draw the rectangle and fill with gradient
154
+ svgLegend
155
+ .append("rect")
156
+ .attr("x", 180)
157
+ .attr("y", 30)
158
+ .attr("width", 150)
159
+ .attr("height", 25)
160
+ .style("fill", "url(#"+currentIndex+")");
161
+ }
162
+
163
+ return (
164
+ <div
165
+ style={{
166
+ right: position ? position[0] : ' ',
167
+ top: position ? position[1] : ' ',
168
+ }}
169
+ >
170
+ {useContColorTable ? <div className="colortableLegend" ref={divRef}></div>
171
+ :
172
+ <div className="d3colorLegend" ref={divRef}></div>}
173
+ </div>
174
+ );
175
+ };
@@ -0,0 +1,39 @@
1
+ import * as d3 from "d3";
2
+
3
+ export const colorScalesCont = [
4
+ {
5
+ "name": "Spectral",
6
+ "discrete": false,
7
+ "colors": d3.interpolateSpectral
8
+ },
9
+ {
10
+ "name": "RdYlBu",
11
+ "discrete": false,
12
+ "colors": d3.interpolateRdYlBu
13
+ },
14
+ {
15
+ "name": "Warm",
16
+ "discrete": false,
17
+ "colors": d3.interpolateWarm
18
+ },
19
+ {
20
+ "name": "Cool",
21
+ "discrete": false,
22
+ "colors": d3.interpolateCool
23
+ },
24
+ {
25
+ "name": "Viridis",
26
+ "discrete": false,
27
+ "colors": d3.interpolateViridis
28
+ },
29
+ {
30
+ "name": "Inferno",
31
+ "discrete": false,
32
+ "colors": d3.interpolateInferno
33
+ },
34
+ ]
35
+
36
+
37
+ export function interpolatorContinuous(): d3.ScaleSequential<string, never> {
38
+ return d3.scaleSequential(d3.interpolateInferno);
39
+ };
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+ import { ColorSelectorWrapper } from "../../../component/ColorSelector/ColorTableSelectorWrapper";
3
+ export default {
4
+ component: ColorSelectorWrapper,
5
+ title: "Legends/ColorSelector",
6
+ };
7
+
8
+ const Template = (args) => {
9
+ return <ColorSelectorWrapper />;
10
+ };
11
+
12
+ export const selectorTemplate = Template.bind({});
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import {ContinuousLegend} from "../../../component/Legend/ContinuousLegend";
3
+ export default {
4
+ component: ContinuousLegend,
5
+ title: "Legends/ContinousLegend",
6
+ };
7
+ import colorTables from "../../../component/color-tables.json";
8
+
9
+ const min = 2918;
10
+ const max = 4770;
11
+ const dataObjectName = "Wells / MD";
12
+ const position = [16, 10];
13
+ const horizontal = true;
14
+ const colorName = "Time/Depth";
15
+
16
+ const Template = (args) => {
17
+ return <ContinuousLegend {...args} />;
18
+ };
19
+
20
+ export const MDTemplate = Template.bind({});
21
+ MDTemplate.args = {
22
+ min,
23
+ max,
24
+ dataObjectName,
25
+ position,
26
+ colorName,
27
+ colorTables,
28
+ horizontal,
29
+ };
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import {ContinuousLegend} from "../../../component/Legend/ContinuousLegend";
3
+ export default {
4
+ component: ContinuousLegend,
5
+ title: "Legends/ContinousLegend",
6
+ };
7
+ import colorTables from "../../../component/color-tables.json";
8
+
9
+ const min = 0;
10
+ const max = 1;
11
+ const dataObjectName = "Wells / NTG";
12
+ const position = [16, 10];
13
+ const horizontal = true;
14
+ const colorName = "Rainbow";
15
+
16
+ const Template = (args) => {
17
+ return <ContinuousLegend {...args} />;
18
+ };
19
+
20
+ export const NTGTemplate = Template.bind({});
21
+ NTGTemplate.args = {
22
+ min,
23
+ max,
24
+ dataObjectName,
25
+ position,
26
+ colorName,
27
+ colorTables,
28
+ horizontal,
29
+ };
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import {ContinuousLegend} from "../../../component/Legend/ContinuousLegend";
3
+ export default {
4
+ component: ContinuousLegend,
5
+ title: "Legends/ContinousLegend",
6
+ };
7
+ import colorTables from "../../../component/color-tables.json";
8
+
9
+ const min = -999;
10
+ const max = 14023;
11
+ const dataObjectName = "Wells / PERMTOT";
12
+ const position = [16, 10];
13
+ const horizontal = true;
14
+ const colorName = "Porosity";
15
+
16
+ const Template = (args) => {
17
+ return <ContinuousLegend {...args} />;
18
+ };
19
+
20
+ export const PermTotTemplate = Template.bind({});
21
+ PermTotTemplate.args = {
22
+ min,
23
+ max,
24
+ dataObjectName,
25
+ position,
26
+ colorName,
27
+ colorTables,
28
+ horizontal,
29
+ };
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import {ContinuousLegend} from "../../../component/Legend/ContinuousLegend";
3
+ export default {
4
+ component: ContinuousLegend,
5
+ title: "Legends/ContinousLegend",
6
+ };
7
+ import colorTables from "../../../component/color-tables.json";
8
+
9
+ const min = -999;
10
+ const max = 14023;
11
+ const dataObjectName = "Wells / PERM";
12
+ const position = [16, 10];
13
+ const horizontal = true;
14
+ const colorName = "Permeability";
15
+
16
+ const Template = (args) => {
17
+ return <ContinuousLegend {...args} />;
18
+ };
19
+
20
+ export const PermeabilityTemplate = Template.bind({});
21
+ PermeabilityTemplate.args = {
22
+ min,
23
+ max,
24
+ dataObjectName,
25
+ position,
26
+ colorName,
27
+ colorTables,
28
+ horizontal,
29
+ };
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import {ContinuousLegend} from "../../../component/Legend/ContinuousLegend";
3
+ export default {
4
+ component: ContinuousLegend,
5
+ title: "Legends/ContinousLegend",
6
+ };
7
+ import colorTables from "../../../component/color-tables.json";
8
+
9
+ const min = 0;
10
+ const max = 0.35;
11
+ const dataObjectName = "Wells / POROTOT";
12
+ const position = [16, 10];
13
+ const horizontal = true;
14
+ const colorName = "Porosity";
15
+
16
+ const Template = (args) => {
17
+ return <ContinuousLegend {...args} />;
18
+ };
19
+
20
+ export const PoroTotTemplate = Template.bind({});
21
+ PoroTotTemplate.args = {
22
+ min,
23
+ max,
24
+ dataObjectName,
25
+ position,
26
+ colorName,
27
+ colorTables,
28
+ horizontal,
29
+ };
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import {ContinuousLegend} from "../../../component/Legend/ContinuousLegend";
3
+ export default {
4
+ component: ContinuousLegend,
5
+ title: "Legends/ContinousLegend",
6
+ };
7
+ import colorTables from "../../../component/color-tables.json";
8
+
9
+ const min = 0;
10
+ const max = 0.35;
11
+ const dataObjectName = "Wells / PORO";
12
+ const position = [16, 10];
13
+ const horizontal = true;
14
+ const colorName = "Porosity";
15
+
16
+ const Template = (args) => {
17
+ return <ContinuousLegend {...args} />;
18
+ };
19
+
20
+ export const PorosityTemplate = Template.bind({});
21
+ PorosityTemplate.args = {
22
+ min,
23
+ max,
24
+ dataObjectName,
25
+ position,
26
+ colorName,
27
+ colorTables,
28
+ horizontal,
29
+ };
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import {ContinuousLegend} from "../../../component/Legend/ContinuousLegend";
3
+ export default {
4
+ component: ContinuousLegend,
5
+ title: "Legends/ContinousLegend",
6
+ };
7
+ import colorTables from "../../../component/color-tables.json";
8
+
9
+ const min = 0;
10
+ const max = 1;
11
+ const dataObjectName = "Wells / SW";
12
+ const position = [16, 10];
13
+ const horizontal = true;
14
+ const colorName = "Rainbow";
15
+
16
+ const Template = (args) => {
17
+ return <ContinuousLegend {...args} />;
18
+ };
19
+
20
+ export const SWTemplate = Template.bind({});
21
+ SWTemplate.args = {
22
+ min,
23
+ max,
24
+ dataObjectName,
25
+ position,
26
+ colorName,
27
+ colorTables,
28
+ horizontal,
29
+ };
package/tsconfig.json CHANGED
@@ -17,8 +17,6 @@
17
17
  "noUnusedLocals": true,
18
18
  "noUnusedParameters": true,
19
19
  "resolveJsonModule": true,
20
- //"esModuleInterop": true,
21
- //"allowSyntheticDefaultImports": true
22
20
  },
23
21
  "include": ["src"],
24
22
  "exclude": ["node_modules"]