@pushwoosh/kit-charts 0.0.3 → 0.0.4

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.
@@ -62,7 +62,8 @@ Deliberate differences from Highcharts:
62
62
  `ChartOptions<TChartMeta, TSeriesMeta, TPointMeta>`.
63
63
  2. Formatters take a typed context **argument**; there is no `this`.
64
64
  3. Formatters return a `ReactNode`, never an HTML string. There is no `useHTML`.
65
- 4. `TooltipPoint` exposes `prev` and `next` neighbours directly.
65
+ 4. `TooltipPoint` exposes `prev` and `next` neighbours directly, and carries the
66
+ point's own `meta` as `pointMeta` beside the series' `meta`.
66
67
  5. Formatters see `ctx.chart.title` and `ctx.chart.meta`, not the option tree.
67
68
  6. No `credits` option.
68
69
  7. No `reflow`; resize is observed automatically.
@@ -338,6 +339,14 @@ the value wrapped in `valuePrefix`/`valueSuffix`. `formatter` replaces the body
338
339
  returns a `ReactNode`; `ctx.points[].prev`/`.next` carry the neighbouring points, so
339
340
  a delta needs no extra lookup. `shared: true` collects every series at the hovered x.
340
341
 
342
+ `ctx.points[].pointMeta` is the hovered point's own `meta` — the third type
343
+ parameter of `ChartOptions<TChartMeta, TSeriesMeta, TPointMeta>`, the same object
344
+ `onPointClick` reports. `meta` beside it stays the series'. A bar whose height is a
345
+ rate and whose tooltip has to name the two counts behind it needs the per-point
346
+ one; nothing else reaches it, because a formatter sees no option tree.
347
+
348
+ Golden case: `tooltip/point-meta`.
349
+
341
350
  Golden cases: `tooltip/callout`, `tooltip/shared-formatter`.
342
351
 
343
352
  ## Styling
@@ -362,6 +371,18 @@ A data label whose text carries `\n` is drawn as stacked lines, styled by
362
371
  `style` for the first and `secondaryStyle` for the rest. It is one label: it
363
372
  moves, measures and hides as one.
364
373
 
374
+ ## Areas
375
+
376
+ `fillColor` paints the body under the line, where the fill is a token of its own
377
+ rather than a wash of the series colour — `color` still keys the legend, the
378
+ markers and the tooltip swatch. Left unset the body is the series colour at
379
+ `fillOpacity`. Golden case: `area/fill-color`.
380
+
381
+ Both live on `SeriesOptionsBase`, as every series option does, but a renderer
382
+ reads only what it draws with: `fillColor` is read by `area` alone, `fillOpacity`
383
+ by `area` and `column`. On a pie or a heatmap they are typed and inert — the same
384
+ deal as `innerSize` on a line.
385
+
365
386
  ## The device pixel grid
366
387
 
367
388
  `useSize` floors the measured box, so the canvas is always a whole number of
@@ -12,8 +12,8 @@ export interface ClickedPoint<TPointMeta = unknown> {
12
12
  color: string;
13
13
  meta: TPointMeta;
14
14
  }
