@emerson-eps/color-tables 0.2.1 → 0.2.2

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.
@@ -6,7 +6,7 @@ declare type legendProps = {
6
6
  dataObjectName: string;
7
7
  position?: number[] | null;
8
8
  colorName: string;
9
- colorTables: colorTablesArray;
9
+ colorTables: colorTablesArray | string;
10
10
  horizontal?: boolean | null;
11
11
  };
12
12
  export declare const ContinuousLegend: React.FC<legendProps>;
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import * as React from "react";
2
11
  import { useRef } from "react";
3
12
  import { RGBToHex, colorsArray } from "../Utils/continousLegend";
@@ -14,74 +23,84 @@ export const ContinuousLegend = ({ min, max, dataObjectName, position, colorName
14
23
  };
15
24
  }, [min, max, colorName, colorTables, horizontal]);
16
25
  function continuousLegend() {
17
- const itemColor = [];
18
- // Return the matched colors array from color.tables.json file
19
- const colorTableColors = colorsArray(colorName, colorTables);
20
- colorTableColors.forEach((value) => {
21
- // return the color and offset needed to draw the legend
22
- itemColor.push({
23
- offset: RGBToHex(value).offset,
24
- color: RGBToHex(value).color,
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const itemColor = [];
28
+ let dataSet;
29
+ if (typeof colorTables === "string") {
30
+ let res = yield fetch(colorTables);
31
+ dataSet = yield res.json();
32
+ }
33
+ // Return the matched colors array from color.tables.json file
34
+ let colorTableColors = typeof colorTables === "string" ?
35
+ colorsArray(colorName, dataSet)
36
+ :
37
+ colorsArray(colorName, colorTables);
38
+ colorTableColors.forEach((value) => {
39
+ // return the color and offset needed to draw the legend
40
+ itemColor.push({
41
+ offset: RGBToHex(value).offset,
42
+ color: RGBToHex(value).color,
43
+ });
25
44
  });
26
- });
27
- const colorScale = scaleSequential().domain([min, max]);
28
- // append a defs (for definition) element to your SVG
29
- const svgLegend = select(divRef.current)
30
- .append("svg")
31
- .style("background-color", "#ffffffcc")
32
- .style("border-radius", "5px");
33
- if (!horizontal) {
45
+ const colorScale = scaleSequential().domain([min, max]);
46
+ // append a defs (for definition) element to your SVG
47
+ const svgLegend = select(divRef.current)
48
+ .append("svg")
49
+ .style("background-color", "#ffffffcc")
50
+ .style("border-radius", "5px");
51
+ if (!horizontal) {
52
+ svgLegend
53
+ .style("transform", "rotate(270deg)")
54
+ .style("margin-top", "80px");
55
+ }
56
+ const defs = svgLegend.append("defs");
57
+ // append a linearGradient element to the defs and give it a unique id
58
+ const linearGradient = defs
59
+ .append("linearGradient")
60
+ .attr("id", "linear-gradient")
61
+ .attr("x1", "0%")
62
+ .attr("x2", "100%") //since it's a horizontal linear gradient
63
+ .attr("y1", "0%")
64
+ .attr("y2", "0%");
65
+ // append multiple color stops by using D3's data/enter step
66
+ linearGradient
67
+ .selectAll("stop")
68
+ .data(itemColor)
69
+ .enter()
70
+ .append("stop")
71
+ .attr("offset", function (data) {
72
+ return data.offset + "%";
73
+ })
74
+ .attr("stop-color", function (data) {
75
+ return data.color;
76
+ });
77
+ // append title
34
78
  svgLegend
35
- .style("transform", "rotate(270deg)")
36
- .style("margin-top", "80px");
37
- }
38
- const defs = svgLegend.append("defs");
39
- // append a linearGradient element to the defs and give it a unique id
40
- const linearGradient = defs
41
- .append("linearGradient")
42
- .attr("id", "linear-gradient")
43
- .attr("x1", "0%")
44
- .attr("x2", "100%") //since it's a horizontal linear gradient
45
- .attr("y1", "0%")
46
- .attr("y2", "0%");
47
- // append multiple color stops by using D3's data/enter step
48
- linearGradient
49
- .selectAll("stop")
50
- .data(itemColor)
51
- .enter()
52
- .append("stop")
53
- .attr("offset", function (data) {
54
- return data.offset + "%";
55
- })
56
- .attr("stop-color", function (data) {
57
- return data.color;
79
+ .append("text")
80
+ .attr("class", "legendTitle")
81
+ .attr("x", 25)
82
+ .attr("y", 20)
83
+ .style("text-anchor", "left")
84
+ .text(dataObjectName);
85
+ // draw the rectangle and fill with gradient
86
+ svgLegend
87
+ .append("rect")
88
+ .attr("x", 25)
89
+ .attr("y", 30)
90
+ .attr("width", 250)
91
+ .attr("height", 25)
92
+ .style("fill", "url(#linear-gradient)");
93
+ //create tick marks
94
+ const xLeg = scaleLinear().domain([min, max]).range([10, 258]);
95
+ const axisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
96
+ svgLegend
97
+ .attr("class", "axis")
98
+ .append("g")
99
+ .attr("transform", "translate(15, 55)")
100
+ .style("font-size", "10px")
101
+ .style("font-weight", "700")
102
+ .call(axisLeg);
58
103
  });
59
- // append title
60
- svgLegend
61
- .append("text")
62
- .attr("class", "legendTitle")
63
- .attr("x", 25)
64
- .attr("y", 20)
65
- .style("text-anchor", "left")
66
- .text(dataObjectName);
67
- // draw the rectangle and fill with gradient
68
- svgLegend
69
- .append("rect")
70
- .attr("x", 25)
71
- .attr("y", 30)
72
- .attr("width", 250)
73
- .attr("height", 25)
74
- .style("fill", "url(#linear-gradient)");
75
- //create tick marks
76
- const xLeg = scaleLinear().domain([min, max]).range([10, 258]);
77
- const axisLeg = axisBottom(xLeg).tickValues(colorScale.domain());
78
- svgLegend
79
- .attr("class", "axis")
80
- .append("g")
81
- .attr("transform", "translate(15, 55)")
82
- .style("font-size", "10px")
83
- .style("font-weight", "700")
84
- .call(axisLeg);
85
104
  }
86
105
  return (React.createElement("div", { style: {
87
106
  position: "absolute",
@@ -1 +1 @@
1
- {"version":3,"file":"ContinuousLegend.js","sourceRoot":"","sources":["../../../src/component/Legend/ContinuousLegend.tsx"],"names":[],"mappings":"AAAA,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AAU,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;YAEjE,SAAS;iBACJ,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC;iBACrB,MAAM,CAAC,GAAG,CAAC;iBACX,IAAI,CAAC,WAAW,EAAE,mBAAmB,CAAC;iBACtC,KAAK,CAAC,WAAW,EAAE,MAAM,CAAC;iBAC1B,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC;iBAC3B,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KAAA;IAED,OAAO,CACH,6BACI,KAAK,EAAE;YACH,QAAQ,EAAE,UAAU;YACpB,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;YACnC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;SACpC;QAED,6BAAK,EAAE,EAAC,QAAQ,EAAC,GAAG,EAAE,MAAM,GAAQ,CAClC,CACT,CAAC;AACN,CAAC,CAAC;AAEF,gBAAgB,CAAC,YAAY,GAAG;IAC5B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;CACpB,CAAC"}
@@ -7,7 +7,7 @@ declare type colorLegendProps = {
7
7
  dataObjectName: string;
8
8
  position?: number[] | null;
9
9
  colorName: string;
10
- colorTables: colorTablesArray;
10
+ colorTables: colorTablesArray | string;
11
11
  horizontal?: boolean | null;
12
12
  };
13
13
  export declare const DiscreteColorLegend: React.FC<colorLegendProps>;
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import * as React from "react";
2
11
  import { useRef } from "react";
3
12
  import legendUtil from "../Utils/discreteLegend";
@@ -14,60 +23,70 @@ export const DiscreteColorLegend = ({ discreteData, dataObjectName, position, co
14
23
  };
15
24
  }, [discreteData, colorName, colorTables, horizontal]);
16
25
  function discreteLegend() {
17
- const itemName = [];
18
- const itemColor = [];
19
- const colorsArray = colorTableData(colorName, colorTables);
20
- Object.keys(discreteData).forEach((key) => {
21
- // eslint-disable-next-line
22
- let code = discreteData[key][1];
23
- // compare the first value in colorarray(colortable) and code from discreteData
24
- const matchedColorsArrays = colorsArray.find((value) => {
25
- return value[0] == code;
26
- });
27
- if (matchedColorsArrays)
28
- itemColor.push({
29
- color: RGBToHex(matchedColorsArrays),
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const itemName = [];
28
+ const itemColor = [];
29
+ let dataSet;
30
+ if (typeof colorTables === "string") {
31
+ let res = yield fetch(colorTables);
32
+ dataSet = yield res.json();
33
+ }
34
+ let colorsArray = typeof colorTables === "string" ?
35
+ colorTableData(colorName, dataSet)
36
+ :
37
+ colorTableData(colorName, colorTables);
38
+ Object.keys(discreteData).forEach((key) => {
39
+ // eslint-disable-next-line
40
+ let code = discreteData[key][1];
41
+ // compare the first value in colorarray(colortable) and code from discreteData
42
+ const matchedColorsArrays = colorsArray.find((value) => {
43
+ return value[0] == code;
30
44
  });
31
- itemName.push(key);
45
+ if (matchedColorsArrays)
46
+ itemColor.push({
47
+ color: RGBToHex(matchedColorsArrays),
48
+ });
49
+ itemName.push(key);
50
+ });
51
+ function RGBToHex(rgb) {
52
+ let r = rgb[1].toString(16), g = rgb[2].toString(16), b = rgb[3].toString(16);
53
+ if (r.length == 1)
54
+ r = "0" + r;
55
+ if (g.length == 1)
56
+ g = "0" + g;
57
+ if (b.length == 1)
58
+ b = "0" + b;
59
+ return "#" + r + g + b;
60
+ }
61
+ const ordinalValues = scaleOrdinal().domain(itemName);
62
+ const colorLegend = legendUtil(itemColor).inputScale(ordinalValues);
63
+ const legendLength = itemColor.length;
64
+ const calcLegendHeight = 22 * legendLength + 4 * legendLength;
65
+ const selectedLegend = select(divRef.current);
66
+ selectedLegend
67
+ .append("div")
68
+ .text(dataObjectName)
69
+ .attr("y", 7)
70
+ .style("color", "#6F6F6F")
71
+ .style("margin", "10px 10px");
72
+ if (horizontal)
73
+ selectedLegend.style("height", 150 + "px");
74
+ const svgLegend = selectedLegend
75
+ .append("svg")
76
+ .style("margin", "10px 10px")
77
+ .call(colorLegend);
78
+ if (colorLegend && !horizontal) {
79
+ svgLegend
80
+ .attr("height", calcLegendHeight + "px")
81
+ .attr("width", 220 + "px");
82
+ }
83
+ else {
84
+ svgLegend
85
+ .style("transform", "rotate(90deg)")
86
+ .attr("width", calcLegendHeight + "px")
87
+ .attr("height", calcLegendHeight + "px");
88
+ }
32
89
  });
33
- function RGBToHex(rgb) {
34
- let r = rgb[1].toString(16), g = rgb[2].toString(16), b = rgb[3].toString(16);
35
- if (r.length == 1)
36
- r = "0" + r;
37
- if (g.length == 1)
38
- g = "0" + g;
39
- if (b.length == 1)
40
- b = "0" + b;
41
- return "#" + r + g + b;
42
- }
43
- const ordinalValues = scaleOrdinal().domain(itemName);
44
- const colorLegend = legendUtil(itemColor).inputScale(ordinalValues);
45
- const legendLength = itemColor.length;
46
- const calcLegendHeight = 22 * legendLength + 4 * legendLength;
47
- const selectedLegend = select(divRef.current);
48
- selectedLegend
49
- .append("div")
50
- .text(dataObjectName)
51
- .attr("y", 7)
52
- .style("color", "#6F6F6F")
53
- .style("margin", "10px 10px");
54
- if (horizontal)
55
- selectedLegend.style("height", 150 + "px");
56
- const svgLegend = selectedLegend
57
- .append("svg")
58
- .style("margin", "10px 10px")
59
- .call(colorLegend);
60
- if (colorLegend && !horizontal) {
61
- svgLegend
62
- .attr("height", calcLegendHeight + "px")
63
- .attr("width", 220 + "px");
64
- }
65
- else {
66
- svgLegend
67
- .style("transform", "rotate(90deg)")
68
- .attr("width", calcLegendHeight + "px")
69
- .attr("height", calcLegendHeight + "px");
70
- }
71
90
  }
72
91
  return (React.createElement("div", { style: {
73
92
  position: "absolute",
@@ -1 +1 @@
1
- {"version":3,"file":"DiscreteLegend.js","sourceRoot":"","sources":["../../../src/component/Legend/DiscreteLegend.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAgB1C,MAAM,CAAC,MAAM,mBAAmB,GAA+B,CAAC,EAC5D,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,SAAS,EACT,WAAW,EACX,UAAU,GACK,EAAE,EAAE;IACnB,MAAM,MAAM,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC5C,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,IAAI,MAAM,CAAC,OAAO,EAAE;YAChB,cAAc,EAAE,CAAC;SACpB;QACD,OAAO,SAAS,OAAO;YACnB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;YAC9C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QAClD,CAAC,CAAC;IACN,CAAC,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;IACvD,SAAS,cAAc;QACnB,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,MAAM,SAAS,GAAgB,EAAE,CAAC;QAClC,MAAM,WAAW,GAAuC,cAAc,CAClE,SAAS,EACT,WAAW,CACd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ACtB,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,SAAS,CAAC,WAAW,EAAE,CAC1D,CAAC;IACF,OAAO,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;AACrE,CAAC;AAED,mBAAmB,CAAC,YAAY,GAAG;IAC/B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;CACpB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emerson-eps/color-tables",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Standard library of color tables for geological domain",
5
5
  "release": {
6
6
  "branches": [
@@ -10,7 +10,7 @@ declare type legendProps = {
10
10
  dataObjectName: string;
11
11
  position?: number[] | null;
12
12
  colorName: string;
13
- colorTables: colorTablesArray;
13
+ colorTables: colorTablesArray | string;
14
14
  horizontal?: boolean | null;
15
15
  }
16
16
 
@@ -38,10 +38,19 @@ export const ContinuousLegend: React.FC<legendProps> = ({
38
38
  };
39
39
  }, [min, max, colorName, colorTables, horizontal]);
40
40
 
41
- function continuousLegend() {
41
+ async function continuousLegend() {
42
42
  const itemColor: ItemColor[] = [];
43
+ let dataSet;
44
+
45
+ if (typeof colorTables === "string") {
46
+ let res = await fetch(colorTables);
47
+ dataSet = await res.json()
48
+ }
43
49
  // Return the matched colors array from color.tables.json file
44
- const colorTableColors = colorsArray(colorName, colorTables);
50
+ let colorTableColors = typeof colorTables === "string" ?
51
+ colorsArray(colorName, dataSet)
52
+ :
53
+ colorsArray(colorName, colorTables);
45
54
  colorTableColors.forEach((value: [number, number, number, number]) => {
46
55
  // return the color and offset needed to draw the legend
47
56
  itemColor.push({
@@ -13,7 +13,7 @@ declare type colorLegendProps = {
13
13
  dataObjectName: string;
14
14
  position?: number[] | null;
15
15
  colorName: string;
16
- colorTables: colorTablesArray;
16
+ colorTables: colorTablesArray | string;
17
17
  horizontal?: boolean | null;
18
18
  }
19
19
 
@@ -35,13 +35,21 @@ export const DiscreteColorLegend: React.FC<colorLegendProps> = ({
35
35
  select(divRef.current).select("svg").remove();
36
36
  };
37
37
  }, [discreteData, colorName, colorTables, horizontal]);
38
- function discreteLegend() {
38
+ async function discreteLegend() {
39
39
  const itemName: string[] = [];
40
40
  const itemColor: ItemColor[] = [];
41
- const colorsArray: [number, number, number, number][] = colorTableData(
42
- colorName,
43
- colorTables
44
- );
41
+ let dataSet;
42
+
43
+ if (typeof colorTables === "string") {
44
+ let res = await fetch(colorTables);
45
+ dataSet = await res.json()
46
+ }
47
+
48
+ let colorsArray = typeof colorTables === "string" ?
49
+ colorTableData(colorName, dataSet)
50
+ :
51
+ colorTableData(colorName, colorTables);
52
+
45
53
  Object.keys(discreteData).forEach((key) => {
46
54
  // eslint-disable-next-line
47
55
  let code = (discreteData as { [key: string]: any })[key][1]