@internetstiftelsen/charts 0.9.2 → 0.10.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.
Files changed (46) hide show
  1. package/README.md +137 -3
  2. package/dist/area.d.ts +2 -0
  3. package/dist/area.js +39 -31
  4. package/dist/bar.d.ts +20 -1
  5. package/dist/bar.js +395 -519
  6. package/dist/base-chart.d.ts +21 -1
  7. package/dist/base-chart.js +166 -93
  8. package/dist/chart-group.d.ts +137 -0
  9. package/dist/chart-group.js +1155 -0
  10. package/dist/chart-interface.d.ts +1 -1
  11. package/dist/donut-center-content.d.ts +1 -0
  12. package/dist/donut-center-content.js +21 -38
  13. package/dist/donut-chart.js +30 -15
  14. package/dist/gauge-chart.d.ts +20 -0
  15. package/dist/gauge-chart.js +229 -133
  16. package/dist/legend-state.d.ts +19 -0
  17. package/dist/legend-state.js +81 -0
  18. package/dist/legend.d.ts +5 -2
  19. package/dist/legend.js +45 -38
  20. package/dist/line.js +3 -1
  21. package/dist/pie-chart.d.ts +3 -0
  22. package/dist/pie-chart.js +45 -19
  23. package/dist/scatter.d.ts +16 -0
  24. package/dist/scatter.js +165 -0
  25. package/dist/tooltip.d.ts +2 -1
  26. package/dist/tooltip.js +21 -25
  27. package/dist/types.d.ts +19 -1
  28. package/dist/utils.js +11 -19
  29. package/dist/validation.d.ts +4 -0
  30. package/dist/validation.js +19 -0
  31. package/dist/x-axis.d.ts +10 -0
  32. package/dist/x-axis.js +190 -149
  33. package/dist/xy-chart.d.ts +40 -1
  34. package/dist/xy-chart.js +488 -165
  35. package/dist/y-axis.d.ts +7 -2
  36. package/dist/y-axis.js +99 -10
  37. package/docs/chart-group.md +213 -0
  38. package/docs/components.md +321 -0
  39. package/docs/donut-chart.md +193 -0
  40. package/docs/gauge-chart.md +175 -0
  41. package/docs/getting-started.md +311 -0
  42. package/docs/pie-chart.md +123 -0
  43. package/docs/theming.md +162 -0
  44. package/docs/word-cloud-chart.md +98 -0
  45. package/docs/xy-chart.md +517 -0
  46. package/package.json +6 -4
@@ -1,5 +1,5 @@
1
1
  import type { ExportHooks } from './types.js';
2
- export type ChartComponentType = 'line' | 'area' | 'bar' | 'xAxis' | 'yAxis' | 'grid' | 'tooltip' | 'legend' | 'title' | 'donutCenterContent';
2
+ export type ChartComponentType = 'line' | 'scatter' | 'area' | 'bar' | 'xAxis' | 'yAxis' | 'grid' | 'tooltip' | 'legend' | 'title' | 'donutCenterContent';
3
3
  export interface ChartComponentBase {
4
4
  type: ChartComponentType;
5
5
  }
@@ -29,5 +29,6 @@ export declare class DonutCenterContent implements ChartComponent<DonutCenterCon
29
29
  getExportConfig(): DonutCenterContentConfigBase;
30
30
  createExportComponent(override?: Partial<DonutCenterContentConfigBase>): ChartComponent<DonutCenterContentConfigBase>;
31
31
  render(svg: Selection<SVGSVGElement, undefined, null, undefined>, cx: number, cy: number, theme: ChartTheme, fontScale?: number): void;
32
+ private buildElement;
32
33
  }
33
34
  export {};
@@ -62,44 +62,11 @@ export class DonutCenterContent {
62
62
  }