15
- export interface ChartProps<TChartMeta = unknown, TSeriesMeta = unknown> {
16
- options: ChartOptions<TChartMeta, TSeriesMeta>;
15
+ export interface ChartProps<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown> {
16
+ options: ChartOptions<TChartMeta, TSeriesMeta, TPointMeta>;
17
17
  renderers?: readonly AnySeriesRenderer[];
18
18
  isLoading?: boolean;
19
19
  empty?: ReactNode;
@@ -28,6 +28,6 @@ export interface ChartProps<TChartMeta = unknown, TSeriesMeta = unknown> {
28
28
  */
29
29
  onSeriesToggle?: (seriesIndex: number, visible: boolean, pointIndex?: number) => void;
30
30
  /** Called with the point nearest a click inside the plot; drill-down hangs off this. */
31
- onPointClick?: (point: ClickedPoint, event: ReactMouseEvent<SVGSVGElement>) => void;
31
+ onPointClick?: (point: ClickedPoint<TPointMeta>, event: ReactMouseEvent<SVGSVGElement>) => void;
32
32
  }
33
- export declare function Chart<TChartMeta = unknown, TSeriesMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta>): ReactElement;
33
+ export declare function Chart<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta, TPointMeta>): ReactElement;
@@ -409,6 +409,7 @@ function ChartBody({
409
409
  value: hit.value,
410
410
  index: hit.pointIndex,
411
411
  meta: series?.options.meta,
412
+ pointMeta: neighbours[hit.pointIndex]?.meta,
412
413
  prev: previous ? {
413
414
  x: previous.x,
414
415
  y: previous.y,
@@ -35,7 +35,7 @@ export interface TooltipNeighbour {
35
35
  y: number | null;
36
36
  index: number;
37
37
  }
38
- export interface TooltipPoint<TSeriesMeta = unknown> {
38
+ export interface TooltipPoint<TSeriesMeta = unknown, TPointMeta = unknown> {
39
39
  seriesIndex: number;
40
40
  seriesName: string;
41
41
  color: string;
@@ -44,16 +44,18 @@ export interface TooltipPoint<TSeriesMeta = unknown> {
44
44
  value: number | null;
45
45
  index: number;
46
46
  meta: TSeriesMeta | undefined;
47
+ /** The hovered point's own `meta` — what `onPointClick` reports, at hover time. */
48
+ pointMeta: TPointMeta | undefined;
47
49
  prev: TooltipNeighbour | undefined;
48
50
  next: TooltipNeighbour | undefined;
49
51
  }
50
- export interface TooltipContext<TChartMeta = unknown, TSeriesMeta = unknown> {
52
+ export interface TooltipContext<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown> {
51
53
  x: number | string;
52
- points: readonly TooltipPoint<TSeriesMeta>[];
54
+ points: readonly TooltipPoint<TSeriesMeta, TPointMeta>[];
53
55
  chart: {
54
56
  title: string | undefined;
55
57
  meta: TChartMeta | undefined;
56
58
  };
57
59
  }
58
- export type TooltipFormatter<TChartMeta = unknown, TSeriesMeta = unknown> = (ctx: TooltipContext<TChartMeta, TSeriesMeta>) => ReactNode;
59
- export type TooltipCellFormatter<TSeriesMeta = unknown> = (point: TooltipPoint<TSeriesMeta>) => ReactNode;
60
+ export type TooltipFormatter<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown> = (ctx: TooltipContext<TChartMeta, TSeriesMeta, TPointMeta>) => ReactNode;
61
+ export type TooltipCellFormatter<TSeriesMeta = unknown, TPointMeta = unknown> = (point: TooltipPoint<TSeriesMeta, TPointMeta>) => ReactNode;
@@ -175,36 +175,36 @@ export interface LegendOptions<TSeriesMeta = unknown> {
175
175
  symbolPadding?: number;
176
176
  labelFormatter?: LegendLabelFormatter<TSeriesMeta>;
177
177
  }
178
- export interface TooltipTableColumn<TChartMeta = unknown, TSeriesMeta = unknown> {
178
+ export interface TooltipTableColumn<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown> {
179
179
  /**
180
180
  * A function is resolved per hover, and one that returns `null` drops the whole
181
181
  * column: that is how a "vs the previous point" column names the date it
182
182
  * compares against and disappears on the first point, where there is none.
183
183
  */
184
- title?: string | TooltipFormatter<TChartMeta, TSeriesMeta>;
184
+ title?: string | TooltipFormatter<TChartMeta, TSeriesMeta, TPointMeta>;
185
185
  align?: 'left' | 'right';
186
- cell: TooltipCellFormatter<TSeriesMeta>;
186
+ cell: TooltipCellFormatter<TSeriesMeta, TPointMeta>;
187
187
  }
188
188
  /**
189
189
  * Lays the tooltip out as a table: a header line, a heading row, and one row per
190
190
  * series with its swatch. Use it when a point carries more than one figure —
191
191
  * a count and its share of the whole — and a single line would run them together.
192
192
  */
193
- export interface TooltipTableOptions<TChartMeta = unknown, TSeriesMeta = unknown> {
193
+ export interface TooltipTableOptions<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown> {
194
194
  /** The line above the table. Defaults to the formatted x. */
195
- header?: TooltipFormatter<TChartMeta, TSeriesMeta>;
195
+ header?: TooltipFormatter<TChartMeta, TSeriesMeta, TPointMeta>;
196
196
  /** Heading over the series-name column. */
197
197
  seriesTitle?: string;
198
- columns: readonly TooltipTableColumn<TChartMeta, TSeriesMeta>[];
198
+ columns: readonly TooltipTableColumn<TChartMeta, TSeriesMeta, TPointMeta>[];
199
199
  }
200
- export interface TooltipOptions<TChartMeta = unknown, TSeriesMeta = unknown> {
200
+ export interface TooltipOptions<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown> {
201
201
  enabled?: boolean;
202
202
  shared?: boolean;
203
- table?: TooltipTableOptions<TChartMeta, TSeriesMeta>;
203
+ table?: TooltipTableOptions<TChartMeta, TSeriesMeta, TPointMeta>;
204
204
  /** `callout` anchors a beaked bubble to the point; `box` floats near the cursor. */
205
205
  shape?: 'callout' | 'box';
206
206
  followPointer?: boolean;
207
- formatter?: TooltipFormatter<TChartMeta, TSeriesMeta>;
207
+ formatter?: TooltipFormatter<TChartMeta, TSeriesMeta, TPointMeta>;
208
208
  dateFormat?: string;
209
209
  valuePrefix?: string;
210
210
  valueSuffix?: string;
@@ -298,6 +298,8 @@ export interface SeriesOptionsBase<TSeriesMeta = unknown, TPointMeta = unknown>
298
298
  */
299
299
  borderPosition?: 'all' | 'top';
300
300
  fillOpacity?: number;
301
+ /** The body's own colour, where the fill is not a wash of the series colour. */
302
+ fillColor?: string;
301
303
  pointPadding?: number;
302
304
  groupPadding?: number;
303
305
  minPointLength?: number;
@@ -321,7 +323,7 @@ export interface ChartOptions<TChartMeta = unknown, TSeriesMeta = unknown, TPoin
321
323
  yAxis?: AxisOptions | readonly AxisOptions[];
322
324
  colorAxis?: ColorAxisOptions;
323
325
  legend?: LegendOptions<TSeriesMeta>;
324
- tooltip?: TooltipOptions<TChartMeta, TSeriesMeta>;
326
+ tooltip?: TooltipOptions<TChartMeta, TSeriesMeta, TPointMeta>;
325
327
  plotOptions?: PlotOptions<TSeriesMeta, TPointMeta>;
326
328
  series?: readonly SeriesOptionsBase<TSeriesMeta, TPointMeta>[];
327
329
  colors?: readonly string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-charts",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Small React chart library on SVG, with a Highcharts-shaped configuration model",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,3 +1,3 @@
1
1
  import { type ReactElement } from 'react';
2
2
  import { type ChartProps } from '../core/Chart/Chart';
3
- export declare function AreaChart<TChartMeta = unknown, TSeriesMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta>): ReactElement;
3
+ export declare function AreaChart<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta, TPointMeta>): ReactElement;
@@ -1,3 +1,3 @@
1
1
  import { type ReactElement } from 'react';
2
2
  import { type ChartProps } from '../core/Chart/Chart';
3
- export declare function ColumnChart<TChartMeta = unknown, TSeriesMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta>): ReactElement;
3
+ export declare function ColumnChart<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta, TPointMeta>): ReactElement;
@@ -1,3 +1,3 @@
1
1
  import { type ReactElement } from 'react';
2
2
  import { type ChartProps } from '../core/Chart/Chart';
3
- export declare function LineChart<TChartMeta = unknown, TSeriesMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta>): ReactElement;
3
+ export declare function LineChart<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta, TPointMeta>): ReactElement;
@@ -1,3 +1,3 @@
1
1
  import { type ReactElement } from 'react';
2
2
  import { type ChartProps } from '../core/Chart/Chart';
3
- export declare function PieChart<TChartMeta = unknown, TSeriesMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta>): ReactElement;
3
+ export declare function PieChart<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown>(props: ChartProps<TChartMeta, TSeriesMeta, TPointMeta>): ReactElement;
@@ -1,7 +1,7 @@
1
1
  import { type ReactElement } from 'react';
2
2
  import { type ChartProps } from '../core/Chart/Chart';
3
3
  import { type Stacking } from '../core/types/options';
4
- export interface StackedColumnChartProps<TChartMeta = unknown, TSeriesMeta = unknown> extends ChartProps<TChartMeta, TSeriesMeta> {
4
+ export interface StackedColumnChartProps<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown> extends ChartProps<TChartMeta, TSeriesMeta, TPointMeta> {
5
5
  stacking?: Stacking;
6
6
  }
7
- export declare function StackedColumnChart<TChartMeta = unknown, TSeriesMeta = unknown>(props: StackedColumnChartProps<TChartMeta, TSeriesMeta>): ReactElement;
7
+ export declare function StackedColumnChart<TChartMeta = unknown, TSeriesMeta = unknown, TPointMeta = unknown>(props: StackedColumnChartProps<TChartMeta, TSeriesMeta, TPointMeta>): ReactElement;
@@ -27,7 +27,7 @@ export const area = {
27
27
  return _jsxs("g", {
28
28
  children: [_jsx("path", {
29
29
  d: toAreaPath(slots),
30
- fill: color,
30
+ fill: ctx.series.fillColor ?? color,
31
31
  fillOpacity: ctx.series.fillOpacity ?? DEFAULT_FILL_OPACITY,
32
32
  stroke: "none"
33
33
  }), lineWidth ? _jsx("path", {