@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 @@
1
+ {"version":3,"file":"PermTot.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/ContinousLegends/PermTot.stories.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,eAAe;IACX,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,yBAAyB;CACnC,CAAC;AACF,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAE/D,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC;AACjB,MAAM,GAAG,GAAG,KAAK,CAAC;AAClB,MAAM,cAAc,GAAG,iBAAiB,CAAC;AACzC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE;IACtB,OAAO,oBAAC,gBAAgB,oBAAK,IAAI,EAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACjD,eAAe,CAAC,IAAI,GAAG;IACnB,GAAG;IACH,GAAG;IACH,cAAc;IACd,QAAQ;IACR,SAAS;IACT,WAAW;IACX,UAAU;CACb,CAAC"}
@@ -0,0 +1,7 @@
1
+ declare namespace _default {
2
+ export { ContinuousLegend as component };
3
+ export const title: string;
4
+ }
5
+ export default _default;
6
+ export const PermeabilityTemplate: any;
7
+ import { ContinuousLegend } from "../../../component/Legend/ContinuousLegend";
@@ -0,0 +1,27 @@
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
+ const min = -999;
9
+ const max = 14023;
10
+ const dataObjectName = "Wells / PERM";
11
+ const position = [16, 10];
12
+ const horizontal = true;
13
+ const colorName = "Permeability";
14
+ const Template = (args) => {
15
+ return React.createElement(ContinuousLegend, Object.assign({}, args));
16
+ };
17
+ export const PermeabilityTemplate = Template.bind({});
18
+ PermeabilityTemplate.args = {
19
+ min,
20
+ max,
21
+ dataObjectName,
22
+ position,
23
+ colorName,
24
+ colorTables,
25
+ horizontal,
26
+ };
27
+ //# sourceMappingURL=Permeability.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Permeability.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/ContinousLegends/Permeability.stories.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,eAAe;IACX,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,yBAAyB;CACnC,CAAC;AACF,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAE/D,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC;AACjB,MAAM,GAAG,GAAG,KAAK,CAAC;AAClB,MAAM,cAAc,GAAG,cAAc,CAAC;AACtC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,cAAc,CAAC;AAEjC,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE;IACtB,OAAO,oBAAC,gBAAgB,oBAAK,IAAI,EAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACtD,oBAAoB,CAAC,IAAI,GAAG;IACxB,GAAG;IACH,GAAG;IACH,cAAc;IACd,QAAQ;IACR,SAAS;IACT,WAAW;IACX,UAAU;CACb,CAAC"}
@@ -0,0 +1,7 @@
1
+ declare namespace _default {
2
+ export { ContinuousLegend as component };
3
+ export const title: string;
4
+ }
5
+ export default _default;
6
+ export const PoroTotTemplate: any;
7
+ import { ContinuousLegend } from "../../../component/Legend/ContinuousLegend";
@@ -0,0 +1,27 @@
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
+ const min = 0;
9
+ const max = 0.35;
10
+ const dataObjectName = "Wells / POROTOT";
11
+ const position = [16, 10];
12
+ const horizontal = true;
13
+ const colorName = "Porosity";
14
+ const Template = (args) => {
15
+ return React.createElement(ContinuousLegend, Object.assign({}, args));
16
+ };
17
+ export const PoroTotTemplate = Template.bind({});
18
+ PoroTotTemplate.args = {
19
+ min,
20
+ max,
21
+ dataObjectName,
22
+ position,
23
+ colorName,
24
+ colorTables,
25
+ horizontal,
26
+ };
27
+ //# sourceMappingURL=PoroTot.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PoroTot.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/ContinousLegends/PoroTot.stories.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,eAAe;IACX,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,yBAAyB;CACnC,CAAC;AACF,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAE/D,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,IAAI,CAAC;AACjB,MAAM,cAAc,GAAG,iBAAiB,CAAC;AACzC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE;IACtB,OAAO,oBAAC,gBAAgB,oBAAK,IAAI,EAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACjD,eAAe,CAAC,IAAI,GAAG;IACnB,GAAG;IACH,GAAG;IACH,cAAc;IACd,QAAQ;IACR,SAAS;IACT,WAAW;IACX,UAAU;CACb,CAAC"}
@@ -0,0 +1,7 @@
1
+ declare namespace _default {
2
+ export { ContinuousLegend as component };
3
+ export const title: string;
4
+ }
5
+ export default _default;
6
+ export const PorosityTemplate: any;
7
+ import { ContinuousLegend } from "../../../component/Legend/ContinuousLegend";
@@ -0,0 +1,27 @@
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
+ const min = 0;
9
+ const max = 0.35;
10
+ const dataObjectName = "Wells / PORO";
11
+ const position = [16, 10];
12
+ const horizontal = true;
13
+ const colorName = "Porosity";
14
+ const Template = (args) => {
15
+ return React.createElement(ContinuousLegend, Object.assign({}, args));
16
+ };
17
+ export const PorosityTemplate = Template.bind({});
18
+ PorosityTemplate.args = {
19
+ min,
20
+ max,
21
+ dataObjectName,
22
+ position,
23
+ colorName,
24
+ colorTables,
25
+ horizontal,
26
+ };
27
+ //# sourceMappingURL=Porosity.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Porosity.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/ContinousLegends/Porosity.stories.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,eAAe;IACX,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,yBAAyB;CACnC,CAAC;AACF,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAE/D,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,IAAI,CAAC;AACjB,MAAM,cAAc,GAAG,cAAc,CAAC;AACtC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,UAAU,CAAC;AAE7B,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE;IACtB,OAAO,oBAAC,gBAAgB,oBAAK,IAAI,EAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAClD,gBAAgB,CAAC,IAAI,GAAG;IACpB,GAAG;IACH,GAAG;IACH,cAAc;IACd,QAAQ;IACR,SAAS;IACT,WAAW;IACX,UAAU;CACb,CAAC"}
@@ -0,0 +1,7 @@
1
+ declare namespace _default {
2
+ export { ContinuousLegend as component };
3
+ export const title: string;
4
+ }
5
+ export default _default;
6
+ export const SWTemplate: any;
7
+ import { ContinuousLegend } from "../../../component/Legend/ContinuousLegend";
@@ -0,0 +1,27 @@
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
+ const min = 0;
9
+ const max = 1;
10
+ const dataObjectName = "Wells / SW";
11
+ const position = [16, 10];
12
+ const horizontal = true;
13
+ const colorName = "Rainbow";
14
+ const Template = (args) => {
15
+ return React.createElement(ContinuousLegend, Object.assign({}, args));
16
+ };
17
+ export const SWTemplate = Template.bind({});
18
+ SWTemplate.args = {
19
+ min,
20
+ max,
21
+ dataObjectName,
22
+ position,
23
+ colorName,
24
+ colorTables,
25
+ horizontal,
26
+ };
27
+ //# sourceMappingURL=SW.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SW.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/ContinousLegends/SW.stories.jsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,gBAAgB,EAAC,MAAM,4CAA4C,CAAC;AAC5E,eAAe;IACX,SAAS,EAAE,gBAAgB;IAC3B,KAAK,EAAE,yBAAyB;CACnC,CAAC;AACF,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAE/D,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,GAAG,GAAG,CAAC,CAAC;AACd,MAAM,cAAc,GAAG,YAAY,CAAC;AACpC,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,SAAS,CAAC;AAE5B,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE;IACtB,OAAO,oBAAC,gBAAgB,oBAAK,IAAI,EAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5C,UAAU,CAAC,IAAI,GAAG;IACd,GAAG;IACH,GAAG;IACH,cAAc;IACd,QAAQ;IACR,SAAS;IACT,WAAW;IACX,UAAU;CACb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emerson-eps/color-tables",
3
- "version": "0.1.20",
3
+ "version": "0.2.0",
4
4
  "description": "Standard library of color tables for geological domain",
