@emerson-eps/color-tables 0.2.5 → 0.2.8
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/ColorSelector/ColorSelectorAccordion.js +2 -2
- package/dist/component/ColorSelector/ColorSelectorAccordion.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorComponent.d.ts +2 -2
- package/dist/component/ColorSelector/ColorSelectorComponent.js +8 -3
- package/dist/component/ColorSelector/ColorSelectorComponent.js.map +1 -1
- package/dist/component/ColorSelector/ColorSelectorWrapper.d.ts +2 -2
- package/dist/component/ColorSelector/ColorSelectorWrapper.js.map +1 -1
- package/dist/component/Legend/ColorLegend.d.ts +6 -3
- package/dist/component/Legend/ColorLegend.js +10 -2
- package/dist/component/Legend/ColorLegend.js.map +1 -1
- package/dist/component/Legend/ContinuousLegend.js +12 -15
- package/dist/component/Legend/ContinuousLegend.js.map +1 -1
- package/dist/component/Legend/DiscreteLegend.js +58 -53
- package/dist/component/Legend/DiscreteLegend.js.map +1 -1
- package/dist/component/Utils/discreteLegend.d.ts +1 -1
- package/dist/component/Utils/discreteLegend.js +120 -64
- package/dist/component/Utils/discreteLegend.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/component/ColorSelector/ColorSelectorAccordion.tsx +2 -2
- package/src/component/ColorSelector/ColorSelectorComponent.tsx +19 -14
- package/src/component/ColorSelector/ColorSelectorWrapper.tsx +5 -5
- package/src/component/Legend/ColorLegend.tsx +14 -4
- package/src/component/Legend/ContinuousLegend.tsx +50 -55
- package/src/component/Legend/DiscreteLegend.tsx +117 -79
- package/src/component/Utils/discreteLegend.ts +125 -75
- package/src/index.ts +22 -5
- package/tsconfig.json +2 -2
|
@@ -1,105 +1,155 @@
|
|
|
1
|
-
declare type ItemColor = {
|
|
2
|
-
color: any;
|
|
3
|
-
}
|
|
1
|
+
declare type ItemColor = {
|
|
2
|
+
color: any;
|
|
3
|
+
};
|
|
4
4
|
|
|
5
5
|
// eslint-disable-next-line
|
|
6
|
-
export default function discreteLegendUtil(itemColor: ItemColor[], isSelectorLegend?: boolean): any {
|
|
7
|
-
var cellWidth = 22;
|
|
8
|
-
var cellHeight = 22;
|
|
9
|
-
const cellPadding = 2;
|
|
6
|
+
export default function discreteLegendUtil(itemColor: ItemColor[], isSelectorLegend?: boolean, horizontal?: any): any {
|
|
7
|
+
// var cellWidth = 22;
|
|
8
|
+
// var cellHeight = 22;
|
|
10
9
|
|
|
11
|
-
if (isSelectorLegend) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
// if (isSelectorLegend) {
|
|
11
|
+
// cellWidth = 25;
|
|
12
|
+
// cellHeight = 22;
|
|
13
|
+
// }
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
const legendValues: ItemColor[] = [];
|
|
17
16
|
|
|
18
17
|
// eslint-disable-next-line
|
|
19
|
-
function legend(g: any) {
|
|
18
|
+
function legend(g: any) {
|
|
20
19
|
function drawLegend() {
|
|
21
20
|
// Code to fill the color
|
|
22
21
|
// Styling for color selector legend
|
|
23
|
-
if (isSelectorLegend) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
//if (isSelectorLegend) {
|
|
23
|
+
g.selectAll("g.legendCells")
|
|
24
|
+
.data(itemColor)
|
|
25
|
+
.enter()
|
|
26
|
+
.append("g")
|
|
27
|
+
.append("rect")
|
|
28
|
+
.attr("class", "rectLabel")
|
|
29
|
+
.style("cursor", "pointer")
|
|
30
|
+
.style("pointer-events", "all");
|
|
31
|
+
g.selectAll("rect")
|
|
32
|
+
.attr("height", 1)
|
|
33
|
+
.attr("width", 1)
|
|
34
|
+
.style("fill", function (d: Record<string, unknown>) {
|
|
35
|
+
return d["color"];
|
|
36
|
+
});
|
|
37
|
+
if (horizontal && !isSelectorLegend) {
|
|
38
|
+
g.selectAll("rect")
|
|
39
|
+
.attr("x", function (d: number, i: number) {
|
|
40
|
+
console.log(d)
|
|
41
|
+
return i;
|
|
42
|
+
})
|
|
43
|
+
.attr("y", 0);
|
|
44
|
+
} else if (!horizontal && !isSelectorLegend) {
|
|
29
45
|
g.selectAll("rect")
|
|
30
|
-
.attr("
|
|
46
|
+
.attr("y", function (d: number, i: number) {
|
|
31
47
|
console.log(d)
|
|
32
48
|
return i;
|
|
33
49
|
})
|
|
34
|
-
.attr("
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.
|
|
38
|
-
|
|
50
|
+
.attr("x", 0);
|
|
51
|
+
} else if (horizontal == true && isSelectorLegend) {
|
|
52
|
+
g.selectAll("rect")
|
|
53
|
+
.attr("x", function (d: number, i: number) {
|
|
54
|
+
console.log(d)
|
|
55
|
+
return i;
|
|
39
56
|
})
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
.
|
|
44
|
-
.attr("class", "breakLabels")
|
|
45
|
-
.style("font-size", "0.4")
|
|
46
|
-
//.attr("x", cellWidth + cellPadding)
|
|
47
|
-
//.attr("y", 5 + cellHeight / 2)
|
|
48
|
-
.attr("x", function (d: any, i: any) {
|
|
57
|
+
.attr("y", 0);
|
|
58
|
+
} else if (horizontal == false && isSelectorLegend) {
|
|
59
|
+
g.selectAll("rect")
|
|
60
|
+
.attr("y", function (d: number, i: number) {
|
|
49
61
|
console.log(d)
|
|
50
|
-
return i
|
|
62
|
+
return i;
|
|
51
63
|
})
|
|
52
|
-
.attr("
|
|
53
|
-
|
|
64
|
+
.attr("x", 0);
|
|
65
|
+
} else {
|
|
66
|
+
g.selectAll("rect")
|
|
67
|
+
.attr("x", function (d: number, i: number) {
|
|
54
68
|
console.log(d)
|
|
55
69
|
return i;
|
|
56
70
|
})
|
|
71
|
+
.attr("y", 0);
|
|
57
72
|
}
|
|
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
|
+
//}
|
|
58
92
|
// styling for main legend
|
|
59
|
-
else {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
+
// }
|
|
78
127
|
}
|
|
79
128
|
|
|
80
129
|
// display the discrete legend
|
|
81
|
-
if (!isSelectorLegend) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
|
|
89
139
|
drawLegend();
|
|
90
140
|
}
|
|
91
141
|
// eslint-disable-next-line
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
142
|
+
legend.inputScale = function (newScale: any) {
|
|
143
|
+
// eslint-disable-next-line
|
|
144
|
+
let scale: any = {};
|
|
145
|
+
scale = newScale;
|
|
146
|
+
|
|
147
|
+
scale.domain().forEach(function (el: any) {
|
|
148
|
+
const cellObject = { color: scale(el), label: el };
|
|
149
|
+
legendValues.push(cellObject);
|
|
150
|
+
});
|
|
151
|
+
return this;
|
|
152
|
+
};
|
|
103
153
|
|
|
104
154
|
return legend;
|
|
105
155
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
import { ColorSelectorAccordion } from './component/ColorSelector/ColorSelectorAccordion';
|
|
6
|
+
import { ColorSelectorComponent } from './component/ColorSelector/ColorSelectorComponent';
|
|
7
|
+
import { ColorSelectorWrapper } from './component/ColorSelector/ColorSelectorWrapper';
|
|
5
8
|
import * as colorTables from './component/color-tables.json';
|
|
6
|
-
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
ContinuousLegend,
|
|
12
|
+
colorsArray,
|
|
13
|
+
rgbValues,
|
|
14
|
+
RGBToHex,
|
|
15
|
+
colorTableData,
|
|
16
|
+
DiscreteColorLegend,
|
|
17
|
+
colorTablesObj,
|
|
18
|
+
colorTablesArray,
|
|
19
|
+
ColorSelectorAccordion,
|
|
20
|
+
ColorSelectorComponent,
|
|
21
|
+
ColorSelectorWrapper,
|
|
22
|
+
colorTables,
|
|
23
|
+
};
|
package/tsconfig.json
CHANGED