@emerson-eps/color-tables 0.2.9 → 0.2.12

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 (44) 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 +1 -11
  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.d.ts +2 -2
  10. package/dist/component/Legend/ColorLegend.js +12 -5
  11. package/dist/component/Legend/ColorLegend.js.map +1 -1
  12. package/dist/component/Legend/ContinuousLegend.d.ts +1 -1
  13. package/dist/component/Legend/ContinuousLegend.js +18 -4
  14. package/dist/component/Legend/ContinuousLegend.js.map +1 -1
  15. package/dist/component/Legend/DiscreteLegend.d.ts +1 -2
  16. package/dist/component/Legend/DiscreteLegend.js +28 -27
  17. package/dist/component/Legend/DiscreteLegend.js.map +1 -1
  18. package/dist/component/{ColorTableTypes.d.ts → Utils/ColorTableTypes.d.ts} +0 -0
  19. package/dist/component/{ColorTableTypes.js → Utils/ColorTableTypes.js} +0 -0
  20. package/dist/component/Utils/ColorTableTypes.js.map +1 -0
  21. package/dist/component/Utils/continousLegend.d.ts +2 -2
  22. package/dist/component/Utils/continousLegend.js.map +1 -1
  23. package/dist/component/Utils/discreteLegend.js +21 -77
  24. package/dist/component/Utils/discreteLegend.js.map +1 -1
  25. package/dist/index.d.ts +7 -5
  26. package/dist/index.js +6 -4
  27. package/dist/index.js.map +1 -1
  28. package/dist/stories/ColorLegends/SingleComponent/Single.stories.d.ts +1 -1
  29. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js +2 -2
  30. package/dist/stories/ColorLegends/SingleComponent/Single.stories.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/component/ColorSelector/ColorSelectorAccordion.tsx +2 -2
  33. package/src/component/ColorSelector/ColorSelectorComponent.tsx +1 -18
  34. package/src/component/ColorSelector/ColorSelectorWrapper.tsx +49 -48
  35. package/src/component/Legend/ColorLegend.tsx +22 -7
  36. package/src/component/Legend/ContinuousLegend.tsx +18 -5
  37. package/src/component/Legend/DiscreteLegend.tsx +32 -60
  38. package/src/component/{ColorTableTypes.ts → Utils/ColorTableTypes.ts} +0 -0
  39. package/src/component/Utils/continousLegend.ts +3 -3
  40. package/src/component/Utils/discreteLegend.ts +11 -82
  41. package/src/index.ts +12 -9
  42. package/src/stories/ColorLegends/SingleComponent/Single.stories.jsx +2 -2
  43. package/tsconfig.json +2 -2
  44. package/dist/component/ColorTableTypes.js.map +0 -1
@@ -2,11 +2,13 @@ import * as React from "react";
2
2
  import { useRef } from "react";
3
3
  import discreteLegendUtil from "../Utils/discreteLegend";
4
4
  import { select, scaleOrdinal } from "d3";
5
- import { colorTablesArray, colorTablesObj } from "../ColorTableTypes";
5
+ import { colorTablesArray } from "../Utils/ColorTableTypes";
6
+ import { colorsArray } from "../Utils/continousLegend"
7
+ import {d3ColorScales} from "../Utils/d3ColorScale";
6
8
 
7
9
  declare type ItemColor = {
8
10
  color: string;
9
- }
11
+ };
10
12
 
11
13
  declare type colorLegendProps = {
12
14
  discreteData: { objects: Record<string, [number[], number]> };
@@ -16,7 +18,7 @@ declare type colorLegendProps = {
16
18
  colorTables: colorTablesArray | string;
17
19
  horizontal?: boolean | null;
18
20
  updateLegend?: any
19
- }
21
+ };
20
22
 
21
23
  export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
22
24
  discreteData,
@@ -56,29 +58,40 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
56
58
  dataSet = await res.json();
57
59
  }
58
60
 
59
- const colorsArray =
61
+ const arrayOfColors =
60
62
  typeof colorTables === "string"
61
- ? colorTableData(colorName, dataSet)
62
- : colorTableData(colorName, colorTables);
63
+ ? colorsArray(colorName, dataSet)
64
+ : colorsArray(colorName, colorTables);
63
65
 
64
- console.log('updateLegend', updateLegend)
66
+ const d3ColorArrays = colorsArray(colorName, d3ColorScales)
65
67
 
