@emerson-eps/color-tables 0.2.10 → 0.2.13

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 (52) hide show
  1. package/dist/component/ColorSelector/ColorSelectorAccordion.js +2 -2
  2. package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -1
  3. package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +0 -3
  4. package/dist/component/ColorSelector/ColorSelectorComponent.js +5 -15
  5. package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
  6. package/dist/component/ColorSelector/ColorSelectorWrapper.d.ts +0 -1
  7. package/dist/component/ColorSelector/ColorSelectorWrapper.js +13 -12
  8. package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -1
  9. package/dist/component/Legend/ColorLegend.js +11 -3
  10. package/dist/component/Legend/ColorLegend.js.map +1 -1
  11. package/dist/component/Legend/ContinuousLegend.d.ts +1 -1
  12. package/dist/component/Legend/ContinuousLegend.js +18 -4
  13. package/dist/component/Legend/ContinuousLegend.js.map +1 -1
  14. package/dist/component/Legend/DiscreteLegend.d.ts +1 -2
  15. package/dist/component/Legend/DiscreteLegend.js +31 -34
  16. package/dist/component/Legend/DiscreteLegend.js.map +1 -1
  17. package/dist/component/{ColorTableTypes.d.ts → Utils/ColorTableTypes.d.ts} +0 -0
  18. package/dist/component/{ColorTableTypes.js → Utils/ColorTableTypes.js} +0 -0
  19. package/dist/component/Utils/ColorTableTypes.js.map +1 -0
  20. package/dist/component/Utils/continousLegend.d.ts +2 -2
  21. package/dist/component/Utils/continousLegend.js.map +1 -1
  22. package/dist/component/Utils/discreteLegend.js +9 -78
  23. package/dist/component/Utils/discreteLegend.js.map +1 -1
  24. package/dist/index.d.ts +3 -3
  25. package/dist/index.js +2 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/stories/ColorLegends/{SingleComponent/Single.stories.d.ts → LegendWithSelector/LegendSelector.stories.d.ts} +1 -1
  28. package/dist/stories/ColorLegends/{SingleComponent/Single.stories.js → LegendWithSelector/LegendSelector.stories.js} +5 -5
  29. package/dist/stories/ColorLegends/LegendWithSelector/LegendSelector.stories.js.map +1 -0
  30. package/package.json +1 -1
  31. package/src/component/ColorSelector/ColorSelectorAccordion.tsx +2 -2
  32. package/src/component/ColorSelector/ColorSelectorComponent.tsx +5 -22
  33. package/src/component/ColorSelector/ColorSelectorWrapper.tsx +49 -48
  34. package/src/component/Legend/ColorLegend.tsx +20 -3
  35. package/src/component/Legend/ContinuousLegend.tsx +18 -5
  36. package/src/component/Legend/DiscreteLegend.tsx +36 -67
  37. package/src/component/{ColorTableTypes.ts → Utils/ColorTableTypes.ts} +0 -0
  38. package/src/component/Utils/continousLegend.ts +3 -3
  39. package/src/component/Utils/discreteLegend.ts +9 -83
  40. package/src/index.ts +2 -3
  41. package/src/stories/ColorLegends/{SingleComponent/Single.stories.jsx → LegendWithSelector/LegendSelector.stories.jsx} +4 -4
  42. package/tsconfig.json +2 -2
  43. package/dist/component/ColorTableTypes.js.map +0 -1
  44. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.d.ts +0 -7
  45. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js +0 -52
  46. package/dist/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.js.map +0 -1
  47. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.d.ts +0 -7
  48. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js +0 -38
  49. package/dist/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.js.map +0 -1
  50. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js.map +0 -1
  51. package/src/stories/ColorLegends/LegendWithSelector/DiscreteLegendWithSelector.stories.jsx +0 -44
  52. package/src/stories/ColorLegends/LegendWithSelector/LegendWithSelector.stories.jsx +0 -30
@@ -1,23 +1,20 @@
1
1
  // eslint-disable-next-line
