@emerson-eps/color-tables 1.0.0 → 1.0.1
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.
- package/dist/component/BreakPoint/Canvas.d.ts +3 -3
- package/dist/component/BreakPoint/Canvas.js +10 -21
- package/dist/component/BreakPoint/Canvas.js.map +1 -1
- package/dist/component/BreakPoint/ColorScale.d.ts +2 -3
- package/dist/component/BreakPoint/ColorScale.js +19 -20
- package/dist/component/BreakPoint/ColorScale.js.map +1 -1
- package/dist/component/BreakPoint/Legend.d.ts +2 -3
- package/dist/component/BreakPoint/Legend.js +31 -37
- package/dist/component/BreakPoint/Legend.js.map +1 -1
- package/dist/component/BreakPoint/Modal.d.ts +6 -3
- package/dist/component/BreakPoint/Modal.js +17 -21
- package/dist/component/BreakPoint/Modal.js.map +1 -1
- package/dist/component/BreakPoint/index.d.ts +4 -0
- package/dist/component/BreakPoint/index.js +6 -0
- package/dist/component/BreakPoint/index.js.map +1 -0
- package/dist/component/ColorSelector/BreakPointModule.d.ts +3 -4
- package/dist/component/ColorSelector/BreakPointModule.js +99 -140
- package/dist/component/ColorSelector/BreakPointModule.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorAccordion.js +55 -60
- package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +2 -3
- package/dist/component/ColorSelector/ColorSelectorComponent.js +83 -86
- package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorWrapper.d.ts +12 -5
- package/dist/component/ColorSelector/ColorSelectorWrapper.js +41 -51
- package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -1
- package/dist/component/ColorSelector/index.d.ts +4 -0
- package/dist/component/ColorSelector/index.js +6 -0
- package/dist/component/ColorSelector/index.js.map +1 -0
- package/dist/component/Legend/ColorLegend.d.ts +2 -2
- package/dist/component/Legend/ColorLegend.js +38 -39
- package/dist/component/Legend/ColorLegend.js.map +1 -1
- package/dist/component/Legend/ColorLegend.stories.js +20 -31
- package/dist/component/Legend/ColorLegend.stories.js.map +1 -1
- package/dist/component/Legend/ContinuousLegend.d.ts +2 -2
- package/dist/component/Legend/ContinuousLegend.js +230 -276
- package/dist/component/Legend/ContinuousLegend.js.map +1 -1
- package/dist/component/Legend/ContinuousLegend.stories.js +13 -24
- package/dist/component/Legend/ContinuousLegend.stories.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.d.ts +2 -2
- package/dist/component/Legend/DiscreteLegend.js +130 -180
- package/dist/component/Legend/DiscreteLegend.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.stories.js +15 -26
- package/dist/component/Legend/DiscreteLegend.stories.js.map +1 -1
- package/dist/component/Legend/constants.js +1 -1
- package/dist/component/Legend/constants.js.map +1 -1
- package/dist/component/Legend/index.d.ts +3 -0
- package/dist/component/Legend/index.js +4 -0
- package/dist/component/Legend/index.js.map +1 -0
- package/dist/component/Utils/d3ColorScale.js +1 -1
- package/dist/component/Utils/d3ColorScale.js.map +1 -1
- package/dist/component/Utils/discreteLegend.d.ts +2 -3
- package/dist/component/Utils/discreteLegend.js.map +1 -1
- package/dist/component/Utils/index.d.ts +2 -0
- package/dist/component/Utils/index.js +4 -0
- package/dist/component/Utils/index.js.map +1 -0
- package/dist/component/Utils/legendCommonFunction.d.ts +7 -7
- package/dist/component/Utils/legendCommonFunction.js +128 -139
- package/dist/component/Utils/legendCommonFunction.js.map +1 -1
- package/dist/component/Utils/legendCommonFunction.stories.js +14 -25
- package/dist/component/Utils/legendCommonFunction.stories.js.map +1 -1
- package/dist/component/colorTableTypes.d.ts +10 -2
- package/dist/component/index.d.ts +6 -0
- package/dist/component/index.js +7 -0
- package/dist/component/index.js.map +1 -0
- package/dist/index.d.ts +1 -9
- package/dist/index.js +1 -8
- package/dist/index.js.map +1 -1
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js +34 -0
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +1 -0
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js +34 -0
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +1 -0
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js +34 -0
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +1 -0
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js +36 -0
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +1 -0
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js +34 -0
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +1 -0
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js +34 -0
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +1 -0
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js +34 -0
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +1 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js +39 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js.map +1 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js +31 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js.map +1 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js +31 -0
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js.map +1 -0
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js +34 -0
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js.map +1 -0
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js +45 -0
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js.map +1 -0
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js +34 -0
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js.map +1 -0
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js +44 -0
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js.map +1 -0
- package/dist/stories/ColorLegends/LegendWithSelector/LegendSelector.stories.d.ts +7 -0
- package/dist/stories/ColorLegends/LegendWithSelector/LegendSelector.stories.js +33 -0
- package/dist/stories/ColorLegends/LegendWithSelector/LegendSelector.stories.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/component/Utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AAEvC,sCAAsC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ColorTableArray } from "../colorTableTypes";
|
|
2
2
|
type Color = [number, number, number];
|
|
3
|
-
export declare function colorsArray(colorName: string, iscolorTablesDefined:
|
|
3
|
+
export declare function colorsArray(colorName: string, iscolorTablesDefined: ColorTableArray | any): any;
|
|
4
4
|
export declare function RGBToHex(rgb: number[], max?: number): {
|
|
5
5
|
color: string;
|
|
6
6
|
offset: number;
|
|
@@ -10,17 +10,17 @@ export declare function HextoRGB(hex: string): {
|
|
|
10
10
|
g: number;
|
|
11
11
|
b: number;
|
|
12
12
|
};
|
|
13
|
-
export declare function getRgbData(point: number, colorName: string, iscolorTablesDefined:
|
|
13
|
+
export declare function getRgbData(point: number, colorName: string, iscolorTablesDefined: ColorTableArray | any, isLog?: boolean, isNearest?: boolean, userBreakPoint?: any): number[] | {
|
|
14
14
|
r: number;
|
|
15
15
|
g: number;
|
|
16
16
|
b: number;
|
|
17
17
|
opacity: number;
|
|
18
18
|
} | undefined;
|
|
19
19
|
export declare function getColors(colorName: string, iscolorTablesDefined: any, point: number): any;
|
|
20
|
-
export declare function rgbValues(point: number, colorName: string, iscolorTablesDefined:
|
|
21
|
-
export declare function sampledColor(colorScaleName: string, point: number, categorial?: boolean, min?: number, max?: number, iscolorTablesDefined?:
|
|
22
|
-
export declare function createColorMapFunction(colorScaleName: string, isLog: boolean, isNearest: boolean, breakPoints: number[]): (x: number, categorial?: boolean, min?: number, max?: number, iscolorTablesDefined?:
|
|
23
|
-
export declare function createContinuousLibraryColorScale(name: string, library?:
|
|
20
|
+
export declare function rgbValues(point: number, colorName: string, iscolorTablesDefined: ColorTableArray | any, isLog?: boolean, isNearest?: boolean, breakPoints?: any): Color;
|
|
21
|
+
export declare function sampledColor(colorScaleName: string, point: number, categorial?: boolean, min?: number, max?: number, iscolorTablesDefined?: ColorTableArray | any, isLog?: boolean, isNearest?: boolean, breakPoints?: number[]): [number, number, number, number] | Color;
|
|
22
|
+
export declare function createColorMapFunction(colorScaleName: string, isLog: boolean, isNearest: boolean, breakPoints: number[]): (x: number, categorial?: boolean, min?: number, max?: number, iscolorTablesDefined?: ColorTableArray | any) => [number, number, number, number] | Color;
|
|
23
|
+
export declare function createContinuousLibraryColorScale(name: string, library?: ColorTableArray): (value: number) => Color;
|
|
24
24
|
export declare function createDefaultContinuousColorScale(): (value: number) => Color;
|
|
25
25
|
export declare const getColorArrayFromBreakPoints: (breakpoints: number[], arraySize?: number) => string[];
|
|
26
26
|
export declare function getColorSelectorPosition(styles: any, isHorizontal: boolean, legendScaleSize: number): {
|
|
@@ -12,24 +12,22 @@ function getColor(rgb) {
|
|
|
12
12
|
}
|
|
13
13
|
// Based on objectName return the colors array from color.tables.json file
|
|
14
14
|
export function colorsArray(colorName, iscolorTablesDefined) {
|
|
15
|
-
|
|
15
|
+
const getColorTables = iscolorTablesDefined
|
|
16
16
|
? iscolorTablesDefined
|
|
17
17
|
: colorTables;
|
|
18
|
-
|
|
19
|
-
return value.name.toLowerCase() === colorName.toLowerCase();
|
|
20
|
-
});
|
|
18
|
+
const colorTableData = getColorTables.filter((value) => value.name.toLowerCase() === colorName.toLowerCase());
|
|
21
19
|
return colorTableData.length > 0 ? colorTableData[0].colors : [];
|
|
22
20
|
}
|
|
23
21
|
// return the hex color code and offset
|
|
24
22
|
export function RGBToHex(rgb, max) {
|
|
25
|
-
|
|
23
|
+
let r = Math.round(rgb[1]).toString(16), g = Math.round(rgb[2]).toString(16), b = Math.round(rgb[3]).toString(16);
|
|
26
24
|
if (r.length === 1)
|
|
27
25
|
r = "0" + r;
|
|
28
26
|
if (g.length === 1)
|
|
29
27
|
g = "0" + g;
|
|
30
28
|
if (b.length === 1)
|
|
31
29
|
b = "0" + b;
|
|
32
|
-
|
|
30
|
+
const offset = max ? ((rgb[0] - 0) / (max - 0)) * 100.0 : rgb[0] * 100.0;
|
|
33
31
|
return { color: "#" + r + g + b, offset: offset };
|
|
34
32
|
}
|
|
35
33
|
export function HextoRGB(hex) {
|
|
@@ -44,38 +42,38 @@ export function HextoRGB(hex) {
|
|
|
44
42
|
// return the colors based on the point
|
|
45
43
|
export function getRgbData(point, colorName, iscolorTablesDefined, isLog, isNearest, userBreakPoint) {
|
|
46
44
|
var _a, _b;
|
|
47
|
-
|
|
45
|
+
const getColorTables = iscolorTablesDefined
|
|
48
46
|
? iscolorTablesDefined
|
|
49
47
|
: colorTables;
|
|
50
48
|
// get colortable colorscale data
|
|
51
|
-
|
|
49
|
+
const getColorTableScale = getColorTables.find((value) => {
|
|
52
50
|
return value.name === colorName;
|
|
53
51
|
});
|
|
54
52
|
// get d3 colorscale data
|
|
55
|
-
|
|
53
|
+
const getD3Scale = d3ColorScales.find(function (value) {
|
|
56
54
|
return value.name === colorName;
|
|
57
55
|
});
|
|
58
|
-
|
|
56
|
+
let rgb;
|
|
59
57
|
// condition for logarithmic values
|
|
60
58
|
if (isLog) {
|
|
61
|
-
|
|
59
|
+
const log = scaleSymlog().domain([0, 1]);
|
|
62
60
|
point = log(point);
|
|
63
61
|
}
|
|
64
62
|
// colortable discrete scale
|
|
65
63
|
if ((getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.discrete) === true) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors.forEach(
|
|
64
|
+
const getSelectedScaleLength = getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors.length;
|
|
65
|
+
const minValue = 0;
|
|
66
|
+
const maxValue = getSelectedScaleLength - 1;
|
|
67
|
+
getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors.forEach((item, index) => {
|
|
70
68
|
var _a, _b, _c;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
const currentIndex = index;
|
|
70
|
+
const normalizedCurrentIndex = (currentIndex - minValue) / (maxValue - minValue);
|
|
71
|
+
const nextIndex = index + 1;
|
|
72
|
+
const normalizedNextIndex = (nextIndex - minValue) / (maxValue - 0);
|
|
75
73
|
//const t = (point - t0) / (t1 - t0); // t = 0.0 gives first color, t = 1.0 gives second color.
|
|
76
74
|
if (point >= normalizedCurrentIndex && point <= normalizedNextIndex) {
|
|
77
75
|
if ((item && (getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors[nextIndex])) !== undefined) {
|
|
78
|
-
|
|
76
|
+
const interpolate = interpolateRgb((_a = RGBToHex(item)) === null || _a === void 0 ? void 0 : _a.color, (_b = RGBToHex(getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors[nextIndex])) === null || _b === void 0 ? void 0 : _b.color)(point);
|
|
79
77
|
rgb = (_c = color(interpolate)) === null || _c === void 0 ? void 0 : _c.rgb();
|
|
80
78
|
}
|
|
81
79
|
}
|
|
@@ -83,43 +81,43 @@ export function getRgbData(point, colorName, iscolorTablesDefined, isLog, isNear
|
|
|
83
81
|
return rgb;
|
|
84
82
|
}
|
|
85
83
|
else if (typeof (getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors) == "function") {
|
|
86
|
-
|
|
84
|
+
const colorMappingRange = getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors(point);
|
|
87
85
|
return (rgb = getColor((_a = color(colorMappingRange)) === null || _a === void 0 ? void 0 : _a.rgb()));
|
|
88
86
|
}
|
|
89
87
|
else if (typeof (getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors) == "object") {
|
|
90
|
-
|
|
91
|
-
getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors.forEach(
|
|
88
|
+
const max = (getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors.length) - 1;
|
|
89
|
+
getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors.forEach((item, index) => {
|
|
92
90
|
var _a;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
const currentIndex = index;
|
|
92
|
+
const normalizedCurrentIndex = (currentIndex - 0) / (max - 0);
|
|
93
|
+
const nextIndex = index + 1;
|
|
94
|
+
const normalizedNextIndex = (nextIndex - 0) / (max - 0);
|
|
95
|
+
const indexableD3Scale = getD3Scale;
|
|
98
96
|
//const t = (point - t0) / (t1 - t0); // t = 0.0 gives first color, t = 1.0 gives second color.
|
|
99
97
|
if (point >= normalizedCurrentIndex && point <= normalizedNextIndex) {
|
|
100
|
-
|
|
98
|
+
const interpolate = interpolateRgb(item, indexableD3Scale[nextIndex])(point);
|
|
101
99
|
rgb = getColor((_a = color(interpolate)) === null || _a === void 0 ? void 0 : _a.rgb());
|
|
102
100
|
}
|
|
103
101
|
});
|
|
104
102
|
return rgb;
|
|
105
103
|
}
|
|
106
104
|
else {
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
let colorTableColors = colorsArray(colorName, getColorTables);
|
|
106
|
+
const itemColor = [];
|
|
109
107
|
if ((userBreakPoint === null || userBreakPoint === void 0 ? void 0 : userBreakPoint.length) > 0) {
|
|
110
|
-
userBreakPoint.forEach(
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
userBreakPoint.forEach((value) => {
|
|
109
|
+
const rgbColor = HextoRGB(value.color);
|
|
110
|
+
itemColor.push([value.position, rgbColor.r, rgbColor.g, rgbColor.b]);
|
|
113
111
|
});
|
|
114
|
-
|
|
112
|
+
itemColor === null || itemColor === void 0 ? void 0 : itemColor.sort((a, b) => {
|
|
115
113
|
if (a[0] === b[0])
|
|
116
114
|
return 0;
|
|
117
115
|
return a[0] < b[0] ? -1 : 1;
|
|
118
116
|
});
|
|
119
|
-
|
|
117
|
+
colorTableColors = itemColor;
|
|
120
118
|
}
|
|
121
119
|
// compare the point and first value from colorTableColors
|
|
122
|
-
|
|
120
|
+
const colorArrays = colorTableColors.find((value) => {
|
|
123
121
|
return point === value[0];
|
|
124
122
|
});
|
|
125
123
|
// if point and value in color table matches then return particular colors
|
|
@@ -128,35 +126,35 @@ export function getRgbData(point, colorName, iscolorTablesDefined, isLog, isNear
|
|
|
128
126
|
}
|
|
129
127
|
// if no match then need to do interpolation
|
|
130
128
|
else {
|
|
131
|
-
|
|
129
|
+
const nearestColor = [];
|
|
132
130
|
if (isNearest) {
|
|
133
|
-
|
|
134
|
-
if (
|
|
131
|
+
colorTableColors.forEach(function (val, index) {
|
|
132
|
+
if (colorTableColors[index + 1] &&
|
|
135
133
|
point > val[0] &&
|
|
136
|
-
point <
|
|
137
|
-
|
|
134
|
+
point < colorTableColors[index + 1][0]) {
|
|
135
|
+
const middle = (val[0] + colorTableColors[index + 1][0]) / 2;
|
|
138
136
|
if (point < middle) {
|
|
139
|
-
|
|
137
|
+
nearestColor.push(val[1], val[2], val[3]);
|
|
140
138
|
}
|
|
141
139
|
else {
|
|
142
|
-
|
|
140
|
+
nearestColor.push(colorTableColors[index + 1][1], colorTableColors[index + 1][2], colorTableColors[index + 1][3]);
|
|
143
141
|
}
|
|
144
142
|
}
|
|
145
143
|
});
|
|
146
|
-
return
|
|
144
|
+
return nearestColor;
|
|
147
145
|
}
|
|
148
146
|
else {
|
|
149
147
|
// Get index of first match of colortable point greater than point
|
|
150
|
-
|
|
148
|
+
const index = colorTableColors.findIndex((value) => {
|
|
151
149
|
return value[0] > point;
|
|
152
150
|
});
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
const firstColorArray = colorTableColors[index - 1];
|
|
152
|
+
const secondColorArray = colorTableColors[index];
|
|
155
153
|
if (firstColorArray && secondColorArray) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
154
|
+
const t0 = firstColorArray[0];
|
|
155
|
+
const t1 = secondColorArray[0];
|
|
156
|
+
const t = (point - t0) / (t1 - t0); // t = 0.0 gives first color, t = 1.0 gives second color.
|
|
157
|
+
const interpolatedValues = interpolateRgb(RGBToHex(firstColorArray).color, RGBToHex(secondColorArray).color)(t);
|
|
160
158
|
return (_b = color(interpolatedValues)) === null || _b === void 0 ? void 0 : _b.rgb();
|
|
161
159
|
}
|
|
162
160
|
}
|
|
@@ -166,13 +164,11 @@ export function getRgbData(point, colorName, iscolorTablesDefined, isLog, isNear
|
|
|
166
164
|
}
|
|
167
165
|
export function getColors(colorName, iscolorTablesDefined, point) {
|
|
168
166
|
var _a;
|
|
169
|
-
|
|
167
|
+
const getColorTables = iscolorTablesDefined
|
|
170
168
|
? iscolorTablesDefined
|
|
171
169
|
: colorTables;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
});
|
|
175
|
-
var colorArrays = (_a = colorTableData[0]) === null || _a === void 0 ? void 0 : _a.colors.find(function (value) {
|
|
170
|
+
const colorTableData = getColorTables.filter((value) => value.name.toLowerCase() === colorName.toLowerCase());
|
|
171
|
+
const colorArrays = (_a = colorTableData[0]) === null || _a === void 0 ? void 0 : _a.colors.find((value) => {
|
|
176
172
|
return value[0] === point;
|
|
177
173
|
});
|
|
178
174
|
return colorTableData.length > 0 ? colorArrays : [];
|
|
@@ -182,22 +178,22 @@ export function rgbValues(point, colorName, iscolorTablesDefined, isLog, isNeare
|
|
|
182
178
|
var _a;
|
|
183
179
|
// condition for logarithmic values
|
|
184
180
|
if (isLog) {
|
|
185
|
-
|
|
181
|
+
const log = scaleSymlog().domain([0, 1]);
|
|
186
182
|
point = log(point);
|
|
187
183
|
}
|
|
188
184
|
// check if the user has his own colortables else use default one
|
|
189
|
-
|
|
185
|
+
const getColorTables = iscolorTablesDefined
|
|
190
186
|
? iscolorTablesDefined
|
|
191
187
|
: colorTables;
|
|
192
188
|
// get the colors from the colortable for matching colorname
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
let colorTableColors = colorsArray(colorName, getColorTables);
|
|
190
|
+
const itemColor = [];
|
|
195
191
|
if ((breakPoints === null || breakPoints === void 0 ? void 0 : breakPoints.length) > 0) {
|
|
196
|
-
breakPoints.forEach(
|
|
197
|
-
|
|
192
|
+
breakPoints.forEach((value) => {
|
|
193
|
+
const rgbColor = HextoRGB(value.color);
|
|
198
194
|
itemColor.push([value.position, rgbColor.r, rgbColor.g, rgbColor.b]);
|
|
199
195
|
});
|
|
200
|
-
itemColor === null || itemColor === void 0 ? void 0 : itemColor.sort(
|
|
196
|
+
itemColor === null || itemColor === void 0 ? void 0 : itemColor.sort((a, b) => {
|
|
201
197
|
if (a[0] === b[0])
|
|
202
198
|
return 0;
|
|
203
199
|
return a[0] < b[0] ? -1 : 1;
|
|
@@ -205,7 +201,7 @@ export function rgbValues(point, colorName, iscolorTablesDefined, isLog, isNeare
|
|
|
205
201
|
colorTableColors = itemColor;
|
|
206
202
|
}
|
|
207
203
|
// compare the point and first value from colorTableColors
|
|
208
|
-
|
|
204
|
+
const colorArrays = colorTableColors.find((value) => {
|
|
209
205
|
return point === value[0];
|
|
210
206
|
});
|
|
211
207
|
// if point and value in color table matches then return particular colors
|
|
@@ -233,17 +229,17 @@ export function rgbValues(point, colorName, iscolorTablesDefined, isLog, isNeare
|
|
|
233
229
|
}
|
|
234
230
|
else {
|
|
235
231
|
// Get index of first match of colortable point greater than point
|
|
236
|
-
|
|
232
|
+
const index = colorTableColors.findIndex((value) => {
|
|
237
233
|
return value[0] > point;
|
|
238
234
|
});
|
|
239
|
-
|
|
240
|
-
|
|
235
|
+
const firstColorArray = colorTableColors[index - 1];
|
|
236
|
+
const secondColorArray = colorTableColors[index];
|
|
241
237
|
if (firstColorArray && secondColorArray) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
238
|
+
const t0 = firstColorArray[0];
|
|
239
|
+
const t1 = secondColorArray[0];
|
|
240
|
+
const t = (point - t0) / (t1 - t0); // t = 0.0 gives first color, t = 1.0 gives second color.
|
|
241
|
+
const interpolatedValues = interpolateRgb(RGBToHex(firstColorArray).color, RGBToHex(secondColorArray).color)(t);
|
|
242
|
+
const c = (_a = color(interpolatedValues)) === null || _a === void 0 ? void 0 : _a.rgb();
|
|
247
243
|
return getColor(c);
|
|
248
244
|
}
|
|
249
245
|
return undefined;
|
|
@@ -252,32 +248,32 @@ export function rgbValues(point, colorName, iscolorTablesDefined, isLog, isNeare
|
|
|
252
248
|
}
|
|
253
249
|
export function sampledColor(colorScaleName, point, categorial, min, max, iscolorTablesDefined, isLog, isNearest, breakPoints) {
|
|
254
250
|
var _a, _b;
|
|
255
|
-
|
|
251
|
+
const getColorTables = iscolorTablesDefined
|
|
256
252
|
? iscolorTablesDefined
|
|
257
253
|
: colorTables;
|
|
258
254
|
// get colortable colorscale data
|
|
259
|
-
|
|
255
|
+
const getColorTableScale = getColorTables.find((value) => {
|
|
260
256
|
return value.name === colorScaleName;
|
|
261
257
|
});
|
|
262
258
|
// get d3 colorscale data
|
|
263
|
-
|
|
259
|
+
const getD3Scale = d3ColorScales.find((value) => {
|
|
264
260
|
return value.name === colorScaleName;
|
|
265
261
|
});
|
|
266
262
|
// condition for logarithmic values
|
|
267
263
|
if (isLog) {
|
|
268
|
-
|
|
264
|
+
const log = scaleSymlog().domain([0, 1]);
|
|
269
265
|
point = log(point);
|
|
270
266
|
}
|
|
271
267
|
// return the color for matched point
|
|
272
268
|
// does interpolation for non-matching point
|
|
273
|
-
|
|
269
|
+
let rgb = rgbValues(point, colorScaleName, getColorTables, isLog, isNearest, breakPoints);
|
|
274
270
|
// colortable continuous scale
|
|
275
271
|
if ((getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.discrete) === false) {
|
|
276
272
|
// if log is discrete, then need to normalize
|
|
277
273
|
if (categorial) {
|
|
278
274
|
// condition added to resolve typescript error
|
|
279
275
|
//if (min && max) {
|
|
280
|
-
|
|
276
|
+
const normalizedPoint = (point - min) / (max - min);
|
|
281
277
|
rgb = rgbValues(normalizedPoint, colorScaleName, getColorTables, isLog, isNearest);
|
|
282
278
|
//}
|
|
283
279
|
}
|
|
@@ -287,10 +283,10 @@ export function sampledColor(colorScaleName, point, categorial, min, max, iscolo
|
|
|
287
283
|
}
|
|
288
284
|
// d3 continuous scale
|
|
289
285
|
if (typeof (getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors) == "function") {
|
|
290
|
-
|
|
286
|
+
let colorMappingRange = getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors(point);
|
|
291
287
|
// if log is discrete, then need to normalize
|
|
292
288
|
if (categorial) {
|
|
293
|
-
|
|
289
|
+
const normalizedPoint = (point - min) / (max - min);
|
|
294
290
|
colorMappingRange = getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors(normalizedPoint);
|
|
295
291
|
}
|
|
296
292
|
rgb = getColor((_a = color(colorMappingRange)) === null || _a === void 0 ? void 0 : _a.rgb());
|
|
@@ -299,26 +295,26 @@ export function sampledColor(colorScaleName, point, categorial, min, max, iscolo
|
|
|
299
295
|
if ((getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.discrete) === true) {
|
|
300
296
|
if (categorial) {
|
|
301
297
|
// compare the code and first value from colorsArray(colortable)
|
|
302
|
-
|
|
303
|
-
|
|
298
|
+
const arrayOfColors = colorsArray(colorScaleName, getColorTables);
|
|
299
|
+
const colorArrays = arrayOfColors.find((value) => {
|
|
304
300
|
return value[0] === point;
|
|
305
301
|
});
|
|
306
302
|
return colorArrays;
|
|
307
303
|
}
|
|
308
304
|
else {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors.forEach(
|
|
305
|
+
const getSelectedScaleLength = getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors.length;
|
|
306
|
+
const minValue = 0;
|
|
307
|
+
const maxValue = getSelectedScaleLength - 1;
|
|
308
|
+
getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors.forEach((item, index) => {
|
|
313
309
|
var _a, _b, _c;
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
310
|
+
const currentIndex = index;
|
|
311
|
+
const normalizedCurrentIndex = (currentIndex - minValue) / (maxValue - minValue);
|
|
312
|
+
const nextIndex = index + 1;
|
|
313
|
+
const normalizedNextIndex = (nextIndex - minValue) / (maxValue - 0);
|
|
318
314
|
//const t = (point - t0) / (t1 - t0); // t = 0.0 gives first color, t = 1.0 gives second color.
|
|
319
315
|
if (point >= normalizedCurrentIndex && point <= normalizedNextIndex) {
|
|
320
316
|
if ((item && (getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors[nextIndex])) !== undefined) {
|
|
321
|
-
|
|
317
|
+
const interpolate = interpolateRgb((_a = RGBToHex(item)) === null || _a === void 0 ? void 0 : _a.color, (_b = RGBToHex(getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.colors[nextIndex])) === null || _b === void 0 ? void 0 : _b.color)(point);
|
|
322
318
|
rgb = getColor((_c = color(interpolate)) === null || _c === void 0 ? void 0 : _c.rgb());
|
|
323
319
|
}
|
|
324
320
|
}
|
|
@@ -330,25 +326,25 @@ export function sampledColor(colorScaleName, point, categorial, min, max, iscolo
|
|
|
330
326
|
// discrete log
|
|
331
327
|
if (categorial) {
|
|
332
328
|
// const normalizedPoint = (point - min) / (max - min);
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return index ===
|
|
329
|
+
const code = point;
|
|
330
|
+
const d3ColorArrays = getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors.find((_value, index) => {
|
|
331
|
+
return index === code;
|
|
336
332
|
});
|
|
337
333
|
rgb = getColor((_b = color(d3ColorArrays)) === null || _b === void 0 ? void 0 : _b.rgb());
|
|
338
334
|
}
|
|
339
335
|
// continous log
|
|
340
336
|
else {
|
|
341
|
-
|
|
342
|
-
getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors.forEach(
|
|
337
|
+
const max = (getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors.length) - 1;
|
|
338
|
+
getD3Scale === null || getD3Scale === void 0 ? void 0 : getD3Scale.colors.forEach((item, index) => {
|
|
343
339
|
var _a;
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
340
|
+
const currentIndex = index;
|
|
341
|
+
const normalizedCurrentIndex = (currentIndex - 0) / (max - 0);
|
|
342
|
+
const nextIndex = index + 1;
|
|
343
|
+
const normalizedNextIndex = (nextIndex - 0) / (max - 0);
|
|
344
|
+
const indexableD3Scale = getD3Scale;
|
|
349
345
|
//const t = (point - t0) / (t1 - t0); // t = 0.0 gives first color, t = 1.0 gives second color.
|
|
350
346
|
if (point >= normalizedCurrentIndex && point <= normalizedNextIndex) {
|
|
351
|
-
|
|
347
|
+
const interpolate = interpolateRgb(item, indexableD3Scale[nextIndex])(point);
|
|
352
348
|
rgb = getColor((_a = color(interpolate)) === null || _a === void 0 ? void 0 : _a.rgb());
|
|
353
349
|
}
|
|
354
350
|
});
|
|
@@ -357,32 +353,26 @@ export function sampledColor(colorScaleName, point, categorial, min, max, iscolo
|
|
|
357
353
|
return rgb;
|
|
358
354
|
}
|
|
359
355
|
export function createColorMapFunction(colorScaleName, isLog, isNearest, breakPoints) {
|
|
360
|
-
return
|
|
361
|
-
if (categorial === void 0) { categorial = false; }
|
|
362
|
-
if (min === void 0) { min = 0; }
|
|
363
|
-
if (max === void 0) { max = 1; }
|
|
364
|
-
if (iscolorTablesDefined === void 0) { iscolorTablesDefined = colorTables; }
|
|
356
|
+
return (x, categorial = false, min = 0, max = 1, iscolorTablesDefined = colorTables) => {
|
|
365
357
|
return sampledColor(colorScaleName, x, categorial, min, max, iscolorTablesDefined, isLog, isNearest, breakPoints);
|
|
366
358
|
};
|
|
367
359
|
}
|
|
368
|
-
export function createContinuousLibraryColorScale(name, library) {
|
|
369
|
-
|
|
370
|
-
return function (value) {
|
|
360
|
+
export function createContinuousLibraryColorScale(name, library = colorTables) {
|
|
361
|
+
return (value) => {
|
|
371
362
|
return rgbValues(value, name, library);
|
|
372
363
|
};
|
|
373
364
|
}
|
|
374
365
|
export function createDefaultContinuousColorScale() {
|
|
375
366
|
return createContinuousLibraryColorScale("Rainbow");
|
|
376
367
|
}
|
|
377
|
-
export
|
|
378
|
-
if (arraySize === void 0) { arraySize = 512; }
|
|
368
|
+
export const getColorArrayFromBreakPoints = (breakpoints, arraySize = 512) => {
|
|
379
369
|
if (breakpoints.length === 0) {
|
|
380
370
|
throw new Error("Couldn't provide color supplier from empty color array");
|
|
381
371
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
return range(0, arraySize).map(
|
|
372
|
+
const colors = breakpoints.map((item) => item.color);
|
|
373
|
+
const ratios = breakpoints.map((item) => item.position);
|
|
374
|
+
let position = 0;
|
|
375
|
+
return range(0, arraySize).map((i) => {
|
|
386
376
|
var _a;
|
|
387
377
|
if (ratios[position] < i / (arraySize - 1)) {
|
|
388
378
|
position++;
|
|
@@ -393,19 +383,18 @@ export var getColorArrayFromBreakPoints = function (breakpoints, arraySize) {
|
|
|
393
383
|
if (position === ratios.length) {
|
|
394
384
|
return colors[colors.length - 1];
|
|
395
385
|
}
|
|
396
|
-
|
|
386
|
+
const color = d3.interpolateRgb(colors[position - 1], colors[position]);
|
|
397
387
|
return (_a = d3
|
|
398
388
|
.color(color((i / arraySize - ratios[position - 1]) /
|
|
399
389
|
(ratios[position] - ratios[position - 1])))) === null || _a === void 0 ? void 0 : _a.formatHex();
|
|
400
390
|
});
|
|
401
391
|
};
|
|
402
|
-
export function getColorSelectorPosition(styles, isHorizontal, legendScaleSize) {
|
|
403
|
-
if (styles === void 0) { styles = { top: "0vh", left: "0vw" }; }
|
|
392
|
+
export function getColorSelectorPosition(styles = { top: "0vh", left: "0vw" }, isHorizontal, legendScaleSize) {
|
|
404
393
|
// when horizontal, the legend dimentions are: width = legendWidth & height = 80px
|
|
405
394
|
// when vertical, the legend dimentions are: height = legendWidth & width = 80px
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
395
|
+
const legendWidth = isHorizontal ? legendScaleSize + "px" : "100px";
|
|
396
|
+
const legendHeight = isHorizontal ? "100px" : legendScaleSize + "px";
|
|
397
|
+
const accordionPosition = { left: "", top: "", right: "", bottom: "" };
|
|
409
398
|
// when any of the styles positions is zero, convert to string so that it can pass the conditions afteron
|
|
410
399
|
styles.left = styles.left == 0 ? "0px" : styles.left;
|
|
411
400
|
styles.right = styles.right == 0 ? "0px" : styles.right;
|
|
@@ -415,37 +404,37 @@ export function getColorSelectorPosition(styles, isHorizontal, legendScaleSize)
|
|
|
415
404
|
if (styles.left && styles.top) {
|
|
416
405
|
accordionPosition.left = isHorizontal
|
|
417
406
|
? styles.left
|
|
418
|
-
:
|
|
407
|
+
: `calc(${styles.left} + ${legendWidth})`;
|
|
419
408
|
accordionPosition.top = isHorizontal
|
|
420
|
-
?
|
|
409
|
+
? `calc(${styles.top} + ${legendHeight})`
|
|
421
410
|
: styles.top;
|
|
422
411
|
}
|
|
423
412
|
else if (styles.left && styles.bottom) {
|
|
424
413
|
/* When legend is close to bottom-left corner */
|
|
425
414
|
accordionPosition.left = isHorizontal
|
|
426
415
|
? styles.left
|
|
427
|
-
:
|
|
416
|
+
: `calc(${styles.left} + ${legendWidth})`;
|
|
428
417
|
accordionPosition.bottom = isHorizontal
|
|
429
|
-
?
|
|
418
|
+
? `calc(${styles.bottom} + ${legendHeight})`
|
|
430
419
|
: styles.bottom;
|
|
431
420
|
}
|
|
432
421
|
else if (styles.top && styles.right) {
|
|
433
422
|
/* When the legend is close to the top-right corner */
|
|
434
423
|
accordionPosition.right = isHorizontal
|
|
435
424
|
? styles.right
|
|
436
|
-
:
|
|
425
|
+
: `calc(${styles.right} + ${legendWidth})`;
|
|
437
426
|
accordionPosition.top = isHorizontal
|
|
438
|
-
?
|
|
427
|
+
? `calc(${styles.top} + ${legendHeight})`
|
|
439
428
|
: styles.top;
|
|
440
429
|
}
|
|
441
430
|
else if (styles.bottom && styles.right) {
|
|
442
431
|
/* When the legend is close to the bottom-right corner */
|
|
443
432
|
accordionPosition.bottom = isHorizontal
|
|
444
|
-
?
|
|
433
|
+
? `calc(${styles.bottom} + ${legendHeight})`
|
|
445
434
|
: styles.bottom;
|
|
446
435
|
accordionPosition.right = isHorizontal
|
|
447
436
|
? styles.right
|
|
448
|
-
:
|
|
437
|
+
: `calc(${styles.right} + ${legendWidth})`;
|
|
449
438
|
}
|
|
450
439
|
else if (
|
|
451
440
|
/* Set a default */
|
|
@@ -457,9 +446,9 @@ export function getColorSelectorPosition(styles, isHorizontal, legendScaleSize)
|
|
|
457
446
|
styles.top = "0px";
|
|
458
447
|
accordionPosition.left = isHorizontal
|
|
459
448
|
? styles.left
|
|
460
|
-
:
|
|
449
|
+
: `calc(${styles.left} + ${legendWidth})`;
|
|
461
450
|
accordionPosition.top = isHorizontal
|
|
462
|
-
?
|
|
451
|
+
? `calc(${styles.top} + ${legendHeight})`
|
|
463
452
|
: styles.top;
|
|
464
453
|
}
|
|
465
454
|
return accordionPosition;
|
|
@@ -472,13 +461,13 @@ export function getTickValues(range, numberOfTicks) {
|
|
|
472
461
|
if (numberOfTicks < 1 || !numberOfTicks) {
|
|
473
462
|
return [];
|
|
474
463
|
}
|
|
475
|
-
|
|
476
|
-
|
|
464
|
+
const min = range[0];
|
|
465
|
+
const max = range[1];
|
|
477
466
|
numberOfTicks = Math.floor(numberOfTicks);
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
for (
|
|
481
|
-
|
|
467
|
+
const step = (max - min) / (numberOfTicks + 1);
|
|
468
|
+
const ticksArray = [];
|
|
469
|
+
for (let i = 1; i <= numberOfTicks; i++) {
|
|
470
|
+
let currentTickValue = step * i + min;
|
|
482
471
|
currentTickValue = Math.round(currentTickValue * 100) / 100;
|
|
483
472
|
ticksArray.push(currentTickValue);
|
|
484
473
|
}
|