5
5
  "release": {
6
6
  "branches": [
@@ -16,12 +16,13 @@
16
16
  "semantic-release": "semantic-release"
17
17
  },
18
18
  "dependencies": {
19
+ "@equinor/eds-core-react": "^0.17.0",
19
20
  "d3": "^7.2.0",
20
21
  "d3-color": "^3.0.1",
21
22
  "d3-interpolate": "^3.0.1",
22
23
  "react": "^17.0.2",
23
24
  "react-dom": "^17.0.2",
24
- "react-scripts": "4.0.3",
25
+ "react-scripts": "^5.0.0",
25
26
  "web-vitals": "^1.1.2"
26
27
  },
27
28
  "repository": {
@@ -49,17 +50,18 @@
49
50
  },
50
51
  "devDependencies": {
51
52
  "@babel/core": "^7.16.0",
52
- "@storybook/addon-actions": "^6.4.9",
53
- "@storybook/addon-essentials": "^6.4.9",
54
- "@storybook/addon-links": "^6.4.9",
55
- "@storybook/react": "^6.4.9",
53
+ "@storybook/addon-actions": "^6.4.17",
54
+ "@storybook/addon-essentials": "^6.4.17",
55
+ "@storybook/addon-links": "^6.4.17",
56
+ "@storybook/react": "^6.4.17",
57
+ "@testing-library/jest-dom": "^5.16.1",
58
+ "@testing-library/react": "^12.1.2",
59
+ "@testing-library/user-event": "^13.5.0",
56
60
  "@types/d3": "^7.1.0",
61
+ "@types/styled-components": "^5.1.23",
57
62
  "babel-loader": "^8.1.0",
58
- "semantic-release": "^18.0.1",
63
+ "semantic-release": "^19.0.2",
59
64
  "ts-loader": "^9.2.6",
60
- "typescript": "^4.5.4",
61
- "@testing-library/jest-dom": "^5.16.1",
62
- "@testing-library/react": "^11.2.7",
63
- "@testing-library/user-event": "^12.8.3"
65
+ "typescript": "^4.5.4"
64
66
  }
65
67
  }
