# KptChart (kpt-chart)
An SVG chart in plain Angular (signals, zoneless), with no Chart.js/D3-style dependency.
The computation core lives in `@konce-pt/chart` - plain TypeScript, tested, shared with the React port.
Import: `import { KptChart } from '@konce-pt/angular/charts';`
## Chart types (config.type)
- `line` - a line chart; interpolation `linear` | `cubic` | `cubic-monotonic`; `area?: boolean`, `points?: boolean`,
`crosshair?: boolean` (hovering a point -> a vertical guide + a highlighted pill on the X axis label)
- `bar` - a bar chart; `orientation: 'vertical' | 'horizontal'`, `borderRadius?: px`
- `pie` - a pie chart
- `doughnut` - a doughnut; `innerRadius?: 0..1` (default 0.6)
- `polarArea` - equal angles, the radius proportional to the value
- `radar` - radial axes + a polygon per series
## Value axis and stacking (line, bar)
- `valueAxis?: { zero?, min?, max? }` - the value axis starts at zero by default, so a bar and the area under a line
show the size directly. `zero: false` fits the axis to the data (a weight of 79-90 kg is no longer a flat line under
the ceiling); `min` / `max` pin an end of the axis exactly and win over `zero` - a value beyond a pinned end is
cut at the edge. Bars and areas grow from zero, or from the end of the axis nearer to it
- `stacked?: boolean` - stacked series: bars on top of each other in one band per category (positive values up,
negative down; only the outer segment is rounded), lines as running totals with a band under each one (with
`area`). The axis covers the totals; the tooltip shows the values of the series, not the totals
- The rules live in `@konce-pt/chart`: `axisScale`, `chartScale`, `stackSeries`, `bandPath` (tested)
## Category axis (line, bar)
- When the category labels do not fit, the axis shows an even subset instead of overlapping text: all of
them if they fit, otherwise the densest split that fits - 9 labels (eighths of the axis), 5 (first, 1/4,
middle, 3/4, last), 3, and finally the two ends only. Horizontal bars apply the same rule to the rows
- The choice is made in on-screen pixels (the chart measures its container), so a narrow column shows fewer
labels and a wide one more; the outer labels and the
crosshair pill are shifted inward so they never leave the chart
- A line chart marks every category with a small dot on the axis; the active one grows on hover. The full
name of any category stays in the crosshair pill and the tooltip
- The rules live in `@konce-pt/chart`: `axisLabelIndices`, `estimateLabelWidth`, `clampLabel` (tested)
## Inputs
- `config: KptChartConfig` (required) - a single object driving everything
- `width` / `height`: the aspect ratio (default 600x360); the chart fills the width of its container
The chart draws in the pixels of its container: a `ResizeObserver` measures the canvas width and the
viewBox follows it, the height comes from the `width`/`height` ratio. Lengths grow and shrink with the
container, while the text (axis labels, 14px by default) and the line weights stay real pixels - the
same in a 300px column and on a 3000px screen. `width`/`height` are therefore only the aspect ratio and the
size of the first frame before the measurement arrives (SSR); there is no need to scale them by hand.
## KptChartConfig (in brief)
- `labels: string[]`, `series: { name; data: number[]; color? }[]`
- `legend`: `{ display?, position: top|bottom|left|right, align: start|center|end, pointStyle: circle|rect|rectRot|triangle|line, title? }`
- `title` / `subtitle`: `{ display?, text, align, color?, font?, padding? }`
- `tooltip`: `{ enabled?, format?(ctx: {series,label,value}): string, motion?: boolean }`
- `animation`: `{ enabled?, duration=400, delay=0, stagger=60, update?: boolean, delta?: boolean }`
- `ariaLabel?`: string - the chart's accessible name; `description?`: string - the takeaway for a screen reader
## Interactions
- Line and bar: the pointer anywhere over the plot picks the nearest category; the tooltip lists every visible
series at that category and travels from category to category without fading out in between.
- Slice/radar point: hovering the element -> a tooltip (series, label, value).
- The bubble never leaves the chart: it is clamped by its real width, not by its center.
- Touch: a tap shows the tooltip at once; dragging a finger sideways scrubs across categories - the bubble
follows the finger on a stiff spring and the digits switch instantly instead of rolling. After the finger
lifts, the bubble stays for 2 s and then fades. The SVG sets `touch-action: pan-y pinch-zoom`, so a
vertical swipe still scrolls the page (a horizontal bar chart therefore answers taps, not vertical drags).
A finger can sweep across slices and radar points too; radar points have a 14 px hit area.
- The category switches only once the pointer passes the midpoint by a few pixels (`pickCategory` in
`@konce-pt/chart`), so a resting finger does not flicker between neighbours.
- Clicking the legend -> hide/show a series (pie/doughnut/polar: hide a slice) with the scale recomputed.
- Hovering the legend -> highlight that series, dim the rest.
## Animations
Line: `stroke-dasharray/offset`. Bars: `scaleY/scaleX` (origin at the axis). Slices/radar: `scale` from the center.
Stagger `delay = index * stagger`. Disabled by `animation.enabled=false` and by `prefers-reduced-motion`.
### Data updates (same chart, new values)
A new `config` with the same type, categories and series names is a data update, not a new chart. The values
travel as a wave from left to right (springs with a damped wobble, 70 ms per category), and a light sheen runs
with the wave front. Line and bar charts also keep the previous state on screen for 1.7 s: a dashed ghost,
up/down segments between old and new values (`--kpt-color-success` / `--kpt-color-danger`, override with
`--kpt-chart-delta-up` / `--kpt-chart-delta-down`) and the difference above each point that changed by 2% or
more. The value axis holds both states while the ghost is visible, then zooms to the new data. Sheen color:
`--kpt-chart-sheen` (default `--kpt-color-info`). `animation.update: false` - values jump; `animation.delta:
false` - the wave without ghost, segments, differences and sheen. Another chart shape (type, categories,
series) plays the regular entry animation.
### Tooltip motion
The bubble, the crosshair and the category pill travel to the next category (460 ms, emphasized curve), the
digits of the value roll on reels to the new number, the category name slides in from the direction of travel
and the target point of a line sends out a ripple. Leaving the chart fades the bubble out. `tooltip.motion:
false` - the bubble jumps.
The code-driven motion (data updates, tooltip) is off with `animation.enabled: false`, with
`provideKptMotion({ enabled: false })` and with the system "reduce motion" setting. The data table for screen
readers always reads the final values from `config`.
## Example
## Accessibility
The `