@pushwoosh/kit-charts 0.0.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 (119) hide show
  1. package/LICENSE +21 -0
  2. package/ai-documentation.md +378 -0
  3. package/core/Chart/Axes.d.ts +19 -0
  4. package/core/Chart/Axes.js +204 -0
  5. package/core/Chart/Chart.d.ts +33 -0
  6. package/core/Chart/Chart.js +616 -0
  7. package/core/Chart/Chart.styles.d.ts +109 -0
  8. package/core/Chart/Chart.styles.js +227 -0
  9. package/core/Chart/ChartErrorBoundary.d.ts +15 -0
  10. package/core/Chart/ChartErrorBoundary.js +27 -0
  11. package/core/Chart/Hinted.d.ts +11 -0
  12. package/core/Chart/Hinted.js +63 -0
  13. package/core/Chart/Legend.d.ts +15 -0
  14. package/core/Chart/Legend.js +92 -0
  15. package/core/Chart/PlotDecorations.d.ts +17 -0
  16. package/core/Chart/PlotDecorations.js +172 -0
  17. package/core/Chart/StackLabels.d.ts +6 -0
  18. package/core/Chart/StackLabels.js +85 -0
  19. package/core/Chart/Titles.d.ts +6 -0
  20. package/core/Chart/Titles.js +67 -0
  21. package/core/Chart/Tooltip.d.ts +13 -0
  22. package/core/Chart/Tooltip.js +87 -0
  23. package/core/Chart/useSize.d.ts +5 -0
  24. package/core/Chart/useSize.js +45 -0
  25. package/core/animation/motion.d.ts +20 -0
  26. package/core/animation/motion.js +20 -0
  27. package/core/animation/useTweenedNumbers.d.ts +1 -0
  28. package/core/animation/useTweenedNumbers.js +51 -0
  29. package/core/data/points.d.ts +14 -0
  30. package/core/data/points.js +73 -0
  31. package/core/format/time.d.ts +2 -0
  32. package/core/format/time.js +38 -0
  33. package/core/geometry/path.d.ts +19 -0
  34. package/core/geometry/path.js +76 -0
  35. package/core/layout/legend-layout.d.ts +21 -0
  36. package/core/layout/legend-layout.js +103 -0
  37. package/core/layout/measure-text.d.ts +9 -0
  38. package/core/layout/measure-text.js +57 -0
  39. package/core/layout/metrics.d.ts +63 -0
  40. package/core/layout/metrics.js +66 -0
  41. package/core/layout/point-width.d.ts +11 -0
  42. package/core/layout/point-width.js +86 -0
  43. package/core/layout/title-layout.d.ts +30 -0
  44. package/core/layout/title-layout.js +99 -0
  45. package/core/model/build-model.d.ts +69 -0
  46. package/core/model/build-model.js +556 -0
  47. package/core/model/palette.d.ts +15 -0
  48. package/core/model/palette.js +17 -0
  49. package/core/options/normalize.d.ts +8 -0
  50. package/core/options/normalize.js +44 -0
  51. package/core/registry/registry.d.ts +5 -0
  52. package/core/registry/registry.js +32 -0
  53. package/core/scale/band.d.ts +10 -0
  54. package/core/scale/band.js +33 -0
  55. package/core/scale/color.d.ts +9 -0
  56. package/core/scale/color.js +69 -0
  57. package/core/scale/linear.d.ts +17 -0
  58. package/core/scale/linear.js +64 -0
  59. package/core/scale/time.d.ts +19 -0
  60. package/core/scale/time.js +187 -0
  61. package/core/stack/stack.d.ts +9 -0
  62. package/core/stack/stack.js +76 -0
  63. package/core/types/formatter.d.ts +59 -0
  64. package/core/types/formatter.js +1 -0
  65. package/core/types/geometry.d.ts +16 -0
  66. package/core/types/geometry.js +1 -0
  67. package/core/types/options.d.ts +331 -0
  68. package/core/types/options.js +2 -0
  69. package/core/types/renderer.d.ts +101 -0
  70. package/core/types/renderer.js +1 -0
  71. package/core/types/scale.d.ts +34 -0
  72. package/core/types/scale.js +1 -0
  73. package/index.d.ts +16 -0
  74. package/index.js +10 -0
  75. package/package.json +64 -0
  76. package/presets/AreaChart.d.ts +3 -0
  77. package/presets/AreaChart.js +13 -0
  78. package/presets/ColumnChart.d.ts +3 -0
  79. package/presets/ColumnChart.js +13 -0
  80. package/presets/LineChart.d.ts +3 -0
  81. package/presets/LineChart.js +13 -0
  82. package/presets/PieChart.d.ts +3 -0
  83. package/presets/PieChart.js +13 -0
  84. package/presets/StackedColumnChart.d.ts +7 -0
  85. package/presets/StackedColumnChart.js +31 -0
  86. package/presets/index.d.ts +5 -0
  87. package/presets/index.js +5 -0
  88. package/series/area/area.d.ts +2 -0
  89. package/series/area/area.js +57 -0
  90. package/series/area/index.d.ts +1 -0
  91. package/series/area/index.js +1 -0
  92. package/series/column/column.d.ts +2 -0
  93. package/series/column/column.js +163 -0
  94. package/series/column/index.d.ts +1 -0
  95. package/series/column/index.js +1 -0
  96. package/series/heatmap/heatmap.d.ts +2 -0
  97. package/series/heatmap/heatmap.js +172 -0
  98. package/series/heatmap/index.d.ts +1 -0
  99. package/series/heatmap/index.js +1 -0
  100. package/series/line/index.d.ts +1 -0
  101. package/series/line/index.js +1 -0
  102. package/series/line/line.d.ts +2 -0
  103. package/series/line/line.js +49 -0
  104. package/series/pie/index.d.ts +1 -0
  105. package/series/pie/index.js +1 -0
  106. package/series/pie/pie.d.ts +2 -0
  107. package/series/pie/pie.js +224 -0
  108. package/series/shared/DataLabels.d.ts +14 -0
  109. package/series/shared/DataLabels.js +124 -0
  110. package/series/shared/Markers.d.ts +9 -0
  111. package/series/shared/Markers.js +34 -0
  112. package/series/shared/color.d.ts +1 -0
  113. package/series/shared/color.js +19 -0
  114. package/series/shared/domain.d.ts +3 -0
  115. package/series/shared/domain.js +14 -0
  116. package/series/shared/hit.d.ts +3 -0
  117. package/series/shared/hit.js +33 -0
  118. package/series/shared/legend.d.ts +3 -0
  119. package/series/shared/legend.js +12 -0