66
68
  // Main discrete legend
67
69
  if (!updateLegend || updateLegend.length == 0) {
68
70
  Object.keys(discreteData).forEach((key) => {
69
71
  //eslint-disable-next-line
70
72
  let code = (discreteData as { [key: string]: any })[key][1]
71
- //compare the first value in colorarray(colortable) and code from discreteData
72
- const matchedColorsArrays = colorsArray.find(
73
- (value: number[]) => {
74
- return value[0] == code;
75
- }
76
- );
77
- if (matchedColorsArrays)
78
- itemColor.push({
79
- color: RGBToHex(matchedColorsArrays),
73
+ // for colortable colors
74
+ if (arrayOfColors.length > 0) {
75
+ //compare the first value in colorarray(colortable) and code from discreteData
76
+ const matchedColorsArrays = arrayOfColors.find(
77
+ (value: number[]) => {
78
+ return value[0] == code;
79
+ }
80
+ );
81
+ if (matchedColorsArrays)
82
+ itemColor.push({
83
+ color: RGBToHex(matchedColorsArrays),
84
+ });
85
+ itemName.push(key);
86
+ }
87
+ // for d3 colors
88
+ else {
89
+ var matchedColorsArrays = d3ColorArrays.find((value: number,index: number) => {
90
+ return index == code;
80
91
  });
81
- itemName.push(key);
92
+ if(matchedColorsArrays) itemColor.push({color: matchedColorsArrays});
93
+ }
94
+
82
95
  });
83
96
  useSelectorLegend = false;
84
97
  }
@@ -103,36 +116,13 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
103
116
  useSelectorLegend = true;
104
117
  }
105
118
 
106
- // const toolTipName = itemName.map((word, idx) => {
107
- // return <li key={idx}>{word}</li>;
108
- // });
109
-
110
- // let nameTool;
111
-
112
- // toolTipName.forEach((data) => {
113
- // //nameTool.push(data.props.children)
114
- // nameTool = data.props.children;
115
- // });
116
-
117
- // // create a tooltip
118
- // const tooltip = select(divRef.current)
119
- // .append("div")
120
- // .style("position", "absolute")
121
- // .style("visibility", "hidden")
122
- // .style("background-color", "black")
123
- // .style("border", "solid")
124
- // .style("border-width", "1px")
125
- // .style("border-radius", "5px")
126
- // .style("padding", "10px")
127
- // .text(nameTool)
128
- // .style("color", "grey");
129
-
130
119
  const ordinalValues = scaleOrdinal().domain(itemName);
131
120
  const colorLegend = discreteLegendUtil(
132
121
  itemColor,
133
122
  useSelectorLegend,
134
123
  horizontal
135
- ).inputScale(ordinalValues);
124
+ )
125
+ .inputScale(ordinalValues);
136
126
  const currentDiv = select(divRef.current);
137
127
  let totalRect;
138
128
 
@@ -148,12 +138,6 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
148
138
  const svgLegend = currentDiv
149
139
  .style("margin", "5px")
150
140
  .append("svg")
151
- // .on("mouseover", function () {
152
- // return tooltip.style("visibility", "visible");
153
- // })
154
- // .on("mouseout", function () {
155
- // return tooltip.style("visibility", "hidden");
156
- // })
157
141
  .call(colorLegend);
158
142
 
159
143
  // Style for main horizontal legend
@@ -210,18 +194,6 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
210
194
  );
211
195
  };
212
196
 
213
- // Based on name return the colors array from color.tables.json file
214
- export function colorTableData(
215
- colorName: string,
216
- colorTables: colorTablesArray
217
- ): [number, number, number, number][] {
218
- const colorTableData = colorTables.filter(
219
- (value: colorTablesObj) =>
220
- value.name.toLowerCase() == colorName.toLowerCase()
221
- );
222
- return colorTableData.length > 0 ? colorTableData[0].colors : [];
223
- }
224
-
225
197
  export function RGBToHex(rgb: number[]) {
226
198
  let r = rgb[1].toString(16),
227
199
  g = rgb[2].toString(16),
@@ -3,13 +3,13 @@ import { interpolateRgb } from "d3-interpolate";
3
3
  import {
4
4
  colorTablesArray,
5
5
  colorTablesObj,
6
- } from "../ColorTableTypes";
6
+ } from "../Utils/ColorTableTypes";
7
7
 
