@pushwoosh/kit-charts 0.0.9 → 0.0.11

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.
@@ -356,9 +356,11 @@ and pass numbers through the chart's `numberFormat`.
356
356
  Inline markup in a template is rendered rather than stripped, so the default
357
357
  Highcharts `pointFormat` arrives looking like itself. The whitelist is `<br>`,
358
358
  `<b>`/`<strong>`, `<i>`/`<em>` and `<span>` carrying a `style` of `color`,
359
- `font-size`, `font-weight` or `font-style`; anything else is dropped and its text
360
- kept. Nothing is parsed as HTML — the tags become React elements and a filled token
361
- is always a text child, so a series name out of the API cannot carry markup in.
359
+ `font-size`, `font-weight` or `font-style`. Anything else loses its tag and keeps
360
+ its text, so `<script>bad()</script>` prints a visible `bad()` — nothing runs, but
361
+ nothing disappears either. Nothing is parsed as HTML: the tags become React elements
362
+ and a filled token is always a text child, so a series name out of the API cannot
363
+ carry markup in.
362
364
  A token may sit inside the `style` attribute, as `{point.color}` does, and the
363
365
  filled value is checked against a plain-CSS pattern before it is used.
364
366
 
@@ -14,6 +14,8 @@ const ANCHOR = {
14
14
  center: 'middle',
15
15
  right: 'end'
16
16
  };
17
+ /** `style.textAlign` wins over the anchor the axis derives from its own geometry. */
18
+ const anchorFor = (style, fallback) => style?.textAlign && ANCHOR[style.textAlign] || fallback;
17
19
  /** What a tick draws: its own node if a formatter made one, its text otherwise. */
18
20
  const tickContent = tick => {
19
21
  if (tick.node !== undefined && tick.node !== null) {
@@ -33,7 +35,7 @@ function TickLabel({
33
35
  const text = _jsx("text", {
34
36
  x: x,
35
37
  y: y,
36
- textAnchor: anchor,
38
+ textAnchor: anchorFor(style, anchor),
37
39
  ...textProps(style),
38
40
  children: children
39
41
  });
@@ -89,7 +91,7 @@ function AxisTitle({
89
91
  return _jsx("text", {
90
92
  x: at.x,
91
93
  y: at.y,
92
- textAnchor: rotation === 0 ? anchor : 'middle',
94
+ textAnchor: rotation === 0 ? anchorFor(title.style, anchor) : 'middle',
93
95
  transform: rotation === 0 ? undefined : `rotate(${rotation} ${at.x} ${at.y})`,
94
96
  ...textProps(title.style),
95
97
  children: title.text
@@ -16,6 +16,11 @@ import { computeStacks } from '../stack/stack';
16
16
  /** Key for a switched-off series, or for one of its points. */
17
17
  export const hiddenKey = (seriesIndex, pointIndex) => pointIndex === undefined ? `${seriesIndex}` : `${seriesIndex}:${pointIndex}`;
18
18
  const DEFAULT_SPACING = [10, 10, 15, 10];
19
+ /** `spacingTop` and friends each override their side of the `spacing` tuple. */
20
+ const resolveSpacing = chart => {
21
+ const [top, right, bottom, left] = chart?.spacing ?? DEFAULT_SPACING;
22
+ return [chart?.spacingTop ?? top, chart?.spacingRight ?? right, chart?.spacingBottom ?? bottom, chart?.spacingLeft ?? left];
23
+ };
19
24
  const isBand = scale => scale.kind === 'band';
20
25
  const isContinuous = scale => scale.kind === 'linear' || scale.kind === 'time';
21
26
  const asText = label => ({
@@ -332,7 +337,9 @@ export function buildChartModel({
332
337
  }) => {
333
338
  points.forEach(point => {
334
339
  if (typeof point.x === 'string') {
335
- point.band = point.x;
340
+ // Highcharts reads a string in `[name, value]` as the point's name and
341
+ // places it by index; we key by category, and fall back where it misses.
342
+ point.band = !explicitCategories || categories.includes(point.x) ? point.x : categories[point.index] ?? point.x;
336
343
  return;
337
344
  }
338
345
  if (!explicitCategories) {
@@ -342,6 +349,8 @@ export function buildChartModel({
342
349
  point.band = categories[Number(point.x)] ?? categories[point.index] ?? String(point.x);
343
350
  });
344
351
  });
352
+ // A band still outside the list extends the axis: a surplus point is data, and
353
+ // dropping it would lose it without a word.
345
354
  resolved.forEach(({
346
355
  points
347
356
  }) => {
@@ -405,7 +414,7 @@ export function buildChartModel({
405
414
  max: acc.x.max + pad
406
415
  } : acc.x;
407
416
  const yDomains = acc.y;
408
- const spacing = options.chart?.spacing ?? DEFAULT_SPACING;
417
+ const spacing = resolveSpacing(options.chart);
409
418
  const [spaceTop, spaceRight, spaceBottom, spaceLeft] = spacing;
410
419
  const labelsOnTop = xAxisOptions.opposite === true;
411
420
  const labelStyle = xAxisOptions.labels?.style;
@@ -29,6 +29,11 @@ export interface ChartRootOptions {
29
29
  width?: number | string | null;
30
30
  backgroundColor?: string;
31
31
  spacing?: Spacing;
32
+ /** One side of `spacing`, which it overrides — the Highcharts pair. */
33
+ spacingTop?: number;
34
+ spacingRight?: number;
35
+ spacingBottom?: number;
36
+ spacingLeft?: number;
32
37
  marginTop?: number;
33
38
  marginRight?: number;
34
39
  marginBottom?: number;
@@ -81,10 +86,8 @@ export interface AxisLabelsOptions {
81
86
  hint?: (ctx: AxisLabelContext) => string | undefined;
82
87
  allowOverlap?: boolean;
83
88
  align?: 'left' | 'center' | 'right';
84
- rotation?: number;
85
89
  x?: number;
86
90
  y?: number;
87
- padding?: number;
88
91
  style?: TextStyle;
89
92
  }
90
93
  /** `zIndex` at or above this draws over the series instead of under it. */
@@ -163,7 +166,6 @@ export interface LegendOptions<TSeriesMeta = unknown> {
163
166
  align?: 'left' | 'center' | 'right';
164
167
  verticalAlign?: 'top' | 'middle' | 'bottom';
165
168
  layout?: 'horizontal' | 'vertical';
166
- margin?: number;
167
169
  x?: number;
168
170
  y?: number;
169
171
  itemStyle?: TextStyle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/kit-charts",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Small React chart library on SVG, with a Highcharts-shaped configuration model",
5
5
  "license": "MIT",
6
6
  "repository": {