@@ -0,0 +1,99 @@
1
+ import { DEFAULT_SUBTITLE_FONT_SIZE, DEFAULT_TITLE_FONT_SIZE, measureText, textHeight } from './measure-text';
2
+ import { HINT_ICON_GAP, HINT_ICON_SIZE, TITLE_BLOCK_GAP } from './metrics';
3
+ const ANCHOR = {
4
+ left: 'start',
5
+ center: 'middle',
6
+ right: 'end'
7
+ };
8
+ const shown = title => {
9
+ var _title$style;
10
+ return Boolean(title === null || title === void 0 ? void 0 : title.text) && (title === null || title === void 0 || (_title$style = title.style) === null || _title$style === void 0 ? void 0 : _title$style.display) !== 'none';
11
+ };
12
+ const sizeOf = (title, fallback) => {
13
+ var _title$style2;
14
+ return (title === null || title === void 0 || (_title$style2 = title.style) === null || _title$style2 === void 0 ? void 0 : _title$style2.fontSize) ?? fallback;
15
+ };
16
+ export function layoutTitles(options, size, spacing) {
17
+ const [spaceTop, spaceRight,, spaceLeft] = spacing;
18
+ const {
19
+ title,
20
+ subtitle
21
+ } = options;
22
+ const entries = [];
23
+ const push = (key, source, fontSize, top) => {
24
+ const height = textHeight({
25
+ ...(source === null || source === void 0 ? void 0 : source.style),
26
+ fontSize
27
+ });
28
+ if (!shown(source)) {
29
+ return 0;
30
+ }
31
+ const align = (source === null || source === void 0 ? void 0 : source.align) ?? 'left';
32
+ const x = (() => {
33
+ if (align === 'center') {
34
+ return size.width / 2;
35
+ }
36
+ if (align === 'right') {
37
+ return size.width - spaceRight;
38
+ }
39
+ return spaceLeft;
40
+ })();
41
+ const text = (source === null || source === void 0 ? void 0 : source.text) ?? '';
42
+ const baseline = top + height;
43
+ const width = measureText(text, {
44
+ ...(source === null || source === void 0 ? void 0 : source.style),
45
+ fontSize
46
+ });
47
+ // The icon follows the text, wherever the anchor put it.
48
+ const textEnd = (() => {
49
+ if (align === 'center') {
50
+ return x + width / 2;
51
+ }
52
+ if (align === 'right') {
53
+ return x;
54
+ }
55
+ return x + width;
56
+ })();
57
+ entries.push({
58
+ key,
59
+ text,
60
+ x,
61
+ // `y` is a baseline, so the first line starts one line height down.
62
+ y: baseline,
63
+ anchor: ANCHOR[align],
64
+ style: source === null || source === void 0 ? void 0 : source.style,
65
+ fontSize,
66
+ hint: source !== null && source !== void 0 && source.hint ? {
67
+ text: source.hint,
68
+ x: textEnd + HINT_ICON_GAP + HINT_ICON_SIZE / 2,
69
+ y: baseline - textHeight({
70
+ fontSize
71
+ }) / 3
72
+ } : undefined
73
+ });
74
+ return height;
75
+ };
76
+ const titleHeight = push('title', title, sizeOf(title, DEFAULT_TITLE_FONT_SIZE), spaceTop);
77
+ // The caption shares the title's row, pushed to the far edge: the note about
78
+ // what the figures cover belongs beside the name, not under it.
79
+ if (title !== null && title !== void 0 && title.caption) {
80
+ push('caption', {
81
+ text: title.caption,
82
+ align: 'right',
83
+ style: title.captionStyle
84
+ }, sizeOf({
85
+ style: title.captionStyle
86
+ }, DEFAULT_SUBTITLE_FONT_SIZE), spaceTop + titleHeight - textHeight({
87
+ ...title.captionStyle,
88
+ fontSize: sizeOf({
89
+ style: title.captionStyle
90
+ }, DEFAULT_SUBTITLE_FONT_SIZE)
91
+ }));
92
+ }
93
+ const subtitleHeight = push('subtitle', subtitle, sizeOf(subtitle, DEFAULT_SUBTITLE_FONT_SIZE), spaceTop + titleHeight);
94
+ const total = titleHeight + subtitleHeight;
95
+ return {
96
+ height: total > 0 ? total + TITLE_BLOCK_GAP : 0,
97
+ entries
98
+ };
99
+ }
@@ -0,0 +1,69 @@
1
+ import { type NormalizedPoint } from '../data/points';
2
+ import { type TitleEntry } from '../layout/title-layout';
3
+ import { type Rect, type Size, type SlotGeometry, type Spacing } from '../types/geometry';
4
+ import { type AxisOptions, type ChartOptions, type SeriesOptionsBase } from '../types/options';
5
+ import { type AnySeriesRenderer, type LegendItem, type NumberFormatter, type StackedValue } from '../types/renderer';
6
+ import { type AnyScale, type BandScale, type ColorScale, type ContinuousScale } from '../types/scale';
7
+ export interface ResolvedSeries {
8
+ options: SeriesOptionsBase;
9
+ renderer: AnySeriesRenderer;
10
+ index: number;
11
+ color: string;
12
+ points: NormalizedPoint[];
13
+ /** Point indices switched off in the legend; kept so their shape can animate out. */
14
+ hiddenPoints: Set<number>;
15
+ /**
16
+ * Switched off in the legend, or `visible: false` in the options. Such a series
17
+ * keeps its legend entry and is still handed to its renderer — transparently —
18
+ * so that hiding and showing it can be animated instead of popping.
19
+ */
20
+ hidden: boolean;
21
+ }
22
+ export type TickAnchor = 'start' | 'middle' | 'end';
23
+ export interface AxisTick {
24
+ value: number | string;
25
+ position: number;
26
+ label: string;
27
+ anchor: TickAnchor;
28
+ /** Sentence this tick explains itself with, opened from the label on hover. */
29
+ hint?: string;
30
+ }
31
+ export interface AxisModel {
32
+ id: string;
33
+ options: AxisOptions;
34
+ scale: AnyScale;
35
+ ticks: AxisTick[];
36
+ }
37
+ export interface ChartModel {
38
+ plot: Rect;
39
+ axisless: boolean;
40
+ xAxis: AxisModel;
41
+ yAxes: AxisModel[];
42
+ titles: TitleEntry[];
43
+ colorScale: ColorScale | undefined;
44
+ series: ResolvedSeries[];
45
+ legend: LegendItem[];
46
+ colors: readonly string[];
47
+ categories: string[];
48
+ stacks: Map<number, Array<StackedValue | undefined>>;
49
+ slots: Map<number, SlotGeometry>;
50
+ numberFormat: NumberFormatter;
51
+ /** Resolved `chart.spacing`; the legend needs the bottom of it to sit inside. */
52
+ spacing: Spacing;
53
+ }
54
+ /** Key for a switched-off series, or for one of its points. */
55
+ export declare const hiddenKey: (seriesIndex: number, pointIndex?: number) => string;
56
+ declare const isBand: (scale: AnyScale) => scale is BandScale;
57
+ declare const isContinuous: (scale: AnyScale) => scale is ContinuousScale;
58
+ export interface BuildModelInput {
59
+ options: ChartOptions;
60
+ size: Size;
61
+ renderers: ReadonlyMap<string, AnySeriesRenderer>;
62
+ /**
63
+ * What the viewer has switched off in the legend, keyed by `hiddenKey`: a whole
64
+ * series, or a single point where the legend keys points, as a pie does.
65
+ */
66
+ hidden?: ReadonlySet<string>;
67
+ }
68
+ export declare function buildChartModel({ options, size, renderers, hidden, }: BuildModelInput): ChartModel | null;
69
+ export { isBand, isContinuous };