63
63
  render(svg, cx, cy, theme, fontScale = 1) {
64
64
  const defaults = theme.donut.centerContent;
65
- const elements = [];
66
- if (this.mainValue) {
67
- const style = this.config.mainValueStyle;
68
- elements.push({
69
- text: this.mainValue,
70
- fontSize: (style?.fontSize ?? defaults.mainValue.fontSize) *
71
- fontScale,
72
- fontWeight: style?.fontWeight ?? defaults.mainValue.fontWeight,
73
- fontFamily: style?.fontFamily ??
74
- defaults.mainValue.fontFamily ??
75
- theme.fontFamily,
76
- color: style?.color ?? defaults.mainValue.color,
77
- });
78
- }
79
- if (this.title) {
80
- const style = this.config.titleStyle;
81
- elements.push({
82
- text: this.title,
83
- fontSize: (style?.fontSize ?? defaults.title.fontSize) * fontScale,
84
- fontWeight: style?.fontWeight ?? defaults.title.fontWeight,
85
- fontFamily: style?.fontFamily ??
86
- defaults.title.fontFamily ??
87
- theme.fontFamily,
88
- color: style?.color ?? defaults.title.color,
89
- });
90
- }
91
- if (this.subtitle) {
92
- const style = this.config.subtitleStyle;
93
- elements.push({
94
- text: this.subtitle,
95
- fontSize: (style?.fontSize ?? defaults.subtitle.fontSize) * fontScale,
96
- fontWeight: style?.fontWeight ?? defaults.subtitle.fontWeight,
97
- fontFamily: style?.fontFamily ??
98
- defaults.subtitle.fontFamily ??
99
- theme.fontFamily,
100
- color: style?.color ?? defaults.subtitle.color,
101
- });
102
- }
65
+ const elements = [
66
+ this.buildElement(this.mainValue, this.config.mainValueStyle, defaults.mainValue, theme.fontFamily, fontScale),
67
+ this.buildElement(this.title, this.config.titleStyle, defaults.title, theme.fontFamily, fontScale),
68
+ this.buildElement(this.subtitle, this.config.subtitleStyle, defaults.subtitle, theme.fontFamily, fontScale),
69
+ ].filter((element) => element !== null);
103
70
  if (elements.length === 0) {
104
71
  return;
105
72
  }
@@ -122,4 +89,20 @@ export class DonutCenterContent {
122
89
  currentY += el.fontSize + lineSpacing;
123
90
  }
124
91
  }
92
+ buildElement(text, style, defaults, themeFontFamily, fontScale) {
93
+ if (!text) {
94
+ return null;
95
+ }
96
+ const resolvedStyle = {
97
+ ...defaults,
98
+ ...style,
99
+ };
100
+ return {
101
+ text,
102
+ fontSize: resolvedStyle.fontSize * fontScale,
103
+ fontWeight: resolvedStyle.fontWeight,
104
+ fontFamily: resolvedStyle.fontFamily || themeFontFamily,
105
+ color: resolvedStyle.color,
106
+ };
107
+ }
125
108
  }
@@ -6,6 +6,15 @@ const HOVER_EXPAND_PX = 8;
6
6
  const ANIMATION_DURATION_MS = 150;
7
7
  const OUTSIDE_LABEL_TEXT_OFFSET_PX = 10;
8
8
  const OUTSIDE_LABEL_LINE_INSET_PX = 4;
