@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,109 @@
1
+ export interface ContainerProps {
2
+ $width: string;
3
+ $height: string;
4
+ $autoHeight: boolean;
5
+ $background: string | undefined;
6
+ $fontFamily: string;
7
+ $fontSize: string;
8
+ }
9
+ export declare const Container: import("styled-components").StyledComponent<"div", any, ContainerProps, never>;
10
+ export declare const ScrollBox: import("styled-components").StyledComponent<"div", any, {
11
+ $scrolls: boolean;
12
+ }, never>;
13
+ /**
14
+ * The y axes of a horizontally scrolling chart, drawn in their own layer over
15
+ * the scroll box so the plot slides under them instead of taking them with it —
16
+ * a row-label column is useless once it has scrolled off. Highcharts does the
17
+ * same with a second, fixed SVG.
18
+ */
19
+ export declare const PinnedAxes: import("styled-components").StyledComponent<"svg", any, {}, never>;
20
+ export declare const Canvas: import("styled-components").StyledComponent<"svg", any, {
21
+ $clickable?: boolean;
22
+ }, never>;
23
+ /**
24
+ * One series. Hiding it never drops it from the tree, so the change can play: the
25
+ * geometry transitions carry every shape to where the renderer put it — collapsed
26
+ * onto its own baseline, or rescaled by the axis the remaining series left behind —
27
+ * and the opacity mops up the rest. `d` is animatable in Chromium; the attribute
28
+ * transitions cover columns, cells and markers everywhere.
29
+ */
30
+ export declare const SeriesLayer: import("styled-components").StyledComponent<"g", any, {
31
+ $hidden: boolean;
32
+ $collapse: boolean;
33
+ $selfAnimated: boolean;
34
+ /** Opacity while another series is hovered, from `states.inactive`. */
35
+ $inactive?: number;
36
+ /** `series.animation`; the chart clock unless this series asked for its own. */
37
+ $motionMs: number;
38
+ $cursor: string;
39
+ }, never>;
40
+ export declare const LegendItemBox: import("styled-components").StyledComponent<"g", any, {
41
+ $off: boolean;
42
+ $interactive: boolean;
43
+ $hoverColor?: string;
44
+ $hoverWeight?: string;
45
+ }, never>;
46
+ /** The hint badge beside a title: a light square with a blue glyph, as in the CP. */
47
+ export declare const HintIcon: import("styled-components").StyledComponent<"g", any, {}, never>;
48
+ export declare const Centred: import("styled-components").StyledComponent<"div", any, {}, never>;
49
+ export interface TooltipBoxProps {
50
+ $x: number;
51
+ $y: number;
52
+ $padding: number;
53
+ $radius: number;
54
+ $borderColor: string;
55
+ $background: string;
56
+ $color: string;
57
+ $fontFamily: string;
58
+ $fontSize: string;
59
+ $whiteSpace: string;
60
+ $shadow: string;
61
+ }
62
+ export declare const TooltipBox: import("styled-components").StyledComponent<"div", any, TooltipBoxProps, never>;
63
+ export interface TailProps {
64
+ $left: number;
65
+ $size: number;
66
+ $color: string;
67
+ $below: boolean;
68
+ }
69
+ /** The callout beak, drawn as a CSS triangle so it inherits the box colour. */
70
+ export declare const Tail: import("styled-components").StyledComponent<"span", any, TailProps, never>;
71
+ export declare const TooltipTitle: import("styled-components").StyledComponent<"div", any, {}, never>;
72
+ export declare const TooltipRow: import("styled-components").StyledComponent<"div", any, {}, never>;
73
+ export declare const TooltipSwatch: import("styled-components").StyledComponent<"span", any, {
74
+ $color: string;
75
+ $round?: boolean;
76
+ }, never>;
77
+ export declare const TooltipName: import("styled-components").StyledComponent<"span", any, {}, never>;
78
+ export declare const TooltipValue: import("styled-components").StyledComponent<"span", any, {}, never>;
79
+ export declare const DEFAULTS: {
80
+ fontFamily: string;
81
+ fontSize: string;
82
+ border: string;
83
+ surface: string;
84
+ text: string;
85
+ tooltipSurface: string;
86
+ tooltipText: string;
87
+ };
88
+ /**
89
+ * The table layout of the tooltip. A heading row plus one row per series, so a
90
+ * count and its share line up in columns instead of running together on one line.
91
+ */
92
+ export declare const TooltipTable: import("styled-components").StyledComponent<"table", any, {}, never>;
93
+ export declare const TooltipHeadCell: import("styled-components").StyledComponent<"th", any, {
94
+ $align: "left" | "right";
95
+ }, never>;
96
+ export declare const TooltipCell: import("styled-components").StyledComponent<"td", any, {
97
+ $align: "left" | "right";
98
+ $muted?: boolean;
99
+ }, never>;
100
+ export declare const TooltipSeriesCell: import("styled-components").StyledComponent<"td", any, {}, never>;
101
+ /** Keeps the swatch on the baseline of the series name inside a table cell. */
102
+ export declare const TooltipSeriesInner: import("styled-components").StyledComponent<"span", any, {}, never>;
103
+ /** Separates the header line from the table under it. */
104
+ export declare const TooltipDivider: import("styled-components").StyledComponent<"div", any, {
105
+ $color: string;
106
+ }, never>;
107
+ /** The rectangle dragged out over the plot before the zoom is applied. */
108
+ export declare const ZoomBand: import("styled-components").StyledComponent<"rect", any, {}, never>;
109
+ export declare const ResetZoom: import("styled-components").StyledComponent<"button", any, {}, never>;
@@ -0,0 +1,227 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { Color } from '@pushwoosh/kit-constants';
3
+ import { HOVER_MS, MOTION_EASING, MOTION_MS } from '../animation/motion';
4
+ import { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from '../layout/measure-text';
5
+ import { DEFAULT_GRID_COLOR, DEFAULT_MUTED_TEXT_COLOR, DEFAULT_SURFACE_COLOR, DEFAULT_TEXT_COLOR, DEFAULT_TOOLTIP_SURFACE_COLOR, DEFAULT_TOOLTIP_TEXT_COLOR } from '../model/palette';
6
+ const MIN_HEIGHT = '160px';
7
+ const TOOLTIP_MAX_WIDTH = '360px';
8
+ const TOOLTIP_Z_INDEX = 2147483000;
9
+ export const Container = styled.div.withConfig({
10
+ displayName: "Container",
11
+ componentId: "sc-1pit1b9-0"
12
+ })(["position:relative;width:", ";height:", ";min-width:0;overflow:hidden;min-height:", ";background:", ";font-family:", ";font-size:", ";"], ({
13
+ $width
14
+ }) => $width, ({
15
+ $height
16
+ }) => $height, ({
17
+ $autoHeight
18
+ }) => $autoHeight ? MIN_HEIGHT : 'auto', ({
19
+ $background
20
+ }) => $background ?? 'transparent', ({
21
+ $fontFamily
22
+ }) => $fontFamily, ({
23
+ $fontSize
24
+ }) => $fontSize);
25
+ export const ScrollBox = styled.div.withConfig({
26
+ displayName: "ScrollBox",
27
+ componentId: "sc-1pit1b9-1"
28
+ })(["", ""], ({
29
+ $scrolls
30
+ }) => $scrolls ? css(["overflow-x:auto;overflow-y:hidden;"]) : '');
31
+ /**
32
+ * The y axes of a horizontally scrolling chart, drawn in their own layer over
33
+ * the scroll box so the plot slides under them instead of taking them with it —
34
+ * a row-label column is useless once it has scrolled off. Highcharts does the
35
+ * same with a second, fixed SVG.
36
+ */
37
+ export const PinnedAxes = styled.svg.withConfig({
38
+ displayName: "PinnedAxes",
39
+ componentId: "sc-1pit1b9-2"
40
+ })(["position:absolute;top:0;left:0;pointer-events:none;"]);
41
+ export const Canvas = styled.svg.withConfig({
42
+ displayName: "Canvas",
43
+ componentId: "sc-1pit1b9-3"
44
+ })(["display:block;touch-action:none;cursor:", ";"], ({
45
+ $clickable
46
+ }) => $clickable ? 'pointer' : 'default');
47
+ /**
48
+ * One series. Hiding it never drops it from the tree, so the change can play: the
49
+ * geometry transitions carry every shape to where the renderer put it — collapsed
50
+ * onto its own baseline, or rescaled by the axis the remaining series left behind —
51
+ * and the opacity mops up the rest. `d` is animatable in Chromium; the attribute
52
+ * transitions cover columns, cells and markers everywhere.
53
+ */
54
+ export const SeriesLayer = styled.g.withConfig({
55
+ displayName: "SeriesLayer",
56
+ componentId: "sc-1pit1b9-4"
57
+ })(["opacity:", ";pointer-events:", ";cursor:", ";transition:opacity ", "ms ", ";", " @media (prefers-reduced-motion:reduce){transition:none;path,rect,circle,text{transition:none;}}"], ({
58
+ $hidden,
59
+ $inactive
60
+ }) => {
61
+ if ($hidden) {
62
+ return 0;
63
+ }
64
+ return $inactive ?? 1;
65
+ }, ({
66
+ $hidden
67
+ }) => $hidden ? 'none' : 'auto', ({
68
+ $cursor
69
+ }) => $cursor, ({
70
+ $motionMs
71
+ }) => $motionMs, MOTION_EASING, ({
72
+ $selfAnimated,
73
+ $motionMs
74
+ }) => $selfAnimated ? '' : css(["path,rect,circle,text{transition:d ", "ms ", ",x ", "ms ", ",y ", "ms ", ",width ", "ms ", ",height ", "ms ", ",cx ", "ms ", ",cy ", "ms ", ",opacity ", "ms ", ";}"], $motionMs, MOTION_EASING, $motionMs, MOTION_EASING, $motionMs, MOTION_EASING, $motionMs, MOTION_EASING, $motionMs, MOTION_EASING, $motionMs, MOTION_EASING, $motionMs, MOTION_EASING, $motionMs, MOTION_EASING));
75
+ export const LegendItemBox = styled.g.withConfig({
76
+ displayName: "LegendItemBox",
77
+ componentId: "sc-1pit1b9-5"
78
+ })(["cursor:", ";opacity:", ";transition:opacity ", "ms ", ";&:hover{opacity:", ";", "}&:focus{outline:none;}&:focus-visible{outline:2px solid ", ";outline-offset:2px;}"], ({
79
+ $interactive
80
+ }) => $interactive ? 'pointer' : 'default', ({
81
+ $off
82
+ }) => $off ? 0.4 : 1, MOTION_MS, MOTION_EASING, ({
83
+ $off,
84
+ $interactive
85
+ }) => {
86
+ if (!$interactive) {
87
+ return $off ? 0.4 : 1;
88
+ }
89
+ return $off ? 0.6 : 0.75;
90
+ }, ({
91
+ $hoverColor,
92
+ $hoverWeight
93
+ }) => $hoverColor || $hoverWeight ? css(["text{", " ", "}"], $hoverColor ? `fill: ${$hoverColor};` : '', $hoverWeight ? `font-weight: ${$hoverWeight};` : '') : '', Color.PRIMARY);
94
+ /** The hint badge beside a title: a light square with a blue glyph, as in the CP. */
95
+ export const HintIcon = styled.g.withConfig({
96
+ displayName: "HintIcon",
97
+ componentId: "sc-1pit1b9-6"
98
+ })(["cursor:help;rect{fill:", ";transition:fill ", "ms ", ";}text{fill:", ";font-weight:700;transition:fill ", "ms ", ";}&:hover rect,&:focus-visible rect{fill:", ";}&:hover text,&:focus-visible text{fill:", ";}&:focus{outline:none;}&:focus-visible{outline:2px solid ", ";outline-offset:2px;}"], Color.BRIGHT_LIGHT, HOVER_MS, MOTION_EASING, Color.PRIMARY, HOVER_MS, MOTION_EASING, Color.PRIMARY, DEFAULT_SURFACE_COLOR, Color.PRIMARY);
99
+ export const Centred = styled.div.withConfig({
100
+ displayName: "Centred",
101
+ componentId: "sc-1pit1b9-7"
102
+ })(["display:flex;align-items:center;justify-content:center;width:100%;height:100%;font-size:", ";color:", ";"], DEFAULT_FONT_SIZE, DEFAULT_MUTED_TEXT_COLOR);
103
+ export const TooltipBox = styled.div.withConfig({
104
+ displayName: "TooltipBox",
105
+ componentId: "sc-1pit1b9-8"
106
+ })(["position:fixed;z-index:", ";top:", ";left:", ";max-width:", ";padding:", ";border:1px solid ", ";border-radius:", ";background:", ";box-shadow:", ";font-family:", ";font-size:", ";line-height:1.45;color:", ";white-space:", ";pointer-events:none;"], TOOLTIP_Z_INDEX, ({
107
+ $y
108
+ }) => `${$y}px`, ({
109
+ $x
110
+ }) => `${$x}px`, TOOLTIP_MAX_WIDTH, ({
111
+ $padding
112
+ }) => `${$padding}px`, ({
113
+ $borderColor
114
+ }) => $borderColor, ({
115
+ $radius
116
+ }) => `${$radius}px`, ({
117
+ $background
118
+ }) => $background, ({
119
+ $shadow
120
+ }) => $shadow, ({
121
+ $fontFamily
122
+ }) => $fontFamily, ({
123
+ $fontSize
124
+ }) => $fontSize, ({
125
+ $color
126
+ }) => $color, ({
127
+ $whiteSpace
128
+ }) => $whiteSpace);
129
+ /** The callout beak, drawn as a CSS triangle so it inherits the box colour. */
130
+ export const Tail = styled.span.withConfig({
131
+ displayName: "Tail",
132
+ componentId: "sc-1pit1b9-9"
133
+ })(["position:absolute;", " left:", ";width:0;height:0;border-right:", " solid transparent;border-left:", " solid transparent;", ""], ({
134
+ $below,
135
+ $size
136
+ }) => $below ? `top: -${$size}px;` : `bottom: -${$size}px;`, ({
137
+ $left,
138
+ $size
139
+ }) => `${$left - $size}px`, ({
140
+ $size
141
+ }) => `${$size}px`, ({
142
+ $size
143
+ }) => `${$size}px`, ({
144
+ $below,
145
+ $size,
146
+ $color
147
+ }) => $below ? `border-bottom: ${$size}px solid ${$color};` : `border-top: ${$size}px solid ${$color};`);
148
+ export const TooltipTitle = styled.div.withConfig({
149
+ displayName: "TooltipTitle",
150
+ componentId: "sc-1pit1b9-10"
151
+ })(["margin:0 0 4px;font-weight:600;"]);
152
+ export const TooltipRow = styled.div.withConfig({
153
+ displayName: "TooltipRow",
154
+ componentId: "sc-1pit1b9-11"
155
+ })(["display:flex;align-items:center;gap:6px;"]);
156
+ export const TooltipSwatch = styled.span.withConfig({
157
+ displayName: "TooltipSwatch",
158
+ componentId: "sc-1pit1b9-12"
159
+ })(["display:inline-block;flex:0 0 auto;width:8px;height:8px;border-radius:", ";background:", ";"], ({
160
+ $round
161
+ }) => $round ? '50%' : '2px', ({
162
+ $color
163
+ }) => $color);
164
+ export const TooltipName = styled.span.withConfig({
165
+ displayName: "TooltipName",
166
+ componentId: "sc-1pit1b9-13"
167
+ })(["opacity:0.7;"]);
168
+ export const TooltipValue = styled.span.withConfig({
169
+ displayName: "TooltipValue",
170
+ componentId: "sc-1pit1b9-14"
171
+ })(["margin-left:auto;font-weight:600;"]);
172
+ export const DEFAULTS = {
173
+ fontFamily: DEFAULT_FONT_FAMILY,
174
+ fontSize: DEFAULT_FONT_SIZE,
175
+ border: DEFAULT_GRID_COLOR,
176
+ surface: DEFAULT_SURFACE_COLOR,
177
+ text: DEFAULT_TEXT_COLOR,
178
+ tooltipSurface: DEFAULT_TOOLTIP_SURFACE_COLOR,
179
+ tooltipText: DEFAULT_TOOLTIP_TEXT_COLOR
180
+ };
181
+ /**
182
+ * The table layout of the tooltip. A heading row plus one row per series, so a
183
+ * count and its share line up in columns instead of running together on one line.
184
+ */
185
+ export const TooltipTable = styled.table.withConfig({
186
+ displayName: "TooltipTable",
187
+ componentId: "sc-1pit1b9-15"
188
+ })(["border-collapse:collapse;width:100%;"]);
189
+ export const TooltipHeadCell = styled.th.withConfig({
190
+ displayName: "TooltipHeadCell",
191
+ componentId: "sc-1pit1b9-16"
192
+ })(["padding:0 0 6px;text-align:", ";font-weight:400;white-space:nowrap;opacity:0.6;&:not(:first-child){padding-left:16px;}"], ({
193
+ $align
194
+ }) => $align);
195
+ export const TooltipCell = styled.td.withConfig({
196
+ displayName: "TooltipCell",
197
+ componentId: "sc-1pit1b9-17"
198
+ })(["padding:3px 0 0;text-align:", ";white-space:nowrap;opacity:", ";&:not(:first-child){padding-left:16px;}"], ({
199
+ $align
200
+ }) => $align, ({
201
+ $muted
202
+ }) => $muted ? 0.6 : 1);
203
+ export const TooltipSeriesCell = styled.td.withConfig({
204
+ displayName: "TooltipSeriesCell",
205
+ componentId: "sc-1pit1b9-18"
206
+ })(["padding:3px 0 0;white-space:nowrap;"]);
207
+ /** Keeps the swatch on the baseline of the series name inside a table cell. */
208
+ export const TooltipSeriesInner = styled.span.withConfig({
209
+ displayName: "TooltipSeriesInner",
210
+ componentId: "sc-1pit1b9-19"
211
+ })(["display:inline-flex;align-items:center;gap:6px;"]);
212
+ /** Separates the header line from the table under it. */
213
+ export const TooltipDivider = styled.div.withConfig({
214
+ displayName: "TooltipDivider",
215
+ componentId: "sc-1pit1b9-20"
216
+ })(["height:1px;margin:8px 0;background:", ";opacity:0.5;"], ({
217
+ $color
218
+ }) => $color);
219
+ /** The rectangle dragged out over the plot before the zoom is applied. */
220
+ export const ZoomBand = styled.rect.withConfig({
221
+ displayName: "ZoomBand",
222
+ componentId: "sc-1pit1b9-21"
223
+ })(["fill:", ";fill-opacity:0.12;pointer-events:none;"], Color.PRIMARY);
224
+ export const ResetZoom = styled.button.withConfig({
225
+ displayName: "ResetZoom",
226
+ componentId: "sc-1pit1b9-22"
227
+ })(["position:absolute;top:8px;right:8px;padding:4px 10px;border:1px solid ", ";border-radius:4px;background:", ";font-family:inherit;font-size:", ";color:", ";cursor:pointer;&:hover{border-color:", ";color:", ";}&:focus-visible{outline:2px solid ", ";outline-offset:2px;}"], DEFAULT_GRID_COLOR, DEFAULT_SURFACE_COLOR, DEFAULT_FONT_SIZE, DEFAULT_TEXT_COLOR, Color.PRIMARY, Color.PRIMARY, Color.PRIMARY);
@@ -0,0 +1,15 @@
1
+ import { Component, type ErrorInfo, type ReactNode } from 'react';
2
+ interface Props {
3
+ children: ReactNode;
4
+ fallback: ReactNode;
5
+ }
6
+ interface State {
7
+ failed: boolean;
8
+ }
9
+ export declare class ChartErrorBoundary extends Component<Props, State> {
10
+ constructor(props: Props);
11
+ static getDerivedStateFromError(): State;
12
+ componentDidCatch(error: Error, info: ErrorInfo): void;
13
+ render(): ReactNode;
14
+ }
15
+ export {};
@@ -0,0 +1,27 @@
1
+ import { Component } from 'react';
2
+ export class ChartErrorBoundary extends Component {
3
+ constructor(props) {
4
+ super(props);
5
+ this.state = {
6
+ failed: false
7
+ };
8
+ }
9
+ static getDerivedStateFromError() {
10
+ return {
11
+ failed: true
12
+ };
13
+ }
14
+ componentDidCatch(error, info) {
15
+ console.error('[kit-charts] Chart failed to render.', error, info.componentStack);
16
+ }
17
+ render() {
18
+ const {
19
+ failed
20
+ } = this.state;
21
+ const {
22
+ children,
23
+ fallback
24
+ } = this.props;
25
+ return failed ? fallback : children;
26
+ }
27
+ }
@@ -0,0 +1,11 @@
1
+ import { type ReactElement, type ReactNode } from 'react';
2
+ export interface HintedProps {
3
+ text: string;
4
+ children: ReactNode;
5
+ }
6
+ /**
7
+ * Anything that explains itself on hover or focus: the `i` beside a title, an
8
+ * axis label that needs a sentence. The explanation opens in the same callout a
9
+ * point uses, and Escape closes it.
10
+ */
11
+ export declare function Hinted({ text, children }: HintedProps): ReactElement;
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useRef, useState } from 'react';
3
+ import { Tooltip } from './Tooltip';
4
+ import { HINT_PADDING } from '../layout/metrics';
5
+ const HINT_TEXT_FONT_SIZE = '14px';
6
+ /**
7
+ * Anything that explains itself on hover or focus: the `i` beside a title, an
8
+ * axis label that needs a sentence. The explanation opens in the same callout a
9
+ * point uses, and Escape closes it.
10
+ */
11
+ export function Hinted({
12
+ text,
13
+ children
14
+ }) {
15
+ const ref = useRef(null);
16
+ const [at, setAt] = useState(null);
17
+ const open = useCallback(() => {
18
+ var _ref$current;
19
+ const box = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect();
20
+ if (box) {
21
+ setAt({
22
+ x: box.left + box.width / 2,
23
+ y: box.top
24
+ });
25
+ }
26
+ }, []);
27
+ const close = useCallback(() => setAt(null), []);
28
+ const onKeyDown = useCallback(event => {
29
+ if (event.key === 'Escape') {
30
+ close();
31
+ return;
32
+ }
33
+ if (event.key === 'Enter' || event.key === ' ') {
34
+ event.preventDefault();
35
+ open();
36
+ }
37
+ }, [close, open]);
38
+ return _jsxs(_Fragment, {
39
+ children: [_jsx("g", {
40
+ ref: ref,
41
+ role: "button",
42
+ tabIndex: 0,
43
+ "aria-label": text,
44
+ onPointerEnter: open,
45
+ onPointerLeave: close,
46
+ onFocus: open,
47
+ onBlur: close,
48
+ onKeyDown: onKeyDown,
49
+ children: children
50
+ }), at ? _jsx(Tooltip, {
51
+ at: at,
52
+ pointer: at,
53
+ options: {
54
+ padding: HINT_PADDING,
55
+ style: {
56
+ whiteSpace: 'normal',
57
+ fontSize: HINT_TEXT_FONT_SIZE
58
+ }
59
+ },
60
+ children: text
61
+ }) : null]
62
+ });
63
+ }
@@ -0,0 +1,15 @@
1
+ import { type ReactElement } from 'react';
2
+ import { type Rect, type Size, type Spacing } from '../types/geometry';
3
+ import { type LegendOptions } from '../types/options';
4
+ import { type LegendItem } from '../types/renderer';
5
+ interface LegendProps {
6
+ items: readonly LegendItem[];
7
+ options: LegendOptions | undefined;
8
+ plot: Rect;
9
+ size: Size;
10
+ spacing: Spacing;
11
+ renderLabel: (item: LegendItem) => React.ReactNode;
12
+ onToggle?: (item: LegendItem) => void;
13
+ }
14
+ export declare function Legend({ items, options, plot, size, spacing, renderLabel, onToggle, }: LegendProps): ReactElement | null;
15
+ export {};
@@ -0,0 +1,92 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { LegendItemBox } from './Chart.styles';
3
+ import { layoutLegend } from '../layout/legend-layout';
4
+ import { measureText, DEFAULT_FONT_SIZE } from '../layout/measure-text';
5
+ import { TEXT_BASELINE_SHIFT } from '../layout/metrics';
6
+ import { DEFAULT_TEXT_COLOR } from '../model/palette';
7
+ /** Clickable area around an item, so the pointer target is not the glyph alone. */
8
+ const HIT_PADDING = 4;
9
+ export function Legend({
10
+ items,
11
+ options,
12
+ plot,
13
+ size,
14
+ spacing,
15
+ renderLabel,
16
+ onToggle
17
+ }) {
18
+ if (!items.length || (options === null || options === void 0 ? void 0 : options.enabled) === false) {
19
+ return null;
20
+ }
21
+ const style = options === null || options === void 0 ? void 0 : options.itemStyle;
22
+ const symbolSize = (options === null || options === void 0 ? void 0 : options.symbolHeight) ?? 8;
23
+ const symbolRadius = (options === null || options === void 0 ? void 0 : options.symbolRadius) ?? 2;
24
+ const symbolPadding = (options === null || options === void 0 ? void 0 : options.symbolPadding) ?? 6;
25
+ const {
26
+ positions,
27
+ metrics
28
+ } = layoutLegend(items, options, plot, size, spacing);
29
+ const interactive = Boolean(onToggle);
30
+ const activate = item => () => onToggle === null || onToggle === void 0 ? void 0 : onToggle(item);
31
+ const onKeyDown = item => event => {
32
+ if (event.key !== 'Enter' && event.key !== ' ') {
33
+ return;
34
+ }
35
+ event.preventDefault();
36
+ onToggle === null || onToggle === void 0 || onToggle(item);
37
+ };
38
+ return _jsx("g", {
39
+ children: items.map((item, index) => {
40
+ var _options$itemHoverSty, _options$itemHoverSty2;
41
+ const {
42
+ x,
43
+ y
44
+ } = positions[index];
45
+ const labelX = x + symbolSize + symbolPadding;
46
+ const width = symbolSize + symbolPadding + measureText(item.label, style);
47
+ return _jsxs(LegendItemBox, {
48
+ "$off": !item.visible,
49
+ "$interactive": interactive,
50
+ "$hoverColor": options === null || options === void 0 || (_options$itemHoverSty = options.itemHoverStyle) === null || _options$itemHoverSty === void 0 ? void 0 : _options$itemHoverSty.color,
51
+ "$hoverWeight": options === null || options === void 0 || (_options$itemHoverSty2 = options.itemHoverStyle) === null || _options$itemHoverSty2 === void 0 ? void 0 : _options$itemHoverSty2.fontWeight,
52
+ role: interactive ? 'button' : undefined,
53
+ tabIndex: interactive ? 0 : undefined,
54
+ "aria-pressed": interactive ? item.visible : undefined,
55
+ "aria-label": interactive ? item.label : undefined,
56
+ onClick: interactive ? activate(item) : undefined,
57
+ onKeyDown: interactive ? onKeyDown(item) : undefined,
58
+ children: [interactive ? _jsx("rect", {
59
+ x: x - HIT_PADDING,
60
+ y: y - metrics.rowHeight / 2 - HIT_PADDING,
61
+ width: width + HIT_PADDING * 2,
62
+ height: metrics.rowHeight + HIT_PADDING * 2,
63
+ fill: "transparent"
64
+ }) : null, item.symbol === 'line' ? _jsx("line", {
65
+ x1: x,
66
+ x2: x + symbolSize,
67
+ y1: y,
68
+ y2: y,
69
+ stroke: item.color,
70
+ strokeWidth: 2,
71
+ strokeLinecap: "round"
72
+ }) : _jsx("rect", {
73
+ x: x,
74
+ y: y - symbolSize / 2,
75
+ width: (options === null || options === void 0 ? void 0 : options.symbolWidth) ?? symbolSize,
76
+ height: symbolSize,
77
+ rx: item.symbol === 'circle' ? symbolSize / 2 : symbolRadius,
78
+ fill: item.color
79
+ }), _jsx("text", {
80
+ x: labelX,
81
+ y: y + TEXT_BASELINE_SHIFT,
82
+ fill: (style === null || style === void 0 ? void 0 : style.color) ?? DEFAULT_TEXT_COLOR,
83
+ fontFamily: style === null || style === void 0 ? void 0 : style.fontFamily,
84
+ fontSize: (style === null || style === void 0 ? void 0 : style.fontSize) ?? DEFAULT_FONT_SIZE,
85
+ fontWeight: style === null || style === void 0 ? void 0 : style.fontWeight,
86
+ textDecoration: item.visible ? undefined : 'line-through',
87
+ children: renderLabel(item)
88
+ })]
89
+ }, `legend-${item.seriesIndex}-${item.label}`);
90
+ })
91
+ });
92
+ }
@@ -0,0 +1,17 @@
1
+ import { type ReactElement } from 'react';
2
+ import { type AxisModel } from '../model/build-model';
3
+ import { type Rect } from '../types/geometry';
4
+ export type PlotLayer = 'under' | 'over';
5
+ interface DecorationsProps {
6
+ plot: Rect;
7
+ axis: AxisModel;
8
+ along: 'x' | 'y';
9
+ layer: PlotLayer;
10
+ }
11
+ /**
12
+ * Plot bands and plot lines for one axis. They are drawn outside the axis
13
+ * component because a `zIndex` may put them over the series, which the axis
14
+ * itself never is.
15
+ */
16
+ export declare function PlotDecorations({ plot, axis, along, layer, }: DecorationsProps): ReactElement | null;
17
+ export {};