@internetstiftelsen/charts 0.0.6 → 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 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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.6",
2
+ "version": "0.0.7",
3
3
  "name": "@internetstiftelsen/charts",
4
4
  "type": "module",
5
5
  "sideEffects": false,
package/types.d.ts CHANGED
@@ -45,6 +45,7 @@ export type LineConfig = {
45
45
  export type BarConfig = {
46
46
  dataKey: string;
47
47
  fill?: string;
48
+ colorAdapter?: (data: DataItem, index: number) => string;
48
49
  orientation?: 'vertical' | 'horizontal';
49
50
  };
50
51
  export declare function getSeriesColor(series: {