9
+ const DEFAULT_DONUT_VALUE_LABEL = {
10
+ show: false,
11
+ position: 'auto',
12
+ outsideOffset: 16,
13
+ minVerticalSpacing: 14,
14
+ formatter: (label, value, _data, _percentage) => {
15
+ return `${label}: ${value}`;
16
+ },
17
+ };
9
18
  export class DonutChart extends RadialChartBase {
10
19
  constructor(config) {
11
20
  super(config);
@@ -57,21 +66,27 @@ export class DonutChart extends RadialChartBase {
57
66
  writable: true,
58
67
  value: null
59
68
  });
60
- const donut = config.donut ?? {};
61
- this.innerRadiusRatio =
62
- donut.innerRadius ?? this.theme.donut.innerRadius;
63
- this.padAngle = donut.padAngle ?? this.theme.donut.padAngle;
64
- this.cornerRadius = donut.cornerRadius ?? this.theme.donut.cornerRadius;
65
- this.valueKey = config.valueKey ?? 'value';
66
- this.labelKey = config.labelKey ?? 'name';
67
- this.valueLabel = {
68
- show: config.valueLabel?.show ?? false,
69
- position: config.valueLabel?.position ?? 'auto',
70
- outsideOffset: config.valueLabel?.outsideOffset ?? 16,
71
- minVerticalSpacing: config.valueLabel?.minVerticalSpacing ?? 14,
72
- formatter: config.valueLabel?.formatter ??
73
- ((label, value, _data, _percentage) => `${label}: ${value}`),
69
+ const donut = {
70
+ innerRadius: this.theme.donut.innerRadius,
71
+ padAngle: this.theme.donut.padAngle,
72
+ cornerRadius: this.theme.donut.cornerRadius,
73
+ ...config.donut,
74
74
  };
75
+ const resolvedConfig = {
76
+ valueKey: 'value',
77
+ labelKey: 'name',
78
+ ...config,
79
+ };
80
+ const valueLabel = {
81
+ ...DEFAULT_DONUT_VALUE_LABEL,
82
+ ...config.valueLabel,
83
+ };
84
+ this.innerRadiusRatio = donut.innerRadius;
85
+ this.padAngle = donut.padAngle;
86
+ this.cornerRadius = donut.cornerRadius;
87
+ this.valueKey = resolvedConfig.valueKey;
88
+ this.labelKey = resolvedConfig.labelKey;
89
+ this.valueLabel = valueLabel;
75
90
  this.initializeDataState();
76
91
  }
77
92
  validateDonutData() {
@@ -122,7 +137,7 @@ export class DonutChart extends RadialChartBase {
122
137
  ...(this.centerContent ? [this.centerContent] : []),
123
138
  ...this.getBaseExportComponents({
124
139
  tooltip: true,
125
- legend: this.legend?.isInlineMode(),
140
+ legend: this.shouldIncludeLegendInExport(),
126
141
  }),
127
142
  ];
128
143
  }
@@ -101,6 +101,7 @@ export declare class GaugeChart extends BaseChart {
101
101
  private targetValue;
102
102
  private lastRenderedValue;
103
103
  constructor(config: GaugeChartConfig);
104
+ private resolveGaugeConstructorValues;
104
105
  private normalizeNeedleConfig;
105
106
  private normalizeMarkerConfig;
106
107
  private getThemePaletteColor;
@@ -108,9 +109,18 @@ export declare class GaugeChart extends BaseChart {
108
109
  private normalizeAnimationConfig;
109
110
  private resolveAnimationEasing;
110
111
  private parseCssLinearEasing;
112
+ private parseLinearEasingStop;
113
+ private resolveLinearEasingPositions;
114
+ private fillMissingLinearEasingPositions;
115
+ private interpolateLinearEasing;
111
116
  private normalizeTickLabelStyle;
112
117
  private normalizeValueLabelStyle;
113
118
  private validateGaugeConfig;
119
+ private validateGaugeRange;
120
+ private validateGaugeGeometry;
121
+ private validateTickSettings;
122
+ private validateIndicatorSettings;
123
+ private validateAnimationSettings;
114
124
  private validateSegments;
115
125
  private refreshResolvedValues;
116
126
  private resolveValue;
@@ -125,6 +135,16 @@ export declare class GaugeChart extends BaseChart {
125
135
  protected createExportChart(): BaseChart;
126
136
  protected syncDerivedState(): void;
127
137
  protected renderChart({ svg, plotGroup, plotArea, }: BaseRenderContext): void;
138
+ private resolveGaugeGeometry;
139
+ private resolveLabelAllowance;
140
+ private resolveHalfCircleGeometry;
141
+ private resolveFullCircleGeometry;
142
+ private resolveInnerRadius;
143
+ private renderSegmentsOrProgress;
144
+ private renderVisibleSegments;
145
+ private renderGaugeLabels;
146
+ private renderGaugeIndicators;
147
+ private attachTooltipIfEnabled;
128
148
  private resolveAnimationStartValue;
129
149
  private shouldAnimateTransition;
130
150
  private buildAriaLabel;