@emerson-eps/color-tables 1.0.13 → 1.0.14
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.js +3 -15
- package/dist/component/BreakPoint/Canvas.js.map +1 -1
- package/dist/component/BreakPoint/ColorScale.js +1 -1
- package/dist/component/BreakPoint/ColorScale.js.map +1 -1
- package/dist/component/BreakPoint/index.d.ts +1 -1
- package/dist/component/BreakPoint/index.js.map +1 -1
- package/dist/component/ColorSelector/BreakPointModule.js +11 -4
- package/dist/component/ColorSelector/BreakPointModule.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorAccordion.js +10 -11
- package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorComponent.js +4 -5
- package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorWrapper.js +13 -13
- package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -1
- package/dist/component/ColorSelector/index.d.ts +1 -1
- package/dist/component/Legend/ColorLegend.js +7 -9
- package/dist/component/Legend/ColorLegend.js.map +1 -1
- package/dist/component/Legend/ColorLegend.stories.d.ts +13 -14
- package/dist/component/Legend/ColorLegend.stories.js +85 -32
- package/dist/component/Legend/ColorLegend.stories.js.map +1 -1
- package/dist/component/Legend/ContinuousLegend.js +221 -229
- package/dist/component/Legend/ContinuousLegend.js.map +1 -1
- package/dist/component/Legend/ContinuousLegend.stories.d.ts +15 -10
- package/dist/component/Legend/ContinuousLegend.stories.js +147 -18
- package/dist/component/Legend/ContinuousLegend.stories.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.js +129 -133
- package/dist/component/Legend/DiscreteLegend.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.stories.d.ts +14 -9
- package/dist/component/Legend/DiscreteLegend.stories.js +178 -16
- package/dist/component/Legend/DiscreteLegend.stories.js.map +1 -1
- package/dist/component/Utils/Utils.stories.d.ts +7 -0
- package/dist/component/Utils/Utils.stories.js +41 -0
- package/dist/component/Utils/Utils.stories.js.map +1 -0
- package/dist/component/Utils/legendCommonFunction.js +40 -48
- package/dist/component/Utils/legendCommonFunction.js.map +1 -1
- package/package.json +10 -15
- package/dist/component/Utils/legendCommonFunction.stories.d.ts +0 -8
- package/dist/component/Utils/legendCommonFunction.stories.js +0 -35
- package/dist/component/Utils/legendCommonFunction.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js +0 -34
- package/dist/stories/ColorLegends/ContinousLegends/MD.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js +0 -34
- package/dist/stories/ColorLegends/ContinousLegends/NTG.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js +0 -34
- package/dist/stories/ColorLegends/ContinousLegends/PermTot.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js +0 -36
- package/dist/stories/ColorLegends/ContinousLegends/Permeability.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js +0 -34
- package/dist/stories/ColorLegends/ContinousLegends/PoroTot.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js +0 -34
- package/dist/stories/ColorLegends/ContinousLegends/Porosity.stories.js.map +0 -1
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js +0 -34
- package/dist/stories/ColorLegends/ContinousLegends/SW.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js +0 -39
- package/dist/stories/ColorLegends/DiscreteLegends/FaciesNoCalcite.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js +0 -31
- package/dist/stories/ColorLegends/DiscreteLegends/FaultDistanceHum.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js +0 -31
- package/dist/stories/ColorLegends/DiscreteLegends/FaultProximityFlag.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js +0 -34
- package/dist/stories/ColorLegends/DiscreteLegends/RDE.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js +0 -45
- package/dist/stories/ColorLegends/DiscreteLegends/RDE_Orig.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js +0 -34
- package/dist/stories/ColorLegends/DiscreteLegends/ZoneMain.stories.js.map +0 -1
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js +0 -44
- package/dist/stories/ColorLegends/DiscreteLegends/Zonelog.stories.js.map +0 -1
- package/dist/stories/ColorLegends/LegendWithSelector/LegendSelector.stories.d.ts +0 -7
- package/dist/stories/ColorLegends/LegendWithSelector/LegendSelector.stories.js +0 -33
- package/dist/stories/ColorLegends/LegendWithSelector/LegendSelector.stories.js.map +0 -1
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { colorTables } from "..";
|
|
3
|
+
import { ColorLegend } from ".";
|
|
4
|
+
// storybook page
|
|
5
|
+
const meta = {
|
|
5
6
|
title: "Legends/ColorLegend",
|
|
7
|
+
component: ColorLegend,
|
|
8
|
+
decorators: [
|
|
9
|
+
(Story) => {
|
|
10
|
+
return React.createElement(Story, null);
|
|
11
|
+
},
|
|
12
|
+
],
|
|
6
13
|
};
|
|
7
|
-
|
|
8
|
-
const [getColor, setColorName] = React.useState("Rainbow");
|
|
9
|
-
const getColorName = React.useCallback((data) => {
|
|
10
|
-
// for geological color scale data (from color-table.json) => data.name
|
|
11
|
-
// for D3 color scale => data.legendColorName
|
|
12
|
-
setColorName((data === null || data === void 0 ? void 0 : data.name) || (data === null || data === void 0 ? void 0 : data.legendColorName));
|
|
13
|
-
}, []);
|
|
14
|
-
return React.createElement(ColorLegend, Object.assign({}, args, { colorName: getColor, getScale: getColorName }));
|
|
15
|
-
};
|
|
14
|
+
export default meta;
|
|
16
15
|
const defaultProps = {
|
|
17
16
|
horizontal: true,
|
|
18
17
|
isOpenProp: true,
|
|
@@ -27,24 +26,78 @@ const defaultProps = {
|
|
|
27
26
|
numberOfTicks: 3,
|
|
28
27
|
legendScaleSize: 300,
|
|
29
28
|
};
|
|
30
|
-
export const DefaultStyle =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
29
|
+
export const DefaultStyle = {
|
|
30
|
+
args: {
|
|
31
|
+
...defaultProps,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export const TopLeftPosition = {
|
|
35
|
+
args: {
|
|
36
|
+
...defaultProps,
|
|
37
|
+
cssLegendStyles: { left: "0vw", top: "0vh" },
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export const TopRightPosition = {
|
|
41
|
+
args: {
|
|
42
|
+
...defaultProps,
|
|
43
|
+
cssLegendStyles: { right: "2vw", top: "0vh" },
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
export const VerticalPositioning = {
|
|
47
|
+
args: {
|
|
48
|
+
...defaultProps,
|
|
49
|
+
cssLegendStyles: { right: "0vw", top: "0vh" },
|
|
50
|
+
horizontal: false,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
export const BottomRightPosition = {
|
|
54
|
+
args: {
|
|
55
|
+
...defaultProps,
|
|
56
|
+
cssLegendStyles: { right: "2vw", bottom: "0vh" },
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
export const BottomLeftPosition = {
|
|
60
|
+
args: {
|
|
61
|
+
...defaultProps,
|
|
62
|
+
cssLegendStyles: { left: "0vw", bottom: "0vh" },
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
export const BackgroundColor = {
|
|
66
|
+
args: {
|
|
67
|
+
...defaultProps,
|
|
68
|
+
cssLegendStyles: {
|
|
69
|
+
backgroundColor: "red",
|
|
70
|
+
borderRadius: "5px",
|
|
71
|
+
padding: "5px",
|
|
72
|
+
},
|
|
73
|
+
horizontal: false,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const ColorSelector = (props) => {
|
|
77
|
+
const [color, setColor] = React.useState("Rainbow");
|
|
78
|
+
const getColorName = React.useCallback((data) => {
|
|
79
|
+
// for geological color scale data (from color-table.json) => data.name
|
|
80
|
+
// for D3 color scale => data.legendColorName
|
|
81
|
+
setColor(data?.name || data?.legendColorName);
|
|
82
|
+
}, []);
|
|
83
|
+
return React.createElement(ColorLegend, { ...props, colorName: color, getScale: getColorName });
|
|
84
|
+
};
|
|
85
|
+
export const LegendWithColorSelector = {
|
|
86
|
+
args: {
|
|
87
|
+
min: 0,
|
|
88
|
+
max: 0.35,
|
|
89
|
+
cssLegendStyles: { left: "0vw", top: "0vh" },
|
|
90
|
+
horizontal: true,
|
|
91
|
+
colorName: "Rainbow",
|
|
92
|
+
dataObjectName: "Legend with Selector",
|
|
93
|
+
colorTables,
|
|
94
|
+
isModal: true,
|
|
95
|
+
isRangeShown: true,
|
|
96
|
+
legendFontSize: 13,
|
|
97
|
+
tickFontSize: 13,
|
|
98
|
+
numberOfTicks: 3,
|
|
99
|
+
legendScaleSize: 300,
|
|
100
|
+
},
|
|
101
|
+
render: (args) => React.createElement(ColorSelector, { ...args }),
|
|
102
|
+
};
|
|
50
103
|
//# sourceMappingURL=ColorLegend.stories.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorLegend.stories.js","sourceRoot":"","sources":["../../../src/component/Legend/ColorLegend.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ColorLegend.stories.js","sourceRoot":"","sources":["../../../src/component/Legend/ColorLegend.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,EAAyB,WAAW,EAAqB,MAAM,GAAG,CAAC;AAE1E,iBAAiB;AACjB,MAAM,IAAI,GAA6B;IACrC,KAAK,EAAE,qBAAqB;IAC5B,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE;QACV,CAAC,KAAK,EAAE,EAAE;YACR,OAAO,oBAAC,KAAK,OAAG,CAAC;QACnB,CAAC;KACF;CACF,CAAC;AACF,eAAe,IAAI,CAAC;AAI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|
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
|
-
};
|
|
10
1
|
import * as React from "react";
|
|
11
2
|
import { useRef } from "react";
|
|
12
|
-
import { select, scaleLinear, scaleSymlog, axisBottom, axisRight } from "d3";
|
|
3
|
+
import { range, select, scaleLinear, scaleSymlog, axisBottom, axisRight, } from "d3";
|
|
13
4
|
import { color } from "d3-color";
|
|
14
|
-
import { range } from "d3";
|
|
15
5
|
import { d3ColorScales } from "../Utils/d3ColorScale";
|
|
16
6
|
import { RGBToHex, colorsArray, getTickValues, } from "../Utils/legendCommonFunction";
|
|
17
|
-
import defaultColorTables from "
|
|
7
|
+
import { colorTables as defaultColorTables } from "..";
|
|
18
8
|
import { DEFAULT_STYLE } from "./constants";
|
|
19
9
|
export const ContinuousLegend = ({ min, max, dataObjectName, colorName = "Rainbow", horizontal, getColorScaleData, id, colorTables = defaultColorTables, colorMapFunction, reverseRange = false, breakPoint, editedBreakPointValues, isLog, isNearest, isRangeShown = true, legendFontSize = 18, tickFontSize = 12, numberOfTicks = 3, legendScaleSize = 200, cssLegendStyles = DEFAULT_STYLE, }) => {
|
|
20
10
|
const generateUniqueId = Math.ceil(Math.random() * 9999).toString();
|
|
@@ -25,235 +15,231 @@ export const ContinuousLegend = ({ min, max, dataObjectName, colorName = "Rainbo
|
|
|
25
15
|
select(divRef.current).select("svg").remove();
|
|
26
16
|
continuousLegend();
|
|
27
17
|
}
|
|
28
|
-
function continuousLegend() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
18
|
+
async function continuousLegend() {
|
|
19
|
+
let itemColor = [];
|
|
20
|
+
let parsedColorTables;
|
|
21
|
+
try {
|
|
22
|
+
// fix for dash wrapper
|
|
23
|
+
if (typeof colorTables === "string") {
|
|
24
|
+
const res = await fetch(colorTables);
|
|
25
|
+
parsedColorTables = await res.json();
|
|
26
|
+
}
|
|
27
|
+
//Return the matched colors array from color.tables.json file
|
|
28
|
+
let legendColors = typeof colorTables === "string"
|
|
29
|
+
? colorsArray(colorName, parsedColorTables)
|
|
30
|
+
: colorsArray(colorName, colorTables);
|
|
31
|
+
const nearestData = [];
|
|
32
|
+
// Update color of legend based on color selector scales
|
|
33
|
+
// data is passed on click upon color scales
|
|
34
|
+
if (getColorScaleData && Object.keys(getColorScaleData).length > 0) {
|
|
35
|
+
// legend using color table data
|
|
36
|
+
if (getColorScaleData.color) {
|
|
37
|
+
legendColors = getColorScaleData.color;
|
|
38
38
|
}
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
: colorsArray(colorName, colorTables);
|
|
43
|
-
const nearestData = [];
|
|
44
|
-
// Update color of legend based on color selector scales
|
|
45
|
-
// data is passed on click upon color scales
|
|
46
|
-
if (getColorScaleData && Object.keys(getColorScaleData).length > 0) {
|
|
47
|
-
// legend using color table data
|
|
48
|
-
if (getColorScaleData.color) {
|
|
49
|
-
legendColors = getColorScaleData.color;
|
|
50
|
-
}
|
|
51
|
-
// legend using d3 data
|
|
52
|
-
else if (getColorScaleData.arrayData) {
|
|
53
|
-
legendColors = getColorScaleData.arrayData;
|
|
54
|
-
}
|
|
39
|
+
// legend using d3 data
|
|
40
|
+
else if (getColorScaleData.arrayData) {
|
|
41
|
+
legendColors = getColorScaleData.arrayData;
|
|
55
42
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
73
|
-
legendColors = arrayData;
|
|
74
|
-
}
|
|
75
|
-
// condition to check if the legend is selected from color selector or not
|
|
76
|
-
const getColorTableScale = (_a = (typeof colorTables === "string" ? parsedColorTables : colorTables)) === null || _a === void 0 ? void 0 : _a.find((value) => {
|
|
77
|
-
if (getColorScaleData) {
|
|
78
|
-
return value.name === (getColorScaleData === null || getColorScaleData === void 0 ? void 0 : getColorScaleData.name);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
return value.name === colorName;
|
|
82
|
-
}
|
|
43
|
+
}
|
|
44
|
+
const isD3Colors = d3ColorScales.find((value) => {
|
|
45
|
+
return value?.name === colorName;
|
|
46
|
+
});
|
|
47
|
+
// main continuous legend for d3 colors
|
|
48
|
+
if (isD3Colors && isD3Colors.discrete === false) {
|
|
49
|
+
const arrayData = [];
|
|
50
|
+
const d3ColorArrays = colorsArray(colorName, d3ColorScales);
|
|
51
|
+
const data = range(10).map((d) => ({ color: d3ColorArrays(d / 10) }));
|
|
52
|
+
data.forEach((colorsObject, index) => {
|
|
53
|
+
arrayData.push([
|
|
54
|
+
0 + "." + index,
|
|
55
|
+
color(colorsObject.color)?.rgb().r,
|
|
56
|
+
color(colorsObject.color)?.rgb().g,
|
|
57
|
+
color(colorsObject.color)?.rgb().b,
|
|
58
|
+
]);
|
|
83
59
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
let rightEnd = 0 + delta;
|
|
91
|
-
legendColors.forEach((val) => {
|
|
92
|
-
nearestData.push({
|
|
93
|
-
breakPoint: Number(leftEnd.toFixed(2)),
|
|
94
|
-
color: RGBToHex([val[0], val[1], val[2], val[3]]).color,
|
|
95
|
-
}, {
|
|
96
|
-
breakPoint: Number(rightEnd.toFixed(2)),
|
|
97
|
-
color: RGBToHex([val[0], val[1], val[2], val[3]]).color,
|
|
98
|
-
});
|
|
99
|
-
leftEnd += delta;
|
|
100
|
-
rightEnd += delta;
|
|
101
|
-
});
|
|
60
|
+
legendColors = arrayData;
|
|
61
|
+
}
|
|
62
|
+
// condition to check if the legend is selected from color selector or not
|
|
63
|
+
const getColorTableScale = (typeof colorTables === "string" ? parsedColorTables : colorTables)?.find((value) => {
|
|
64
|
+
if (getColorScaleData) {
|
|
65
|
+
return value.name === getColorScaleData?.name;
|
|
102
66
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const rgbValue = [];
|
|
106
|
-
for (var i = 0; i <= 1; i += 0.05) {
|
|
107
|
-
const value = colorMapFunction(i);
|
|
108
|
-
rgbValue.push([i.toFixed(2), value[0], value[1], value[2]]);
|
|
109
|
-
}
|
|
110
|
-
legendColors = rgbValue;
|
|
67
|
+
else {
|
|
68
|
+
return value.name === colorName;
|
|
111
69
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
breakPoint: (getColorTableScale === null || getColorTableScale === void 0 ? void 0 : getColorTableScale.discrete) === true
|
|
128
|
-
? RGBToHex(value, maxValue).offset
|
|
129
|
-
: (breakPoint === null || breakPoint === void 0 ? void 0 : breakPoint.length) > 0
|
|
130
|
-
? domainIndex * 100.0
|
|
131
|
-
: value[0] * 100.0,
|
|
132
|
-
color: RGBToHex(value).color,
|
|
70
|
+
});
|
|
71
|
+
const maxValue = legendColors.length - 1;
|
|
72
|
+
// condition for nearest interpolation
|
|
73
|
+
if (isNearest) {
|
|
74
|
+
const nColors = legendColors.length;
|
|
75
|
+
const delta = 1 / nColors;
|
|
76
|
+
let leftEnd = 0;
|
|
77
|
+
let rightEnd = 0 + delta;
|
|
78
|
+
legendColors.forEach((val) => {
|
|
79
|
+
nearestData.push({
|
|
80
|
+
breakPoint: Number(leftEnd.toFixed(2)),
|
|
81
|
+
color: RGBToHex([val[0], val[1], val[2], val[3]]).color,
|
|
82
|
+
}, {
|
|
83
|
+
breakPoint: Number(rightEnd.toFixed(2)),
|
|
84
|
+
color: RGBToHex([val[0], val[1], val[2], val[3]]).color,
|
|
133
85
|
});
|
|
86
|
+
leftEnd += delta;
|
|
87
|
+
rightEnd += delta;
|
|
134
88
|
});
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
(
|
|
142
|
-
const options = editedBreakPointValues.colorArray.map(function (row) {
|
|
143
|
-
return { breakPoint: row.position * 100.0, color: row.color };
|
|
144
|
-
});
|
|
145
|
-
itemColor = options;
|
|
89
|
+
}
|
|
90
|
+
// if colorMapFunction prop is passed
|
|
91
|
+
if (colorMapFunction) {
|
|
92
|
+
const rgbValue = [];
|
|
93
|
+
for (var i = 0; i <= 1; i += 0.05) {
|
|
94
|
+
const value = colorMapFunction(i);
|
|
95
|
+
rgbValue.push([i.toFixed(2), value[0], value[1], value[2]]);
|
|
146
96
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.style("border-radius", "5px");
|
|
158
|
-
const defs = svgLegend.append("defs");
|
|
159
|
-
svgLegend
|
|
160
|
-
.attr("width", horizontal ? (legendScaleSize < 200 ? 200 : legendScaleSize) : "100")
|
|
161
|
-
.attr("height", horizontal
|
|
162
|
-
? "70"
|
|
163
|
-
: legendScaleSize < 200
|
|
164
|
-
? 200
|
|
165
|
-
: legendScaleSize - 17);
|
|
166
|
-
const currentIndex = "linear-gradient-" + id + "0";
|
|
167
|
-
const linearGradient = defs
|
|
168
|
-
.append("linearGradient")
|
|
169
|
-
.attr("id", currentIndex);
|
|
170
|
-
// append a linearGradient element to the defs and give it a unique id
|
|
171
|
-
if ((horizontal && !reverseRange) || (!horizontal && reverseRange)) {
|
|
172
|
-
linearGradient
|
|
173
|
-
.attr("x1", "0%")
|
|
174
|
-
.attr("x2", horizontal ? "100%" : "0%")
|
|
175
|
-
.attr("y1", "0%")
|
|
176
|
-
.attr("y2", horizontal ? "0%" : "100%");
|
|
97
|
+
legendColors = rgbValue;
|
|
98
|
+
}
|
|
99
|
+
const arrOfNum = breakPoint?.map((str) => {
|
|
100
|
+
return Number(str);
|
|
101
|
+
});
|
|
102
|
+
const userDefinedDomain = arrOfNum ? arrOfNum : [];
|
|
103
|
+
legendColors.forEach((value, index) => {
|
|
104
|
+
let domainIndex;
|
|
105
|
+
if (userDefinedDomain[index]) {
|
|
106
|
+
domainIndex = userDefinedDomain[index];
|
|
177
107
|
}
|
|
178
|
-
else
|
|
179
|
-
|
|
180
|
-
linearGradient
|
|
181
|
-
.attr("x1", horizontal ? "100%" : "0%")
|
|
182
|
-
.attr("x2", "0%")
|
|
183
|
-
.attr("y1", horizontal ? "0%" : "100%")
|
|
184
|
-
.attr("y2", "0%");
|
|
108
|
+
else {
|
|
109
|
+
domainIndex = value[0];
|
|
185
110
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
? colorScale(data.breakPoint) / 4 + "%"
|
|
196
|
-
: data.breakPoint + "%";
|
|
197
|
-
})
|
|
198
|
-
.attr("stop-color", function (data) {
|
|
199
|
-
return data.color;
|
|
111
|
+
// return the color and breakPoint needed to draw the legend
|
|
112
|
+
itemColor.push({
|
|
113
|
+
// to support discrete color for continous data
|
|
114
|
+
breakPoint: getColorTableScale?.discrete === true
|
|
115
|
+
? RGBToHex(value, maxValue).offset
|
|
116
|
+
: breakPoint?.length > 0
|
|
117
|
+
? domainIndex * 100.0
|
|
118
|
+
: value[0] * 100.0,
|
|
119
|
+
color: RGBToHex(value).color,
|
|
200
120
|
});
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
.attr("x", 25)
|
|
205
|
-
.attr("y", horizontal ? 30 : 18)
|
|
206
|
-
.attr("width", horizontal
|
|
207
|
-
? legendScaleSize < 200
|
|
208
|
-
? 159
|
|
209
|
-
: legendScaleSize - 40
|
|
210
|
-
: 20)
|
|
211
|
-
.attr("height", horizontal ? 20 : legendScaleSize < 200 ? 159 : legendScaleSize - 40)
|
|
212
|
-
.style("fill", "url(#" + currentIndex + ")");
|
|
213
|
-
// append title
|
|
214
|
-
svgLegend
|
|
215
|
-
.append("text")
|
|
216
|
-
.attr("x", horizontal ? 25 : -168)
|
|
217
|
-
.attr("y", horizontal ? 20 : 15)
|
|
218
|
-
.style("text-anchor", "left")
|
|
219
|
-
.style("transform", horizontal ? "none" : "left")
|
|
220
|
-
.style("transform", horizontal ? "none" : "rotate(270deg)")
|
|
221
|
-
.style("fill", "grey")
|
|
222
|
-
.style("font-size", legendFontSize && legendFontSize > 0
|
|
223
|
-
? `${legendFontSize}px`
|
|
224
|
-
: "16px")
|
|
225
|
-
.text(dataObjectName);
|
|
226
|
-
// create tick marks
|
|
227
|
-
// range varies the size of the axis
|
|
228
|
-
const xLeg = (isLog ? scaleSymlog() : scaleLinear())
|
|
229
|
-
.domain(reverseRange ? [max, min] : [min, max])
|
|
230
|
-
/*@ts-ignore*/
|
|
231
|
-
.range([10, legendScaleSize < 200 ? 168 : legendScaleSize - 32]);
|
|
232
|
-
const yLeg = (isLog ? scaleSymlog() : scaleLinear())
|
|
233
|
-
.domain(reverseRange ? [min, max] : [max, min])
|
|
234
|
-
/*@ts-ignore*/
|
|
235
|
-
.range([10, legendScaleSize < 200 ? 168 : legendScaleSize - 32]);
|
|
236
|
-
const horizontalAxisLeg = axisBottom(xLeg).tickValues(xLeg
|
|
237
|
-
.ticks(0)
|
|
238
|
-
.concat(xLeg.domain(), getTickValues(xLeg.domain(), numberOfTicks)));
|
|
239
|
-
const VerticalAxisLeg = axisRight(yLeg).tickValues(yLeg
|
|
240
|
-
.ticks(0)
|
|
241
|
-
.concat(yLeg.domain(), getTickValues(xLeg.domain(), numberOfTicks)));
|
|
242
|
-
if (isRangeShown) {
|
|
243
|
-
svgLegend
|
|
244
|
-
.attr("class", "axis")
|
|
245
|
-
.append("g")
|
|
246
|
-
.attr("transform", horizontal ? "translate(16, 50)" : "translate(45, 7.5)")
|
|
247
|
-
.style("font-size", tickFontSize && tickFontSize > 0 ? `${tickFontSize}px` : "12px")
|
|
248
|
-
.style("font-weight", "700")
|
|
249
|
-
.call(horizontal ? horizontalAxisLeg : VerticalAxisLeg)
|
|
250
|
-
.style("height", 15);
|
|
251
|
-
}
|
|
121
|
+
});
|
|
122
|
+
if (legendColors.length === 0) {
|
|
123
|
+
return [0, 0, 0];
|
|
252
124
|
}
|
|
253
|
-
|
|
254
|
-
|
|
125
|
+
// get the position and color from the breakpoint modal
|
|
126
|
+
// updates main legend onclicking the custom scales
|
|
127
|
+
if (editedBreakPointValues?.colorArray?.length > 0 &&
|
|
128
|
+
editedBreakPointValues?.customizeFlag === true) {
|
|
129
|
+
const options = editedBreakPointValues.colorArray.map(function (row) {
|
|
130
|
+
return { breakPoint: row.position * 100.0, color: row.color };
|
|
131
|
+
});
|
|
132
|
+
itemColor = options;
|
|
133
|
+
}
|
|
134
|
+
itemColor.sort((a, b) => {
|
|
135
|
+
return a.breakPoint - b.breakPoint;
|
|
136
|
+
});
|
|
137
|
+
//const colorScale = scaleSymlog().domain([min, max]).range([0, 150]);
|
|
138
|
+
// append a defs (for definition) element to your SVG
|
|
139
|
+
const svgLegend = select(divRef.current)
|
|
140
|
+
.style("margin-right", "2px")
|
|
141
|
+
.style("margin-left", "2px")
|
|
142
|
+
.append("svg")
|
|
143
|
+
.style("cursor", getColorScaleData ? "pointer" : "auto")
|
|
144
|
+
.style("border-radius", "5px");
|
|
145
|
+
const defs = svgLegend.append("defs");
|
|
146
|
+
svgLegend
|
|
147
|
+
.attr("width", horizontal ? (legendScaleSize < 200 ? 200 : legendScaleSize) : "100")
|
|
148
|
+
.attr("height", horizontal
|
|
149
|
+
? "70"
|
|
150
|
+
: legendScaleSize < 200
|
|
151
|
+
? 200
|
|
152
|
+
: legendScaleSize - 17);
|
|
153
|
+
const currentIndex = "linear-gradient-" + id + "0";
|
|
154
|
+
const linearGradient = defs
|
|
155
|
+
.append("linearGradient")
|
|
156
|
+
.attr("id", currentIndex);
|
|
157
|
+
// append a linearGradient element to the defs and give it a unique id
|
|
158
|
+
if ((horizontal && !reverseRange) || (!horizontal && reverseRange)) {
|
|
159
|
+
linearGradient
|
|
160
|
+
.attr("x1", "0%")
|
|
161
|
+
.attr("x2", horizontal ? "100%" : "0%")
|
|
162
|
+
.attr("y1", "0%")
|
|
163
|
+
.attr("y2", horizontal ? "0%" : "100%");
|
|
164
|
+
}
|
|
165
|
+
else if ((!horizontal && !reverseRange) ||
|
|
166
|
+
(horizontal && reverseRange)) {
|
|
167
|
+
linearGradient
|
|
168
|
+
.attr("x1", horizontal ? "100%" : "0%")
|
|
169
|
+
.attr("x2", "0%")
|
|
170
|
+
.attr("y1", horizontal ? "0%" : "100%")
|
|
171
|
+
.attr("y2", "0%");
|
|
172
|
+
}
|
|
173
|
+
const colorScale = scaleLinear().domain([0, 1]).range([0, 400]);
|
|
174
|
+
// append multiple color stops by using D3's data/enter step
|
|
175
|
+
linearGradient
|
|
176
|
+
.selectAll("stop")
|
|
177
|
+
.data(nearestData.length > 0 ? nearestData : itemColor)
|
|
178
|
+
.enter()
|
|
179
|
+
.append("stop")
|
|
180
|
+
.attr("offset", function (data) {
|
|
181
|
+
return nearestData.length > 0
|
|
182
|
+
? colorScale(data.breakPoint) / 4 + "%"
|
|
183
|
+
: data.breakPoint + "%";
|
|
184
|
+
})
|
|
185
|
+
.attr("stop-color", function (data) {
|
|
186
|
+
return data.color;
|
|
187
|
+
});
|
|
188
|
+
// draw the rectangle and fill with gradient
|
|
189
|
+
svgLegend
|
|
190
|
+
.append("rect")
|
|
191
|
+
.attr("x", 25)
|
|
192
|
+
.attr("y", horizontal ? 30 : 18)
|
|
193
|
+
.attr("width", horizontal
|
|
194
|
+
? legendScaleSize < 200
|
|
195
|
+
? 159
|
|
196
|
+
: legendScaleSize - 40
|
|
197
|
+
: 20)
|
|
198
|
+
.attr("height", horizontal ? 20 : legendScaleSize < 200 ? 159 : legendScaleSize - 40)
|
|
199
|
+
.style("fill", "url(#" + currentIndex + ")");
|
|
200
|
+
// append title
|
|
201
|
+
svgLegend
|
|
202
|
+
.append("text")
|
|
203
|
+
.attr("x", horizontal ? 25 : -168)
|
|
204
|
+
.attr("y", horizontal ? 20 : 15)
|
|
205
|
+
.style("text-anchor", "left")
|
|
206
|
+
.style("transform", horizontal ? "none" : "left")
|
|
207
|
+
.style("transform", horizontal ? "none" : "rotate(270deg)")
|
|
208
|
+
.style("fill", "grey")
|
|
209
|
+
.style("font-size", legendFontSize && legendFontSize > 0
|
|
210
|
+
? `${legendFontSize}px`
|
|
211
|
+
: "16px")
|
|
212
|
+
.text(dataObjectName);
|
|
213
|
+
// create tick marks
|
|
214
|
+
// range varies the size of the axis
|
|
215
|
+
const xLeg = (isLog ? scaleSymlog() : scaleLinear())
|
|
216
|
+
.domain(reverseRange ? [max, min] : [min, max])
|
|
217
|
+
/*@ts-ignore*/
|
|
218
|
+
.range([10, legendScaleSize < 200 ? 168 : legendScaleSize - 32]);
|
|
219
|
+
const yLeg = (isLog ? scaleSymlog() : scaleLinear())
|
|
220
|
+
.domain(reverseRange ? [min, max] : [max, min])
|
|
221
|
+
/*@ts-ignore*/
|
|
222
|
+
.range([10, legendScaleSize < 200 ? 168 : legendScaleSize - 32]);
|
|
223
|
+
const horizontalAxisLeg = axisBottom(xLeg).tickValues(xLeg
|
|
224
|
+
.ticks(0)
|
|
225
|
+
.concat(xLeg.domain(), getTickValues(xLeg.domain(), numberOfTicks)));
|
|
226
|
+
const VerticalAxisLeg = axisRight(yLeg).tickValues(yLeg
|
|
227
|
+
.ticks(0)
|
|
228
|
+
.concat(yLeg.domain(), getTickValues(xLeg.domain(), numberOfTicks)));
|
|
229
|
+
if (isRangeShown) {
|
|
230
|
+
svgLegend
|
|
231
|
+
.attr("class", "axis")
|
|
232
|
+
.append("g")
|
|
233
|
+
.attr("transform", horizontal ? "translate(16, 50)" : "translate(45, 7.5)")
|
|
234
|
+
.style("font-size", tickFontSize && tickFontSize > 0 ? `${tickFontSize}px` : "12px")
|
|
235
|
+
.style("font-weight", "700")
|
|
236
|
+
.call(horizontal ? horizontalAxisLeg : VerticalAxisLeg)
|
|
237
|
+
.style("height", 15);
|
|
255
238
|
}
|
|
256
|
-
}
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
console.error(error);
|
|
242
|
+
}
|
|
257
243
|
}
|
|
258
244
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
259
245
|
}, [
|
|
@@ -275,7 +261,13 @@ export const ContinuousLegend = ({ min, max, dataObjectName, colorName = "Rainbo
|
|
|
275
261
|
numberOfTicks,
|
|
276
262
|
legendScaleSize,
|
|
277
263
|
]);
|
|
278
|
-
return (React.createElement("div", { style:
|
|
264
|
+
return (React.createElement("div", { style: {
|
|
265
|
+
position: "absolute",
|
|
266
|
+
minHeight: "70px",
|
|
267
|
+
zIndex: 999,
|
|
268
|
+
margin: "10px",
|
|
269
|
+
...cssLegendStyles,
|
|
270
|
+
} },
|
|
279
271
|
React.createElement("div", { id: id ? id : `cont-legend - ${generateUniqueId}`, ref: divRef })));
|
|
280
272
|
};
|
|
281
273
|
//# sourceMappingURL=ContinuousLegend.js.map
|