@@ -0,0 +1,68 @@
1
+ import * as React from "react";
2
+ import { LegendContinous } from "../Legend/legendContinous";
3
+ import * as colorTables from "../color-tables.json";
4
+ import {colorScalesCont} from "../Utils/d3ColorScale"
5
+
6
+ const position = [16, 206];
7
+ const continuosColorData: any = []
8
+ const continuosD3ColorData: any = []
9
+
10
+ interface legendProps {
11
+ useColorTableColors: boolean
12
+ useD3Colors: boolean
13
+ }
14
+
15
+ // code is for color table continuous data
16
+ var colorTableContinuousData = colorTables.filter((element: any) => {
17
+ return element.discrete == false;
18
+ });
19
+
20
+ colorTableContinuousData.forEach((element: any) => {
21
+ continuosColorData.push({color: element.colors, name: element.name})
22
+ });
23
+
24
+ // code is for d3 continuous data
25
+ var d3continuousData = colorScalesCont.filter((element: any) => {
26
+ return element.discrete == false;
27
+ });
28
+
29
+ d3continuousData.forEach((element: any) => {
30
+ continuosD3ColorData.push({color: element.colors, name: element.name})
31
+ });
32
+
33
+ export const ColorSelector: React.FC<legendProps> = ({
34
+ useColorTableColors,
35
+ useD3Colors,
36
+ }: legendProps) => {
37
+ let continuousLegend;
38
+ if (useColorTableColors) {
39
+ continuousLegend = continuosColorData.map((value: any, key: any) => {
40
+ return <LegendContinous
41
+ position={position + key}
42
+ colorArray={value}
43
+ legendColor={''}
44
+ legendColorName={''}
45
+ useContColorTable={true}
46
+ valueIndex={key}
47
+ />
48
+ });
49
+ }
50
+ if (useD3Colors) {
51
+ continuousLegend = continuosD3ColorData.map((val: any, key: any) => {
52
+ return <LegendContinous
53
+ position={position + key}
54
+ colorArray={{}}
55
+ legendColor={val.color}
56
+ legendColorName={val.name}
57
+ useContColorTable={false}
58
+ valueIndex={key + "0"}
59
+ />
60
+ });
61
+ }
62
+
63
+ return (
64
+ <div>
65
+ {continuousLegend}
66
+ </div>
67
+ );
68
+ };
@@ -0,0 +1,51 @@
1
+ import * as React from "react";
2
+ import { Accordion } from "@equinor/eds-core-react";
3
+ import {ColorSelector} from "./ColorSelectorComponent";
4
+
5
+ export const ColorSelectorWrapper = () => {
6
+ // export const ColorSelector: React.FC<legendProps> = ({
7
+ // }: legendProps) => {
8
+ return (
9
+ <div style={{width: "450px"}}>
10
+ <Accordion >
11
+ <Accordion.Item>
12
+ <Accordion.Header>
13
+ Color Scales
14
+ </Accordion.Header>
15
+ <Accordion.Panel>
16
+ <Accordion >
17
+ <Accordion.Item>
18
+ <Accordion.Header>
19
+ Geologic Color Scale
20
+ </Accordion.Header>
21
+ <Accordion.Panel>
22
+ <ColorSelector useColorTableColors={true} useD3Colors={false} key={1}/>
23
+ </Accordion.Panel>
24
+ </Accordion.Item>
25
+ </Accordion>
26
+ <Accordion >
27
+ <Accordion.Item>
28
+ <Accordion.Header>
29
+ D3 Color Scale
30
+ </Accordion.Header>
31
+ <Accordion.Panel>
32
+ <ColorSelector useColorTableColors={false} useD3Colors={true} key={1}/>
33
+ </Accordion.Panel>
34
+ </Accordion.Item>
35
+ </Accordion>
36
+ <Accordion >
37
+ <Accordion.Item>
38
+ <Accordion.Header>
39
+ Custom Color Scale
40
+ </Accordion.Header>
41
+ <Accordion.Panel>
42
+ Custom Content
43
+ </Accordion.Panel>
44
+ </Accordion.Item>
45
+ </Accordion>
46
+ </Accordion.Panel>
47
+ </Accordion.Item>
48
+ </Accordion>
49
+ </div>
50
+ );
51
+ };
@@ -1,6 +1,6 @@
1
1
  export declare type colorTablesObj = {
2
2
  name: string;
3
- description: string;
3
+ discrete: boolean;
4
4
  colors: [number, number, number, number][];
5
5
  }
