affiliate-charts

Affiliate dashboard charts as SVG strings — funnels, the waterfall from GGR to commission, daily series and KPI tiles, rendering under a strict CSP.

Available on: npm GitHub Project site

affiliate-charts draws charts for affiliate programmes as SVG strings. One call returns markup, in Node at build time or in the browser. Zero dependencies; the core and the funnel are 4.5 KB gzipped together.

The charts

  • Funnel — clicks to first deposits in counts, and deposits to revenue in money: the base of each event beside what the partner earned from it, with cancellations and rejected records on the same scale. A conversion funnel as SVG in three forms: bars, steps or the classic centred shape.
  • Waterfall — the waterfall from GGR to commission, step by step: totals stand on zero, each delta floats from where the running total stands.
  • Daily series — lines, an area or columns over days, at most two series on one value axis, with an optional comparison period.
  • KPI tiles and sparklines — a label, a value, a change coloured by whether it is good, and a trend; a 32 px sparkline for a table cell.
  • Rankings, part to whole, heatmaps and cohorts, meters and flows — bars by source, a 100% bar or a donut, cohort triangles, progress to the next tier, and a sankey from sources to registrations.

Built for a dashboard

  • Renders under a strict CSP. No style="", no <style>, no <script>, no data: — dashboard charts under a strict CSP such as default-src 'self', where most chart libraries break.
  • Small. A core plus one file per chart: the waterfall adds 1.1 KB to the core, the daily series 2.9 KB, rankings 0.9 KB.
  • Reads on a phone. Bars follow the width of their container; text keeps its pixel size.
  • Honest by construction. Steps are never summed, money and counts never share an axis, a missing rate is a dash and never 0%, and the library never formats or computes a number it shows: every label and value is your string.
  • Styleable. Bars take your brand colour, fitted for contrast on a light or a dark surface; text and lines use currentColor, and every mark has a class a stylesheet can recolour.

How to use it

Install with npm install affiliate-charts, import a chart file such as affiliate-charts/charts-funnel.js and pass it your steps — each with a label, a value and the display string you have already formatted:

const svg = Charts.funnel(steps, { title: 'Funnel' });

Bad input throws a TypeError — the library never repairs data. The same input gives the same bytes within a minor version.

Licence

MIT © 301ST. The live demo has every option wired to a control, in light and dark, with a width slider to watch the bars follow their container.