@internetstiftelsen/charts 0.0.5 → 0.0.7
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/bar.d.ts +1 -0
- package/bar.js +9 -2
- package/legend.js +5 -3
- package/package.json +1 -1
- package/theme.js +1 -1
- package/types.d.ts +1 -0
package/bar.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class Bar implements ChartComponent {
|
|
|
5
5
|
readonly type: "bar";
|
|
6
6
|
readonly dataKey: string;
|
|
7
7
|
readonly fill: string;
|
|
8
|
+
readonly colorAdapter?: (data: DataItem, index: number) => string;
|
|
8
9
|
readonly orientation: Orientation;
|
|
9
10
|
constructor(config: BarConfig);
|
|
10
11
|
render(plotGroup: Selection<SVGGElement, undefined, null, undefined>, data: DataItem[], xKey: string, x: any, y: any, parseValue: (value: any) => number, xScaleType?: ScaleType, _theme?: ChartTheme): void;
|
package/bar.js
CHANGED
|
@@ -18,6 +18,12 @@ export class Bar {
|
|
|
18
18
|
writable: true,
|
|
19
19
|
value: void 0
|
|
20
20
|
});
|
|
21
|
+
Object.defineProperty(this, "colorAdapter", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
21
27
|
Object.defineProperty(this, "orientation", {
|
|
22
28
|
enumerable: true,
|
|
23
29
|
configurable: true,
|
|
@@ -26,6 +32,7 @@ export class Bar {
|
|
|
26
32
|
});
|
|
27
33
|
this.dataKey = config.dataKey;
|
|
28
34
|
this.fill = config.fill || '#8884d8';
|
|
35
|
+
this.colorAdapter = config.colorAdapter;
|
|
29
36
|
this.orientation = config.orientation || 'vertical';
|
|
30
37
|
}
|
|
31
38
|
render(plotGroup, data, xKey, x, y, parseValue, xScaleType = 'band', _theme) {
|
|
@@ -83,7 +90,7 @@ export class Bar {
|
|
|
83
90
|
const yPos = y(parseValue(d[this.dataKey])) || 0;
|
|
84
91
|
return Math.abs(yBaseline - yPos);
|
|
85
92
|
})
|
|
86
|
-
.attr('fill', this.fill);
|
|
93
|
+
.attr('fill', (d, i) => this.colorAdapter ? this.colorAdapter(d, i) : this.fill);
|
|
87
94
|
}
|
|
88
95
|
renderHorizontal(plotGroup, data, xKey, x, y, parseValue, yScaleType) {
|
|
89
96
|
const getYPosition = (d) => {
|
|
@@ -132,6 +139,6 @@ export class Bar {
|
|
|
132
139
|
return Math.abs(xPos - xBaseline);
|
|
133
140
|
})
|
|
134
141
|
.attr('height', bandwidth)
|
|
135
|
-
.attr('fill', this.fill);
|
|
142
|
+
.attr('fill', (d, i) => this.colorAdapter ? this.colorAdapter(d, i) : this.fill);
|
|
136
143
|
}
|
|
137
144
|
}
|
package/legend.js
CHANGED
|
@@ -54,8 +54,10 @@ export class Legend {
|
|
|
54
54
|
return this.visibilityState.get(dataKey) ?? true;
|
|
55
55
|
}
|
|
56
56
|
getCheckmarkPath(size) {
|
|
57
|
-
const scale = size / 24;
|
|
58
|
-
|
|
57
|
+
const scale = (size / 24) * 0.7;
|
|
58
|
+
const offsetX = size * 0.15;
|
|
59
|
+
const offsetY = size * 0.15;
|
|
60
|
+
return `M ${4 * scale + offsetX} ${12 * scale + offsetY} L ${9 * scale + offsetX} ${17 * scale + offsetY} L ${20 * scale + offsetX} ${6 * scale + offsetY}`;
|
|
59
61
|
}
|
|
60
62
|
parseColor(color) {
|
|
61
63
|
// Handle hex colors
|
|
@@ -153,7 +155,7 @@ export class Legend {
|
|
|
153
155
|
const isVisible = this.visibilityState.get(d.dataKey) ?? true;
|
|
154
156
|
return isVisible ? d.color : theme.legend.uncheckedColor;
|
|
155
157
|
})
|
|
156
|
-
.attr('rx',
|
|
158
|
+
.attr('rx', 3);
|
|
157
159
|
// Add checkmark when visible
|
|
158
160
|
legendGroups
|
|
159
161
|
.append('path')
|
package/package.json
CHANGED
package/theme.js
CHANGED
package/types.d.ts
CHANGED