6
6
  export type colorTablesArray = Array<colorTablesObj>;
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { useRef } from "react";
2
3
  import { RGBToHex, colorsArray } from "../Utils/continousLegend";
3
4
  import { select, scaleLinear, scaleSequential, axisBottom } from "d3";
4
5
  import { colorTablesArray } from "../ColorTableTypes";
@@ -7,10 +8,10 @@ declare type legendProps = {
7
8
  min: number;
8
9
  max: number;
9
10
  dataObjectName: string;
10
- position: number[];
11
+ position?: number[] | null;
11
12
  colorName: string;
12
13
  colorTables: colorTablesArray;
13
- horizontal: boolean;
14
+ horizontal?: boolean | null;
14
15
  }
15
16
 
16
17
  declare type ItemColor = {
@@ -27,11 +28,17 @@ export const ContinuousLegend: React.FC<legendProps> = ({
27
28
  colorTables,
28
29
  horizontal,
29
30
  }: legendProps) => {
31
+ const divRef = useRef<HTMLDivElement>(null);
30
32
  React.useEffect(() => {
31
- continuousLegend("#legend");
33
+ if (divRef.current) {
34
+ continuousLegend();
35
+ };
36
+ return function cleanup() {
37
+ select(divRef.current).select("svg").remove();
38
+ };
32
39
  }, [min, max, colorName, colorTables, horizontal]);
33
40
 
34
- function continuousLegend(selected_id: string) {
41
+ function continuousLegend() {
35
42
  const itemColor: ItemColor[] = [];
36
43
  // Return the matched colors array from color.tables.json file
37
44
  const colorTableColors = colorsArray(colorName, colorTables);
@@ -42,10 +49,9 @@ export const ContinuousLegend: React.FC<legendProps> = ({
42
49
  color: RGBToHex(value).color,
43
50
  });
44
51
  });
45
- select(selected_id).select("svg").remove();
46
52
  const colorScale = scaleSequential().domain([min, max]);
47
53
  // append a defs (for definition) element to your SVG
48
- const svgLegend = select(selected_id)
54
+ const svgLegend = select(divRef.current)
49
55
  .append("svg")
50
56
  .style("background-color", "#ffffffcc")
51
57
  .style("border-radius", "5px");
@@ -112,11 +118,11 @@ export const ContinuousLegend: React.FC<legendProps> = ({
112
118
  <div
113
119
  style={{
114
120
  position: "absolute",
115
- right: position[0],
116
- top: position[1],
121
+ right: position ? position[0] : ' ',
122
+ top: position ? position[1] : ' ',
117
123
  }}
118
124
  >
119
- <div id="legend"></div>
125
+ <div id="legend" ref={divRef}></div>
120
126
  </div>
121
127
  );
122
128
  };
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { useRef } from "react";
2
3
  import legendUtil from "../Utils/discreteLegend";
3
4
  import { scaleOrdinal, select } from "d3";
4
5
  import { colorTablesArray, colorTablesObj } from "../ColorTableTypes";
@@ -10,10 +11,10 @@ declare type ItemColor = {
10
11
  declare type colorLegendProps = {
11
12
  discreteData: { objects: Record<string, [number[], number]> };
12
13
  dataObjectName: string;
13
- position: number[];
14
+ position?: number[] | null;
14
15
  colorName: string;
15
16
  colorTables: colorTablesArray;
16
- horizontal: boolean;
17
+ horizontal?: boolean | null;
17
18
  }
18
19
 
19
20
  export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
@@ -24,10 +25,17 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
24
25
  colorTables,
25
26
  horizontal,
26
27
  }: colorLegendProps) => {
28
+ const divRef = useRef<HTMLDivElement>(null);
27
29
  React.useEffect(() => {
28
- discreteLegend("#legend");
30
+ if (divRef.current) {
31
+ discreteLegend();
32
+ }
33
+ return function cleanup() {
34
+ select(divRef.current).select("div").remove();
35
+ select(divRef.current).select("svg").remove();
36
+ };
29
37
  }, [discreteData, colorName, colorTables, horizontal]);
30
- function discreteLegend(legend: string) {
38
+ function discreteLegend() {
31
39
  const itemName: string[] = [];
32
40
  const itemColor: ItemColor[] = [];
33
41
  const colorsArray: [number, number, number, number][] = colorTableData(
@@ -59,23 +67,21 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
59
67
  }
60
68
  const ordinalValues = scaleOrdinal().domain(itemName);
61
69
  const colorLegend = legendUtil(itemColor).inputScale(ordinalValues);
62
- select(legend).select("div").remove();
63
- select(legend).select("svg").remove();
64
70
  const legendLength = itemColor.length;
65
71
  const calcLegendHeight = 22 * legendLength + 4 * legendLength;
66
- const selectedLegend = select(legend);
72
+ const selectedLegend = select(divRef.current);
67
73
  selectedLegend
68
74
  .append("div")
69
75
  .text(dataObjectName)
70
76
  .attr("y", 7)
71
77
  .style("color", "#6F6F6F")
72
78
  .style("margin", "10px 10px");
73
- if (!horizontal) selectedLegend.style("height", 150 + "px");
79
+ if (horizontal) selectedLegend.style("height", 150 + "px");
74
80
  const svgLegend = selectedLegend
75
81
  .append("svg")
76
82
  .style("margin", "10px 10px")
77
83
  .call(colorLegend);
78
- if (colorLegend && horizontal) {
84
+ if (colorLegend && !horizontal) {
79
85
  svgLegend
80
86
  .attr("height", calcLegendHeight + "px")
81
87
  .attr("width", 220 + "px");
@@ -90,13 +96,13 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
90
96
  <div
91
97
  style={{
92
98
  position: "absolute",
93
- right: position[0],
94
- top: position[1],
99
+ right: position ? position[0] : ' ',
100
+ top: position ? position[1] : ' ',
95
101
  backgroundColor: "#ffffffcc",
96
102
  borderRadius: "5px",
97
103
  }}
98
104
  >
99
- <div id="legend"></div>
105
+ <div id="legend" ref={divRef}></div>
100
106
  </div>
101
107
  );
102
108
  };