Skip to content

0.12.0

Choose a tag to compare

@github-actions github-actions released this 02 Dec 20:21
· 9 commits to main since this release
46eec97

What Chart.js does and nervure did not: events on marks, a tooltip you control, legend options, plugins, stack groups, colours worked out from values, point shapes, richer axes, line segments, and more ways to animate.

Added

  • Events on marks: onClick and onHover render options receive the point under the pointer (chart type, series, stack, segment, label, value, index, item of the spec, colour, DOM event); onHover gets null when the pointer leaves. Enter on a mark reached with the keyboard calls onClick. Works on xy, pie, scatter, radar, heatmap, waterfall, treemap, pack, funnel and every chart with tooltips. Vue @click / @hover, React onClick / onHover, point-click / point-hover events on <nervure-chart>.
  • Tooltip: tooltip: false, or { format, html, position } for every chart; html gets an escape helper and loses scripts and event attributes. showTooltip(series, index), hideTooltip() and setActive(series, index) on the handle.
  • Legend: legend takes { position: 'top' | 'bottom' | 'left' | 'right', align, onClick } (return false to keep a series); pie and radar take legend too. legendItems() on the handle, to write a legend of your own with toggle().
  • Plugins: plugins render option and registerPlugin(), with beforeDraw, afterDraw and onDestroy, the plot area, the hole of round charts and two layers, under and above the chart. nervure/plugins ships plotAreaBorder, centerLabel and emptyState, outside the main bundle.
  • Stack groups on xy charts: stack on a series. With stacked, bars sharing a stack pile up and the stacks stand side by side in each category, with a space between them, vertical or horizontal; stacked: 'percent' fills 100 % stack by stack, totals writes one total by stack, and the keyboard says the stack.
  • Colours from values: color and colors of a series take (value, index, category) => colour (for example red below zero); pie charts take color: (value, index, name) => colour and scatter charts color: (y, index, label) => colour. The legend and the exports use the first colour worked out. From code only, not from JSON.
  • Point shapes: dots: { shape, size } with circle, square, triangle, diamond, cross, star or rect-rot, on line and area points, scatter points (shape), radar corners (dots) and in the legend. On lines cut into segments, points take the colour of their segment; dashed lines and dashed segments have no points.
  • radius (corner radius of the bars) and barWidth (share of a category taken by its bars) on xy charts.
  • Axes: suggestedMin, suggestedMax, step, ticks, tickFormat(value, index) and grid (false, or { dashed, color }) on each axis of xy charts; scatter and bubbles take xAxis and yAxis with the same options (log scale included) and center: true for axes crossing at zero. New type AxisScale.
  • Lines: gaps: 'break' | 'join' | 'zero' for missing values of lines, areas and bands (break stays the default); segments draw a stretch of a series another way (dashed, color, opacity, label), such as a forecast, with every curve, areas, zoom, keyboard reading and export.
  • Animation: named easings (linear, ease, ease-in, ease-out, ease-in-out, bounce, elastic), loop: true to replay the entrance, and line: 'trace' | 'grow' | 'draw' for how the lines of xy charts come in. Nothing moves or loops for readers who ask for less motion.
  • Guide pages Events, Tooltip, Legend, Plugins, Series and bars, Axes, and Lines, gaps and segments; gallery samples bar_stack_groups and line_points (216 entries).

Changed

  • A tap opens the tooltip on touch screens. radar, heatmap and waterfall are read mark by mark with the keyboard.
  • The shared core grew with events, tooltip control and plugins: one chart alone is now 13 to 15 kB gzipped (was 11 to 13), lines and bars 24 kB, the one-file build 178 kB (budget 180 kB).