8
8
  // Based on objectName return the colors array from color.tables.json file
9
9
  export function colorsArray(
10
10
  colorName: string,
11
- colorTables: colorTablesArray
12
- ): [number, number, number, number][] {
11
+ colorTables: any
12
+ ): any {
13
13
  const colorTableData = colorTables.filter(
14
14
  (value: colorTablesObj) =>
15
15
  value.name.toLowerCase() == colorName.toLowerCase()
@@ -4,14 +4,6 @@ declare type ItemColor = {
4
4
 
5
5
  // eslint-disable-next-line
6
6
  export default function discreteLegendUtil(itemColor: ItemColor[], isSelectorLegend?: boolean, horizontal?: any): any {
7
- // var cellWidth = 22;
8
- // var cellHeight = 22;
9
-
10
- // if (isSelectorLegend) {
11
- // cellWidth = 25;
12
- // cellHeight = 22;
13
- // }
14
-
15
7
  const legendValues: ItemColor[] = [];
16
8
 
17
9
  // eslint-disable-next-line
@@ -37,105 +29,42 @@ export default function discreteLegendUtil(itemColor: ItemColor[], isSelectorLeg
37
29
  if (horizontal && !isSelectorLegend) {
38
30
  g.selectAll("rect")
39
31
  .attr("x", function (d: number, i: number) {
40
- console.log(d)
41
- return i;
32
+ // temporary workaround to ignore typescript error (d value as unused)
33
+ if (i) return i;
34
+ else if (d) return null;
42
35
  })
43
36
  .attr("y", 0);
44
37
  } else if (!horizontal && !isSelectorLegend) {
45
38
  g.selectAll("rect")
46
39
  .attr("y", function (d: number, i: number) {
47
- console.log(d)
48
- return i;
40
+ if (i) return i;
41
+ else if (d) return null;
49
42
  })
50
43
  .attr("x", 0);
51
44
  } else if (horizontal == true && isSelectorLegend) {
52
45
  g.selectAll("rect")
53
46
  .attr("x", function (d: number, i: number) {
54
- console.log(d)
55
- return i;
47
+ if (i) return i;
48
+ else if (d) return null;
56
49
  })
57
50
  .attr("y", 0);
58
51
  } else if (horizontal == false && isSelectorLegend) {
59
52
  g.selectAll("rect")
60
53
  .attr("y", function (d: number, i: number) {
61
- console.log(d)
62
- return i;
54
+ if (i) return i;
55
+ else if (d) return null;
63
56
  })
64
57
  .attr("x", 0);
65
58
  } else {
66
59
  g.selectAll("rect")
67
60
  .attr("x", function (d: number, i: number) {
68
- console.log(d)
69
- return i;
61
+ if (i) return i;
62
+ else if (d) return null;
70
63
  })
71
64
  .attr("y", 0);
72
65
  }
73
-
74
- // Display the labels for legend
75
- // g.selectAll("g")
76
- // .style("background", "grey")
77
- // .append("text")
78
- // .attr("class", "breakLabels")
79
- // .style("font-size", "0.4")
80
- // //.attr("x", cellWidth + cellPadding)
81
- // //.attr("y", 5 + cellHeight / 2)
82
- // .attr("x", function (d: any, i: any) {
83
- // //console.log(d)
84
- // return i + "." + 25
85
- // })
86
- // .attr("y", 1.5)
87
- // .text(function (d: any, i: any) {
88
- // //console.log(d)
89
- // return i;
90
- // })
91
- //}
92
- // styling for main legend
93
- // else {
94
- // itemColor.forEach((item, index) => {
95
- // legendValues[index].color = item.color;
96
- // });
97
- // g.selectAll("g.legendCells")
98
- // .append("text")
99
- // .attr("class", "breakLabels")
100
- // .style("fill", "#6F6F6F")
101
- // .attr("x", cellWidth + cellPadding)
102
- // .attr("y", 5 + cellHeight / 2)
103
- // .text(function (d: Record<string, unknown>, i:any) {
104
- // return d['label'];
105
- // });
106
- // g.selectAll("g.legendCells")
107
- // .style("cursor", "pointer")
108
- // .append("rect")
109
- // .attr("height", cellHeight)
110
- // .attr("width", cellWidth)
111
- // .style("fill", function (d: Record<string, unknown>) {
112
- // //console.log('d', d)
113
- // return d["color"];
114
- // })
115
-
116
- // // Alighment of cell in straight line
117
- // g.selectAll("g.legendCells").attr(
118
- // "transform",
119
- // function (_d: Record<string, unknown>, i: number) {
120
- // return (
121
- // "translate(0," + i * (cellHeight + cellPadding) + ")"
122
- // //"translate(0," + i + ")"
123
- // );
124
- // }
125
- // );
126
- // }
127
66
  }
128
67
 
129
- // display the discrete legend
130
- // if (!isSelectorLegend) {
131
- // // console.log('itemcolor', itemColor)
132
- // g.selectAll("g.legendCells")
133
- // .data(legendValues)
134
- // .enter()
135
- // .append("g")
136
- // .attr("class", "legendCells")
137
- // }
138
-
139
68
  drawLegend();
140
69
  }
141
70
  // eslint-disable-next-line
package/src/index.ts CHANGED
@@ -1,23 +1,26 @@
1
- import { ContinuousLegend } from './component/Legend/ContinuousLegend';
2
- import { colorsArray, rgbValues, RGBToHex} from './component/Utils/continousLegend';
3
- import { colorTableData, DiscreteColorLegend } from './component/Legend/DiscreteLegend';
4
- import { colorTablesObj, colorTablesArray } from './component/ColorTableTypes';
5
1
  import { ColorSelectorAccordion } from './component/ColorSelector/ColorSelectorAccordion';
6
2
  import { ColorSelectorComponent } from './component/ColorSelector/ColorSelectorComponent';
7
3
  import { ColorSelectorWrapper } from './component/ColorSelector/ColorSelectorWrapper';
4
+ import { ContinuousLegend } from './component/Legend/ContinuousLegend';
5
+ import { DiscreteColorLegend } from './component/Legend/DiscreteLegend';
6
+ import { ColorLegend } from './component/Legend/ColorLegend';
7
+ import { colorsArray, rgbValues, RGBToHex } from './component/Utils/continousLegend';
8
+ import { d3ColorScales } from './component/Utils/d3ColorScale';
9
+ import { colorTablesObj, colorTablesArray } from './component/Utils/ColorTableTypes';
8
10
  import * as colorTables from './component/color-tables.json';
9
11
 
10
12
  export {
13
+ ColorSelectorAccordion,
14
+ ColorSelectorComponent,
15
+ ColorSelectorWrapper,
11
16
  ContinuousLegend,
17
+ DiscreteColorLegend,
18
+ ColorLegend,
12
19
  colorsArray,
13
20
  rgbValues,
14
21
  RGBToHex,
15
- colorTableData,
16
- DiscreteColorLegend,
22
+ d3ColorScales,
17
23
  colorTablesObj,
18
24
  colorTablesArray,
19
- ColorSelectorAccordion,
20
- ColorSelectorComponent,
21
- ColorSelectorWrapper,
22
25
  colorTables,
23
26
  };
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import colorTables from "../../../component/color-tables.json";
3
- import ColorLegend from "../../../component/Legend/ColorLegend";
3
+ import {ColorLegend} from "../../../component/Legend/ColorLegend";
4
4
 
5
5
  export default {
6
6
  component: ColorLegend,
@@ -13,7 +13,7 @@ const max = 0.35;
13
13
  const dataObjectName = "Legend";
14
14
  const position = [16, 10];
15
15
  const horizontal = true;
16
- const colorName = "Physics";
16
+ const colorName = "Pastel1";
17
17
 
18
18
  // prop for discrete data
19
19
  const discreteData = {
package/tsconfig.json CHANGED
@@ -14,8 +14,8 @@
14
14
  "noImplicitAny": true,
15
15
  "strictNullChecks": true,
16
16
  "suppressImplicitAnyIndexErrors": true,
17
- "noUnusedLocals": true,
18
- "noUnusedParameters": true,
17
+ "noUnusedLocals": false,
18
+ "noUnusedParameters": false,
19
19
  "resolveJsonModule": true,
20
20
  },
21
21
  "include": ["src", "./src/custom.d.ts"],
@@ -1 +0,0 @@
1
- {"version":3,"file":"ColorTableTypes.js","sourceRoot":"","sources":["../../src/component/ColorTableTypes.ts"],"names":[],"mappings":""}