2
2
  export default function discreteLegendUtil(itemColor, isSelectorLegend, horizontal) {
3
- // var cellWidth = 22;
4
- // var cellHeight = 22;
5
- // if (isSelectorLegend) {
6
- // cellWidth = 25;
7
- // cellHeight = 22;
8
- // }
9
3
  var legendValues = [];
10
4
  // eslint-disable-next-line
11
5
  function legend(g) {
12
6
  function drawLegend() {
13
7
  // Code to fill the color
14
8
  // Styling for color selector legend
15
- //if (isSelectorLegend) {
16
9
  g.selectAll("g.legendCells")
17
10
  .data(itemColor)
18
11
  .enter()
19
12
  .append("g")
20
13
  .append("rect")
14
+ .append("title")
15
+ .text(function (d) {
16
+ return d["name"];
17
+ })
21
18
  .attr("class", "rectLabel")
22
19
  .style("cursor", "pointer")
23
20
  .style("pointer-events", "all");
@@ -29,106 +26,40 @@ export default function discreteLegendUtil(itemColor, isSelectorLegend, horizont
29
26
  });
30
27
  if (horizontal && !isSelectorLegend) {
31
28
  g.selectAll("rect")
32
- .attr("x", function (d, i) {
33
- console.log(d);
29
+ .attr("x", function (_d, i) {
34
30
  return i;
35
31
  })
36
32
  .attr("y", 0);
37
33
  }
38
34
  else if (!horizontal && !isSelectorLegend) {
39
35
  g.selectAll("rect")
40
- .attr("y", function (d, i) {
41
- console.log(d);
36
+ .attr("y", function (_d, i) {
42
37
  return i;
43
38
  })
44
39
  .attr("x", 0);
45
40
  }
46
41
  else if (horizontal == true && isSelectorLegend) {
47
42
  g.selectAll("rect")
48
- .attr("x", function (d, i) {
49
- console.log(d);
43
+ .attr("x", function (_d, i) {
50
44
  return i;
51
45
  })
52
46
  .attr("y", 0);
53
47
  }
54
48
  else if (horizontal == false && isSelectorLegend) {
55
49
  g.selectAll("rect")
56
- .attr("y", function (d, i) {
57
- console.log(d);
50
+ .attr("y", function (_d, i) {
58
51
  return i;
59
52
  })
60
53
  .attr("x", 0);
61
54
  }
62
55
  else {
63
56
  g.selectAll("rect")
64
- .attr("x", function (d, i) {
65
- console.log(d);
57
+ .attr("x", function (_d, i) {
66
58
  return i;
67
59
  })
68
60
  .attr("y", 0);
69
61
  }
70
- // Display the labels for legend
71
- // g.selectAll("g")
72
- // .style("background", "grey")
73
- // .append("text")
74
- // .attr("class", "breakLabels")
75
- // .style("font-size", "0.4")
76
- // //.attr("x", cellWidth + cellPadding)
77
- // //.attr("y", 5 + cellHeight / 2)
78
- // .attr("x", function (d: any, i: any) {
79
- // //console.log(d)
80
- // return i + "." + 25
81
- // })
82
- // .attr("y", 1.5)
83
- // .text(function (d: any, i: any) {
84
- // //console.log(d)
85
- // return i;
86
- // })
87
- //}
88
- // styling for main legend
89
- // else {
90
- // itemColor.forEach((item, index) => {
91
- // legendValues[index].color = item.color;
92
- // });
93
- // g.selectAll("g.legendCells")
94
- // .append("text")
95
- // .attr("class", "breakLabels")
96
- // .style("fill", "#6F6F6F")
97
- // .attr("x", cellWidth + cellPadding)
98
- // .attr("y", 5 + cellHeight / 2)
99
- // .text(function (d: Record<string, unknown>, i:any) {
100
- // return d['label'];
101
- // });
102
- // g.selectAll("g.legendCells")
103
- // .style("cursor", "pointer")
104
- // .append("rect")
105
- // .attr("height", cellHeight)
106
- // .attr("width", cellWidth)
107
- // .style("fill", function (d: Record<string, unknown>) {
108
- // //console.log('d', d)
109
- // return d["color"];
110
- // })
111
- // // Alighment of cell in straight line
112
- // g.selectAll("g.legendCells").attr(
113
- // "transform",
114
- // function (_d: Record<string, unknown>, i: number) {
115
- // return (
116
- // "translate(0," + i * (cellHeight + cellPadding) + ")"
117
- // //"translate(0," + i + ")"
118
- // );
119
- // }
120
- // );
121
- // }
122
62
  }
123
- // display the discrete legend
124
- // if (!isSelectorLegend) {
125
- // // console.log('itemcolor', itemColor)
126
- // g.selectAll("g.legendCells")
127
- // .data(legendValues)
128
- // .enter()
129
- // .append("g")
130
- // .attr("class", "legendCells")
131
- // }
132
63
  drawLegend();
133
64
  }
134
65
  // eslint-disable-next-line
@@ -1 +1 @@
1
- {"version":3,"file":"discreteLegend.js","sourceRoot":"","sources":["../../../src/component/Utils/discreteLegend.ts"],"names":[],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Y,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC;AAClB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,10 +2,10 @@ import { ColorSelectorAccordion } from './component/ColorSelector/ColorSelectorA
2
2
  import { ColorSelectorComponent } from './component/ColorSelector/ColorSelectorComponent';
3
3
  import { ColorSelectorWrapper } from './component/ColorSelector/ColorSelectorWrapper';
4
4
  import { ContinuousLegend } from './component/Legend/ContinuousLegend';
5
- import { colorTableData, DiscreteColorLegend } from './component/Legend/DiscreteLegend';
5
+ import { DiscreteColorLegend } from './component/Legend/DiscreteLegend';
6
6
  import { ColorLegend } from './component/Legend/ColorLegend';
7
7
  import { colorsArray, rgbValues, RGBToHex } from './component/Utils/continousLegend';
8
8
  import { d3ColorScales } from './component/Utils/d3ColorScale';
9
- import { colorTablesObj, colorTablesArray } from './component/ColorTableTypes';
9
+ import { colorTablesObj, colorTablesArray } from './component/Utils/ColorTableTypes';
10
10
  import * as colorTables from './component/color-tables.json';
11
- export { ColorSelectorAccordion, ColorSelectorComponent, ColorSelectorWrapper, ContinuousLegend, colorTableData, DiscreteColorLegend, ColorLegend, colorsArray, rgbValues, RGBToHex, d3ColorScales, colorTablesObj, colorTablesArray, colorTables, };
11
+ export { ColorSelectorAccordion, ColorSelectorComponent, ColorSelectorWrapper, ContinuousLegend, DiscreteColorLegend, ColorLegend, colorsArray, rgbValues, RGBToHex, d3ColorScales, colorTablesObj, colorTablesArray, colorTables, };
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import { ColorSelectorAccordion } from './component/ColorSelector/ColorSelectorA
2
2
  import { ColorSelectorComponent } from './component/ColorSelector/ColorSelectorComponent';
3
3
  import { ColorSelectorWrapper } from './component/ColorSelector/ColorSelectorWrapper';
4
4
  import { ContinuousLegend } from './component/Legend/ContinuousLegend';
5
- import { colorTableData, DiscreteColorLegend } from './component/Legend/DiscreteLegend';
5
+ import { DiscreteColorLegend } from './component/Legend/DiscreteLegend';
6
6
  import { ColorLegend } from './component/Legend/ColorLegend';
7
7
  import { colorsArray, rgbValues, RGBToHex } from './component/Utils/continousLegend';
8
8
  import { d3ColorScales } from './component/Utils/d3ColorScale';
9
9
  import * as colorTables from './component/color-tables.json';
10
- export { ColorSelectorAccordion, ColorSelectorComponent, ColorSelectorWrapper, ContinuousLegend, colorTableData, DiscreteColorLegend, ColorLegend, colorsArray, rgbValues, RGBToHex, d3ColorScales, colorTables, };
10
+ export { ColorSelectorAccordion, ColorSelectorComponent, ColorSelectorWrapper, ContinuousLegend, DiscreteColorLegend, ColorLegend, colorsArray, rgbValues, RGBToHex, d3ColorScales, colorTables, };
11
11
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,SAAS,EACT,QAAQ,EACR,aAAa,EAGb,WAAW,GACd,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,OAAO,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAE/D,OAAO,KAAK,WAAW,MAAM,+BAA+B,CAAC;AAE7D,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,SAAS,EACT,QAAQ,EACR,aAAa,EAGb,WAAW,GACd,CAAC"}
@@ -3,5 +3,5 @@ declare namespace _default {
3
3
  export const title: string;
4
4
  }
5
5
  export default _default;
6
- export const legendWithSelector: any;
6
+ export const LegendWithColorSelector: any;
7
7
  import { ColorLegend } from "../../../component/Legend/ColorLegend";
@@ -14,7 +14,7 @@ import colorTables from "../../../component/color-tables.json";
14
14
  import { ColorLegend } from "../../../component/Legend/ColorLegend";
15
15
  export default {
16
16
  component: ColorLegend,
17
- title: "Legends/SingleComponent",
17
+ title: "Legends/LegendWithColorSelector",
18
18
  };
19
19
  // prop for continous legend
20
20
  var min = 0;
@@ -22,7 +22,7 @@ var max = 0.35;
22
22
  var dataObjectName = "Legend";
23
23
  var position = [16, 10];
24
24
  var horizontal = true;
25
- var colorName = "Physics";
25
+ var colorName = "Rainbow";
26
26
  // prop for discrete data
27
27
  var discreteData = {
28
28
  "Above_BCU": [[], 0],
@@ -44,8 +44,8 @@ var discreteData = {
44
44
  var Template = function (args) {
45
45
  return React.createElement(ColorLegend, __assign({}, args));
46
46
  };
47
- export var legendWithSelector = Template.bind({});
48
- legendWithSelector.args = {
47
+ export var LegendWithColorSelector = Template.bind({});
48
+ LegendWithColorSelector.args = {
49
49
  min: min,
50
50
  max: max,
51
51
  dataObjectName: dataObjectName,
@@ -55,4 +55,4 @@ legendWithSelector.args = {
55
55
  colorTables: colorTables,
56
56
  discreteData: discreteData,
57
57
  };
58
- //# sourceMappingURL=Single.stories.js.map
58
+ //# sourceMappingURL=LegendSelector.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LegendSelector.stories.js","sourceRoot":"","sources":["../../../../src/stories/ColorLegends/LegendWithSelector/LegendSelector.stories.jsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAC,WAAW,EAAC,MAAM,uCAAuC,CAAC;AAElE,eAAe;IACX,SAAS,EAAE,WAAW;IACtB,KAAK,EAAE,iCAAiC;CAC3C,CAAC;AAEF,4BAA4B;AAC5B,IAAM,GAAG,GAAG,CAAC,CAAC;AACd,IAAM,GAAG,GAAG,IAAI,CAAC;AACjB,IAAM,cAAc,GAAG,QAAQ,CAAC;AAChC,IAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAC1B,IAAM,UAAU,GAAG,IAAI,CAAC;AACxB,IAAM,SAAS,GAAG,SAAS,CAAC;AAE5B,yBAAyB;AACzB,IAAM,YAAY,GAAG;IACjB,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACpB,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAChB,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACd,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACd,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACd,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IACb,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IACd,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IACd,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IACd,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;IACd,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;CACpB,CAAC;AAEF,IAAM,QAAQ,GAAG,UAAC,IAAI;IAClB,OAAO,oBAAC,WAAW,eAAK,IAAI,EAAI,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,CAAC,IAAM,uBAAuB,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACzD,uBAAuB,CAAC,IAAI,GAAG;IAC3B,GAAG,KAAA;IACH,GAAG,KAAA;IACH,cAAc,gBAAA;IACd,QAAQ,UAAA;IACR,UAAU,YAAA;IACV,SAAS,WAAA;IACT,WAAW,aAAA;IACX,YAAY,cAAA;CACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emerson-eps/color-tables",
3
- "version": "0.2.10",
3
+ "version": "0.2.13",
4
4
  "description": "Standard library of color tables for geological domain",
5
5
  "release": {
6
6
  "branches": [
@@ -22,7 +22,7 @@ export const ColorSelectorAccordion = (props: any) => {
22
22
  Geologic Color Scale
23
23
  </Accordion.Header>
24
24
  <Accordion.Panel>
25
- <ColorSelectorWrapper useColorTableColors={true} useD3Colors={false} colorScaleObject={props}/>
25
+ <ColorSelectorWrapper useColorTableColors={true} colorScaleObject={props}/>
26
26
  </Accordion.Panel>
27
27
  </Accordion.Item>
28
28
  </Accordion>
@@ -32,7 +32,7 @@ export const ColorSelectorAccordion = (props: any) => {
32
32
  D3 Color Scale
33
33
  </Accordion.Header>
34
34
  <Accordion.Panel>
35
- <ColorSelectorWrapper useD3Colors={true} useColorTableColors={false} colorScaleObject={props}/>
35
+ <ColorSelectorWrapper useColorTableColors={false} colorScaleObject={props}/>
36
36
  </Accordion.Panel>
37
37
  </Accordion.Item>
38
38
  </Accordion>
@@ -4,7 +4,6 @@ import { RGBToHex } from "../Utils/continousLegend";
4
4
  import {d3ColorScales} from "../Utils/d3ColorScale";
5
5
  import { select, range} from "d3";
6
6
  import * as d3 from "d3";
7
- import { colorTablesArray, colorTablesObj } from "../ColorTableTypes";
8
7
  import discreteLegendUtil from "../Utils/discreteLegend";
9
8
  import { color } from "d3-color";
10
9
 
@@ -17,7 +16,6 @@ declare type legendProps = {
17
16
  useDiscColorTable?: boolean;
18
17
  valueIndex?: any;
19
18
  colorScaleData: any;
20
- getColorMapname?: any | null;
21
19
  }
22
20
 
23
21
  declare type ItemColor = {
@@ -26,7 +24,6 @@ declare type ItemColor = {
26
24
  }
27
25
 
28
26
  export const ColorSelectorComponent: React.FC<legendProps> = ({
29
- // position,
30
27
  colorsObject,
31
28
  legendColor,
32
29
  legendColorName,
@@ -34,7 +31,6 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
34
31
  useDiscColorTable,
35
32
  valueIndex,
36
33
  colorScaleData,
37
- // getColorMapname,
38
34
  }: legendProps) => {
39
35
 
40
36
  const divRef = useRef<HTMLDivElement>(null);
@@ -55,7 +51,7 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
55
51
  const handleChange = React.useCallback(() => {
56
52
  // continous legend with colortable colors
57
53
  if (colorsObject && Object.keys(colorsObject).length > 0 && useContColorTable) {
58
- colorScaleData(colorsObject, true);
54
+ colorScaleData ? colorScaleData(colorsObject, true) : null;
59
55
  }
60
56
  // continous legend with d3 colors
61
57
  else if (data && !useContColorTable) {
@@ -63,15 +59,15 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
63
59
  data.forEach((colorsObject: any) => {
64
60
  arrayData.push([0 + "." + colorsObject.value, color(colorsObject.color)?.rgb().r, color(colorsObject.color)?.rgb().g, color(colorsObject.color)?.rgb().b])
65
61
  });
66
- colorScaleData({ arrayData, legendColorName }, true);
62
+ colorScaleData ? colorScaleData({ arrayData, legendColorName }, true) : null;
67
63
  }
68
64
  // discrete legend with colortable colors
69
65
  else if (colorsObject && Object.keys(colorsObject).length > 0 && useDiscColorTable) {
70
- colorScaleData(colorsObject, false);
66
+ colorScaleData ? colorScaleData(colorsObject, false) : null;
71
67
  }
72
68
  // discrete legend with d3 colors
73
69
  else {
74
- colorScaleData({colorsObject, legendColorName}, false);
70
+ colorScaleData ? colorScaleData({colorsObject, legendColorName}, false) : null;
75
71
  }
76
72
  }, []);
77
73
 
@@ -159,7 +155,6 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
159
155
  .attr("y", 15)
160
156
  .style("font-size", "smaller")
161
157
  .style("font-weight", "900")
162
- // .attr("textLength","5em")
163
158
  .text(colorsObject.name);
164
159
 
165
160
  // draw the rectangle and fill with gradient
@@ -314,16 +309,4 @@ export const ColorSelectorComponent: React.FC<legendProps> = ({
314
309
  ref={divRef} onClick={handleChange}></div>
315
310
  </div>
316
311
  );
317
- };
318
-
319
- // Based on name return the colors array from color.tables.json file
320
- export function colorTableData(
321
- colorName: string,
322
- colorTables: colorTablesArray
323
- ): [number, number, number, number][] {
324
- const colorTableData = colorTables.filter(
325
- (value: colorTablesObj) =>
326
- value.name.toLowerCase() == colorName.toLowerCase()
327
- );
328
- return colorTableData.length > 0 ? colorTableData[0].colors : [];
329
- }
312
+ };
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import * as colorTables from "../color-tables.json";
2
+ const colorTables = require("../color-tables.json");
3
3
  import {d3ColorScales} from "../Utils/d3ColorScale";
4
4
  import {ColorSelectorComponent} from "./ColorSelectorComponent";
5
5
 
@@ -11,7 +11,6 @@ const discreteD3ColorData: any = [];
11
11
 
12
12
  declare type legendProps = {
13
13
  useColorTableColors: boolean,
14
- useD3Colors: boolean,
15
14
  colorScaleObject: any
16
15
  }
17
16
 
@@ -53,59 +52,61 @@ d3discreteData.forEach((element: any) => {
53
52
 
54
53
  export const ColorSelectorWrapper: React.FC<legendProps> = ({
55
54
  useColorTableColors,
56
- useD3Colors,
57
55
  colorScaleObject,
58
56
  }: legendProps) => {
59
57
  let continuousLegend;
60
58
  let discreteLegend;
59
+
60
+ // return continuous and discrete legend which uses d3 data
61
+ if (!useColorTableColors) {
61
62
 
62
- // return continuous and discrete legend which uses colortable data
63
- if (useColorTableColors) {
64
- continuousLegend = continuosColorData.map((value: any, key: any) => {
65
- return <div>
66
- <ColorSelectorComponent
67
- position={position + key}
68
- colorsObject={value}
69
- useContColorTable={true}
70
- valueIndex={key}
63
+ continuousLegend = continuosD3ColorData.map((val: any, key: any) => {
64
+ return <ColorSelectorComponent
65
+ position={position + key}
66
+ legendColor={val.color}
67
+ legendColorName={val.name}
68
+ useContColorTable={false}
69
+ valueIndex={key + "0"}
70
+ colorScaleData={colorScaleObject.colorScaleObject}
71
+ />
72
+ });
73
+
74
+ discreteLegend = d3discreteData.map((val: any, key: any) => {
75
+ return <ColorSelectorComponent
76
+ position={position + key}
77
+ colorsObject={val.colors}
78
+ legendColorName={val.name}
79
+ useDiscColorTable={false}
80
+ colorScaleData={colorScaleObject.colorScaleObject}
81
+ />
82
+ });
83
+ }
84
+
85
+ // return continuous and discrete legend which uses colortable data
86
+ else if (useColorTableColors) {
87
+ continuousLegend = continuosColorData.map((value: any, key: any) => {
88
+ return <div>
89
+ <ColorSelectorComponent
90
+ position={position + key}
91
+ colorsObject={value}
92
+ useContColorTable={true}
93
+ valueIndex={key}
94
+ colorScaleData={colorScaleObject.colorScaleObject}
95
+ />
96
+ </div>
97
+ });
98
+
99
+ discreteLegend = discreteColorData.map((val: any, key: any) => {
100
+ return <ColorSelectorComponent
101
+ position={position + key}
102
+ colorsObject={discreteColorData[key]}
103
+ legendColorName={val.name}
104
+ useDiscColorTable={true}
71
105
  colorScaleData={colorScaleObject.colorScaleObject}
72
106
  />
73
- </div>
74
- });
75
-
76
- discreteLegend = discreteColorData.map((val: any, key: any) => {
77
- return <ColorSelectorComponent
78
- position={position + key}
79
- colorsObject={discreteColorData[key]}
80
- legendColorName={val.name}
81
- useDiscColorTable={true}
82
- colorScaleData={colorScaleObject.colorScaleObject}
83
- />
84
- });
85
- }
86
- // return continuous and discrete legend which uses d3 data
87
- if (useD3Colors) {
88
- continuousLegend = continuosD3ColorData.map((val: any, key: any) => {
89
- return <ColorSelectorComponent
90
- position={position + key}
91
- legendColor={val.color}
92
- legendColorName={val.name}
93
- useContColorTable={false}
94
- valueIndex={key + "0"}
95
- colorScaleData={colorScaleObject.colorScaleObject}
96
- />
97
- });
98
-
99
- discreteLegend = d3discreteData.map((val: any, key: any) => {
100
- return <ColorSelectorComponent
101
- position={position + key}
102
- colorsObject={val.colors}
103
- legendColorName={val.name}
104
- useDiscColorTable={false}
105
- colorScaleData={colorScaleObject.colorScaleObject}
106
- />
107
- });
108
- }
107
+ });
108
+ }
109
+ //}
109
110
 
110
111
  return (
111
112
  <div className="legendWrapper"
@@ -3,6 +3,7 @@ import { DiscreteColorLegend } from "./DiscreteLegend";
3
3
  import { ContinuousLegend } from "./ContinuousLegend";
4
4
  import {useCallback} from "react";
5
5
  import { ColorSelectorAccordion } from "../ColorSelector/ColorSelectorAccordion";
6
+ import {d3ColorScales} from "../Utils/d3ColorScale";
6
7
 
7
8
  declare type ColorLegendProps = {
8
9
  colorTables: any;
@@ -35,7 +36,23 @@ export const ColorLegend: React.FC<ColorLegendProps> = ({
35
36
  }, []);
36
37
 
37
38
  const [updateLegend, setUpdateLegendColor] = React.useState([] as any);
38
- const [isCont, setIsCont] = React.useState(true);
39
+
40
+ const isColortableColors = colorTables.find(
41
+ (value: any) => {
42
+ return value?.name == colorName
43
+ }
44
+ );
45
+
46
+ const isD3Colors = d3ColorScales.find(
47
+ (value: any) => {
48
+ return value?.name == colorName
49
+ }
50
+ );
51
+
52
+ const [isCont, setIsCont] = React.useState(
53
+ (isColortableColors || isD3Colors) &&
54
+ (isColortableColors?.discrete == false || isD3Colors?.discrete == false) ? true : false
55
+ );
39
56
 
40
57
  // Get new colorscale from colorselector and update legend
41
58
  const colorScaleObject = React.useCallback((data: any, value: any) => {
@@ -54,7 +71,7 @@ export const ColorLegend: React.FC<ColorLegendProps> = ({
54
71
  return (
55
72
  <div>
56
73
  <div onClick={handleClick}>
57
- {isCont && (
74
+ {isCont == true && (
58
75
  <ContinuousLegend
59
76
  min={min}
60
77
  max={max}
@@ -66,7 +83,7 @@ export const ColorLegend: React.FC<ColorLegendProps> = ({
66
83
  updateLegend={updateLegend}
67
84
  />
68
85
  )}
69
- {!isCont && (
86
+ {isCont == false && (
70
87
  <DiscreteColorLegend
71
88
  discreteData={discreteData}
72
89
  dataObjectName={dataObjectName}
@@ -2,7 +2,10 @@ import * as React from "react";
2
2
  import { useRef } from "react";
3
3
  import { RGBToHex, colorsArray } from "../Utils/continousLegend";
4
4
  import { select, scaleLinear, scaleSequential, axisBottom, axisRight } from "d3";
5
- import { colorTablesArray } from "../ColorTableTypes";
5
+ import { colorTablesArray } from "../Utils/ColorTableTypes";
6
+ import {d3ColorScales} from "../Utils/d3ColorScale";
7
+ import { color } from "d3-color";
8
+ import { range } from "d3";
6
9
 
7
10
  declare type legendProps = {
8
11
  min: number;
@@ -56,11 +59,11 @@ export const ContinuousLegend: React.FC<legendProps> = ({
56
59
  let legendColors = typeof colorTables === "string" ?
57
60
  colorsArray(colorName, dataSet)
58
61
  :
59
- colorsArray(colorName, colorTables);
62
+ colorsArray(colorName, colorTables);
60
63
 
61
64
  // Update color of legend based on color selector scales
62
65
  // data is passed on click upon color scales
63
- if (updateLegend) {
66
+ if (updateLegend && Object.keys(updateLegend).length > 0) {
64
67
  // legend using color table data
65
68
  if (updateLegend.color) {
66
69
  legendColors = updateLegend.color;
@@ -70,9 +73,19 @@ export const ContinuousLegend: React.FC<legendProps> = ({
70
73
  legendColors = updateLegend.arrayData;
71
74
  }
72
75
  }
73
- // main continuous legend
76
+ // main continuous legend for colortable colors
77
+ if (legendColors.length > 0) {
78
+ legendColors = legendColors
79
+ }
80
+ // main continuous legend for d3 colors
74
81
  else {
75
- legendColors
82
+ const arrayData: any = []
83
+ const d3ColorArrays = colorsArray(colorName, d3ColorScales)
84
+ const data = range(10).map((d) => ({color: d3ColorArrays(d / 10)}));
85
+ data.forEach((colorsObject: any, index: number) => {
86
+ arrayData.push([0 + "." + index, color(colorsObject.color)?.rgb().r, color(colorsObject.color)?.rgb().g, color(colorsObject.color)?.rgb().b])
87
+ });
88
+ legendColors = arrayData
76
89
  }
77
90
 
78
91
  legendColors.forEach((value: [number, number, number, number]) => {