Signups over Month, one range against another
How does Signups in one stretch of Month compare with another?
Thirty months of signups, January 2023 to June 2025, beside a constant target of 13,500. One measure over time with a fixed goal, which is the starting point for a what-if projection: choose a growth rate and a horizon and see the month the target is reached.
Monthly Signups with a Target: 30 rows, 3 columns. Download the CSV
| Month | Signups | Signups Target |
|---|---|---|
| 2023-01-01 | 6200 | 13500 |
| 2023-02-01 | 6349 | 13500 |
| 2023-03-01 | 6501 | 13500 |
| 2023-04-01 | 6657 | 13500 |
| 2023-05-01 | 6817 | 13500 |
| 2023-06-01 | 6981 | 13500 |
| 2023-07-01 | 7148 | 13500 |
| 2023-08-01 | 7320 | 13500 |
| 2023-09-01 | 7495 | 13500 |
| 2023-10-01 | 7675 | 13500 |

How to read it
The ranges are aligned so you can read them point against point; where one line runs above the other, that range was higher. Over the whole span Signups went from 6.2K to 12.3K (+99%).
The chart's code (40 KB of JavaScript, D3)
It carries its own copies of these helpers: llmText, llmFrameTween, llmRangeBrush, llmSlider, llmNumberEntry, llmSegmented, llmPredictor, llmResponseCurves, llmTerritories, llmCutoff, llmContrast, llmSurvival, llmModelFormat, llmSubgroups, llmSegments, llmGlyphs, llmBreadcrumb, llmKeyframes, llmScrubber, llmValueColumn, llmValueRamp, llmFitLabel, llmThinLabels, llmFitAxisTicks, llmSymlog, llmClipOutliers, llmGeoZoom, llmGeoPointNotes, llmMapLabels, llmGeoMarks, llmPlaceUnit, llmWorldFit, llmRegionFit, llmFlowKey, llmFlowArcs, llmFrameFill, llmTooltip, llmSwarm, llmKde, llmOrbit3d, llmBoundedScale, llmBivariate, llmLegendLayout, llmPager, llmTableFrame, llmGrid, llmUtcDays, llmPeriodGrid, llmTileGrid, llmMermaid, llmDecomp, llmTopN, llmFlipDeck, llmFilterScope, llmDisplayName, llmThemeColors, llmWordCloud.
// bic:keyboard-marks
// English whatever the chart's language. A helper now asks for each one here and declares `// @requires llmText`:
d3.llmText = function (key, english, vars, count) {
var fill = function (s, vv) {
vv = vv || vars;
return String(s).replace(/\{([a-z][a-z0-9_]*)\}/g, function (m, k) {
return vv && Object.prototype.hasOwnProperty.call(vv, k) ? String(vv[k]) : m;
});
};
var en = fill(english);
var host = d3.llmText.host;
if (typeof host === 'function') {
try { var h = host(key, english, vars, count); if (typeof h === 'string' && h !== en && h !== english) return h; } catch (e) {}
}
var cat = d3.llmText._cat, lang = d3.llmText._lang;
if (cat && lang && Object.prototype.hasOwnProperty.call(cat, key)) {
var v = cat[key];
if (v && typeof v === 'object') {
var form = 'other';
try { form = new Intl.PluralRules(lang).select(typeof count === 'number' ? count : 0); } catch (e) {}
v = v[form] != null ? v[form] : v.other != null ? v.other : v.many;
}
var tv = vars;
if (vars && typeof vars.grain === 'string' && Object.prototype.hasOwnProperty.call(cat, 'd3.grain.' + vars.grain)
&& typeof cat['d3.grain.' + vars.grain] === 'string' && cat['d3.grain.' + vars.grain]) {
tv = {};
for (var vk in vars) if (Object.prototype.hasOwnProperty.call(vars, vk)) tv[vk] = vars[vk];
tv.grain = cat['d3.grain.' + vars.grain];
}
if (typeof v === 'string' && v) {
var t = fill(v, tv), left = String(t).match(/\{[a-z][a-z0-9_]*\}/g) || [];
if (left.every(function (x) { return en.indexOf(x) >= 0; })) return t;
}
}
return en;
};
d3.llmText._lang = null;
d3.llmText._cat = null;
d3.llmText.use = function (lang, catalog) {
d3.llmText._lang = lang || null; d3.llmText._cat = catalog || null;
d3.llmText.dates(lang);
};
d3.llmText.dates = function (lang) {
try {
var o = d3.llmText._d3orig;
if (!o) {
o = d3.llmText._d3orig = { timeFormat: d3.timeFormat, utcFormat: d3.utcFormat, timeParse: d3.timeParse,
utcParse: d3.utcParse, scaleTime: d3.scaleTime, scaleUtc: d3.scaleUtc };
}
var restore = function () { for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k) && o[k]) d3[k] = o[k]; };
var base = String(lang || '').toLowerCase().split(/[-_]/)[0];
if (!base || base === 'en' || typeof d3.timeFormatLocale !== 'function' || typeof Intl === 'undefined') { restore(); return; }
var mk = function (opts) { var x = { timeZone: 'UTC' }; for (var k in opts) x[k] = opts[k]; return new Intl.DateTimeFormat(lang, x); };
var months = [], shortMonths = [], days = [], shortDays = [], m, w;
var fM = mk({ month: 'long' }), fMs = mk({ month: 'short' }), fD = mk({ weekday: 'long' }), fDs = mk({ weekday: 'short' });
for (m = 0; m < 12; m++) { var dm = new Date(Date.UTC(2021, m, 15)); months.push(fM.format(dm)); shortMonths.push(fMs.format(dm)); }
for (w = 0; w < 7; w++) { var dw = new Date(Date.UTC(2021, 0, 3 + w)); days.push(fD.format(dw)); shortDays.push(fDs.format(dw)); } // 3 Jan 2021 is a Sunday
if (months[0] === 'January' && days[0] === 'Sunday') { restore(); return; } // no names for the language here: keep d3's
var L = d3.timeFormatLocale({ dateTime: '%x %X', date: '%Y-%m-%d', time: '%H:%M:%S', periods: ['AM', 'PM'],
days: days, shortDays: shortDays, months: months, shortMonths: shortMonths });
d3.timeFormat = L.format; d3.utcFormat = L.utcFormat; d3.timeParse = L.parse; d3.utcParse = L.utcParse;
var multi = function (utc) {
var F = utc ? L.utcFormat : L.format, P = utc ? 'utc' : 'time';
var iv = function (n) { return d3[P + n]; };
var fL = F('.%L'), fS = F(':%S'), fMi = F('%H:%M'), fH = F('%H:00'), fDy = F('%a %d'), fW = F('%b %d'), fMo = F('%B'), fY = F('%Y');
var wk = utc ? d3.utcSunday : d3.timeSunday;
return function (date) {
return (iv('Second')(date) < date ? fL : iv('Minute')(date) < date ? fS : iv('Hour')(date) < date ? fMi
: iv('Day')(date) < date ? fH : iv('Month')(date) < date ? (wk(date) < date ? fDy : fW)
: iv('Year')(date) < date ? fMo : fY)(date);
};
};
var wrap = function (make, utc) {
if (typeof make !== 'function') return make;
var dress = function (sc) {
var cp = sc.copy;
sc.tickFormat = function (count, spec) { return spec == null ? multi(utc) : (utc ? L.utcFormat : L.format)(spec); };
if (typeof cp === 'function') sc.copy = function () { return dress(cp.apply(sc, arguments)); };
return sc;
};
return function () { return dress(make.apply(this, arguments)); };
};
d3.scaleTime = wrap(o.scaleTime, false); d3.scaleUtc = wrap(o.scaleUtc, true);
} catch (e) {}
};
// @requires llmText
d3.llmRangeBrush = function (svg, cfg) {
cfg = cfg || {};
var xScale = cfg.xScale, snaps = cfg.snapValues || [];
var options = cfg.options || {};
var onWindow = typeof cfg.onWindow === 'function' ? cfg.onWindow : function () {};
var stateKey = cfg.stateKey || 'rangeWindow';
var noop = { window: function () { return null; }, set: function () {}, clear: function () {} };
if (!svg || !xScale || snaps.length < 2) return noop;
var x0 = cfg.x0 != null ? cfg.x0 : 0, x1 = cfg.x1 != null ? cfg.x1 : 100;
var y0 = cfg.y0 != null ? cfg.y0 : 0, y1 = cfg.y1 != null ? cfg.y1 : 100;
var fg = options.themeFg || '#252423';
var accent = options.themeAccent || fg;
var isDate = snaps[0] instanceof Date;
function num(v) { return +v; }
function px(v) { var p = +xScale(v); return p < x0 ? x0 : (p > x1 ? x1 : p); }
function nearestIdx(pxPos) {
var lo = 0, hi = snaps.length - 1;
while (hi - lo > 1) { var mid = (lo + hi) >> 1; if (px(snaps[mid]) < pxPos) lo = mid; else hi = mid; }
return (pxPos - px(snaps[lo])) <= (px(snaps[hi]) - pxPos) ? lo : hi;
}
function nearestValIdx(v) {
var n = num(isDate && !(v instanceof Date) ? new Date(v) : v);
if (isNaN(n)) return -1;
var best = 0, bd = Infinity;
for (var i = 0; i < snaps.length; i++) { var d = Math.abs(num(snaps[i]) - n); if (d < bd) { bd = d; best = i; } }
return best;
}
var ia = -1, ib = -1;
function tryRestore(pair) {
if (!pair || pair.length !== 2) return false;
var a = nearestValIdx(pair[0]), b = nearestValIdx(pair[1]);
if (a < 0 || b < 0 || a === b) return false;
ia = Math.min(a, b); ib = Math.max(a, b); return true;
}
if (!tryRestore(options.uiState && options.uiState[stateKey]) && !tryRestore(cfg.initial)) {
ia = Math.max(0, Math.round((snaps.length - 1) * 2 / 3)); ib = snaps.length - 1;
if (ia === ib) ia = ib - 1;
}
var g = svg.append('g').attr('class', 'llm-range-brush');
var shade = g.append('rect')
.attr('y', y0).attr('height', Math.max(0, y1 - y0))
.attr('fill', accent).attr('opacity', 0.10).attr('pointer-events', 'none');
function mkHandle(which) {
var side = which; // the end this handle stands for at rest: 'a' the start, 'b' the end (a drag may cross them)
var hg = g.append('g').attr('class', 'llm-range-handle').attr('cursor', 'ew-resize');
hg.append('line').attr('y1', y0).attr('y2', y1)
.attr('stroke', fg).attr('stroke-width', 1.25).attr('opacity', 0.85);
hg.append('circle').attr('cy', y0 + 8).attr('r', 5)
.attr('fill', fg).attr('stroke', 'none');
hg.append('rect').attr('y', y0).attr('height', Math.max(0, y1 - y0))
.attr('x', -9).attr('width', 18).attr('fill', 'transparent').attr('pointer-events', 'all');
hg.attr('role', 'slider').attr('tabindex', 0).attr('aria-orientation', 'horizontal')
.attr('aria-label', side === 'a' ? d3.llmText('d3.range.start', 'Start of the range') : d3.llmText('d3.range.end', 'End of the range'));
hg.on('keydown', function (event) {
var k = event && event.key, big = Math.max(1, Math.round(snaps.length / 10));
var lo = side === 'a' ? 0 : ia + 1, hi = side === 'a' ? ib - 1 : snaps.length - 1, cur = side === 'a' ? ia : ib, to;
if (k === 'ArrowRight' || k === 'ArrowUp') to = cur + 1;
else if (k === 'ArrowLeft' || k === 'ArrowDown') to = cur - 1;
else if (k === 'PageUp') to = cur + big;
else if (k === 'PageDown') to = cur - big;
else if (k === 'Home') to = lo;
else if (k === 'End') to = hi;
else return;
if (event && typeof event.preventDefault === 'function') event.preventDefault();
if (event && typeof event.stopPropagation === 'function') event.stopPropagation();
to = Math.max(lo, Math.min(hi, to));
if (to === cur) return;
if (side === 'a') ia = to; else ib = to;
paint();
rest();
});
hg.call(d3.drag()
.on('drag', function (event) {
var idx = nearestIdx(Math.max(x0, Math.min(x1, event.x)));
var changed = false;
if (which === 'a') { if (idx !== ia) { ia = idx; changed = true; } }
else { if (idx !== ib) { ib = idx; changed = true; } }
if (ia > ib) { var t = ia; ia = ib; ib = t; which = (which === 'a') ? 'b' : 'a'; } // hands crossed
if (changed) { paint(); onWindow(snaps[ia], snaps[ib], 'drag'); }
})
.on('end', function () { rest(); }));
return hg;
}
function ser(v) { return isDate ? new Date(num(v)).toISOString() : num(v); }
function rest() {
onWindow(snaps[ia], snaps[ib], 'end');
if (typeof options.setUiState === 'function') {
var st = {}; st[stateKey] = [ser(snaps[ia]), ser(snaps[ib])];
try { options.setUiState(st); } catch (e) { /* persistence is best-effort, never fatal */ }
}
}
var ha = mkHandle('a'), hb = mkHandle('b');
function paint() {
var pa = px(snaps[ia]), pb = px(snaps[ib]);
shade.attr('x', pa).attr('width', Math.max(0, pb - pa));
ha.attr('transform', 'translate(' + pa + ',0)');
hb.attr('transform', 'translate(' + pb + ',0)');
[[ha, ia], [hb, ib]].forEach(function (p) {
p[0].attr('aria-valuemin', 0).attr('aria-valuemax', snaps.length - 1).attr('aria-valuenow', p[1])
.attr('aria-valuetext', isDate ? new Date(num(snaps[p[1]])).toISOString().slice(0, 10) : String(snaps[p[1]]));
});
}
paint();
onWindow(snaps[ia], snaps[ib], 'init'); // first paint: the chart computes its KPIs once
return {
window: function () { return [snaps[ia], snaps[ib]]; },
set: function (a, b, fire) {
var na = nearestValIdx(a), nb = nearestValIdx(b);
if (na < 0 || nb < 0) return;
ia = Math.min(na, nb); ib = Math.max(na, nb); paint();
if (fire !== false) rest();
},
clear: function () { ia = 0; ib = snaps.length - 1; paint(); rest(); }
};
};
d3.llmTooltip = function (container, opts) {
opts = opts || {};
var gap = opts.gap == null ? 12 : opts.gap; // distance from the cursor
var edge = opts.edge == null ? 4 : opts.edge; // minimum distance from the container edge
var routed = false; // true while the HOST is showing our content
var lastContent = ''; // what to re-send if the host is driving
var lastEv = null; // where the cursor last was, for a re-fit
var host = (container && typeof container.node === 'function') ? container.node() : container;
var noop = { show: function () { return this; }, move: function () { return this; }, hide: function () { return this; },
html: function () { return this; }, text: function () { return this; }, node: null };
if (!host || !host.appendChild) return noop;
var mount = host;
if (mount.tagName && String(mount.tagName).toLowerCase() === 'svg' && mount.parentNode) {
mount = mount.parentNode;
}
if (!mount || !mount.appendChild) return noop;
try {
var pos = (typeof getComputedStyle === 'function') ? getComputedStyle(mount).position : '';
if (!pos || pos === 'static') mount.style.position = 'relative';
} catch (e) { /* jsdom / exec-gate: no layout engine, positioning is inert anyway */ }
var tip = mount.__llmTip;
if (!tip || tip.parentNode !== mount) {
tip = document.createElement('div');
tip.className = 'llm-tooltip';
tip.style.position = 'absolute';
tip.style.left = '0px';
tip.style.top = '0px';
tip.style.pointerEvents = 'none';
tip.style.visibility = 'hidden';
tip.style.zIndex = '20';
tip.style.boxSizing = 'border-box';
tip.style.whiteSpace = opts.wrap ? 'normal' : 'nowrap';
tip.style.background = 'rgba(255,255,255,0.97)';
tip.style.border = '1px solid rgba(0,0,0,0.28)';
tip.style.borderRadius = '4px';
tip.style.padding = '6px 9px';
tip.style.boxShadow = '0 2px 6px rgba(0,0,0,0.22)';
tip.style.color = '#222';
tip.style.fontSize = '12px';
mount.appendChild(tip);
mount.__llmTip = tip;
}
function hostTip() {
try {
var n = mount, guard = 0;
while (n && guard++ < 8) {
if (n.__lchHostTip && typeof n.__lchHostTip.show === 'function') return n.__lchHostTip;
n = n.parentNode;
}
} catch (e) { /* detached node / cross-document parent */ }
return null;
}
function metrics() {
var w = 0, h = 0, cw = 0, ch = 0;
try {
var r = mount.getBoundingClientRect();
cw = r.width; ch = r.height;
} catch (e) { /* fall through to the client* fallbacks */ }
if (!cw) cw = mount.clientWidth || 0;
if (!ch) ch = mount.clientHeight || 0;
w = tip.offsetWidth || 0;
h = tip.offsetHeight || 0;
return { w: w, h: h, cw: cw, ch: ch };
}
function local(ev) {
var x = 0, y = 0;
try {
var r = mount.getBoundingClientRect();
if (ev && ev.clientX != null) { x = ev.clientX - r.left; y = ev.clientY - r.top; }
} catch (e) {
if (ev && ev.clientX != null) { x = ev.clientX; y = ev.clientY; }
}
return { x: x, y: y };
}
function place(ev) {
var m = metrics();
if (!m.cw || !m.ch) return; // no layout to clamp against (exec gate)
var p = local(ev);
var left = p.x + gap;
if (left + m.w > m.cw - edge) left = p.x - gap - m.w;
if (left < edge) left = edge;
if (left + m.w > m.cw - edge) left = Math.max(edge, m.cw - m.w - edge);
var top = p.y + gap;
if (top + m.h > m.ch - edge) top = p.y - gap - m.h;
if (top < edge) top = edge;
if (top + m.h > m.ch - edge) top = Math.max(edge, m.ch - m.h - edge);
tip.style.left = Math.round(left) + 'px';
tip.style.top = Math.round(top) + 'px';
}
function looksLikeEvent(x) {
return !!x && typeof x === 'object' && !Array.isArray(x)
&& (typeof x.clientX === 'number' || typeof x.type === 'string' || ('target' in x));
}
function setContent(content, asText) {
if (Array.isArray(content)) content = content.map(function (x) { return x == null ? '' : String(x); }).join(asText ? ' ' : '<br/>');
lastContent = content == null ? '' : String(content);
if (!asText && typeof content === 'string' && content.indexOf('<') >= 0) tip.innerHTML = lastContent;
else tip.textContent = lastContent;
}
function setAndRefit(self, content, asText) {
setContent(content, asText);
if (routed) {
var hbSet = hostTip();
if (hbSet && hbSet.show(lastContent, lastEv) === true) return self;
routed = false; // the host let go: the tooltip is still on screen, so draw ours
return self.show(null, lastEv);
}
if (tip.style.visibility === 'visible') return self.show(null, lastEv);
return self;
}
return {
node: tip,
html: function (content) { return arguments.length ? setAndRefit(this, content, false) : lastContent; },
text: function (content) { return arguments.length ? setAndRefit(this, content, true) : (tip.textContent || ''); },
show: function (content, ev) {
if (looksLikeEvent(content) && !looksLikeEvent(ev)) { var swapped = content; content = ev; ev = swapped; }
if (ev) lastEv = ev;
if (content != null) setContent(content, false);
tip.style.maxWidth = 'none';
tip.style.visibility = 'visible'; // measurable BEFORE placing
var m = metrics();
if (m.ch && m.h + (2 * edge) > m.ch) {
var hbShow = hostTip();
if (hbShow && hbShow.show(lastContent, ev) === true) {
routed = true;
tip.style.visibility = 'hidden';
return this;
}
}
routed = false;
if (m.cw) tip.style.maxWidth = Math.max(80, m.cw - (2 * edge)) + 'px';
place(ev);
return this;
},
move: function (ev) {
if (ev) lastEv = ev;
if (routed) { var hbMove = hostTip(); if (hbMove) hbMove.move(ev); return this; }
if (tip.style.visibility === 'visible') place(ev);
return this;
},
hide: function () {
if (routed) { var hbHide = hostTip(); if (hbHide) hbHide.hide(); routed = false; }
tip.style.visibility = 'hidden';
return this;
}
};
};
d3.llmUtcDays = function (data, options) {
if (!data || !Array.isArray(data.columns) || !Array.isArray(data.rows)) return data;
if (options && options.dateCellsAreUtcDays === true) return data;
var DAY = 86400000;
var dateCols = [];
for (var ci = 0; ci < data.columns.length; ci++) {
var col = data.columns[ci];
if (col && /date|time/i.test(String(col.dataType || ''))) dateCols.push(ci);
}
if (!dateCols.length) return data;
function empty(v) { return v === null || v === undefined || v === ''; }
function localWall(t) { return t - new Date(t).getTimezoneOffset() * 60000; }
var fix = [];
for (var k = 0; k < dateCols.length; k++) {
var idx = dateCols[k], moved = 0, ok = true;
for (var r = 0; r < data.rows.length; r++) {
var row = data.rows[r];
if (!row || empty(row[idx])) continue;
var t = new Date(row[idx]).getTime();
if (!isFinite(t)) { ok = false; break; }
if (t % DAY === 0) continue;
if (localWall(t) % DAY !== 0) { ok = false; break; }
moved++;
}
if (ok && moved > 0) fix.push(idx);
}
if (!fix.length) return data;
var rows = data.rows.map(function (row) {
if (!row) return row;
var out = row.slice();
for (var f = 0; f < fix.length; f++) {
var j = fix[f];
if (empty(out[j])) continue;
var tt = new Date(out[j]).getTime();
if (tt % DAY === 0) continue;
out[j] = new Date(localWall(tt)).toISOString();
}
return out;
});
var result = {};
for (var key in data) if (Object.prototype.hasOwnProperty.call(data, key)) result[key] = data[key];
result.rows = rows;
return result;
};
// @requires llmDisplayName
d3.llmPeriodGrid = function (data, opts) {
opts = opts || {};
var cols = (data && data.columns) || [], rows = (data && data.rows) || [];
var idx = function (n) { for (var k = 0; k < cols.length; k++) if (cols[k] && cols[k].name === n) return k; return -1; };
var ti = opts.time ? idx(opts.time) : -1;
if (ti < 0) for (var a = 0; a < cols.length && ti < 0; a++) if (cols[a] && (cols[a].isTemporal || cols[a].dataType === 'DateTime')) ti = a;
var isInt = function (c) { return c && /^(int|integer|int64|int32|whole number)$/i.test(String(c.dataType || '')); };
var counts = Array.isArray(opts.counts) ? opts.counts.slice()
: cols.filter(function (c) { return c && c.isMeasure && isInt(c) && String(c.name).indexOf('__') !== 0; }).map(function (c) { return c.name; });
var name = function (n) { return d3.llmDisplayName(n); }; // llmDisplayName arrives through @requires
var stamped = [];
rows.forEach(function (r, i) { var d = ti >= 0 ? new Date(r[ti]) : null; if (d && !isNaN(d.getTime())) stamped.push({ t: d, i: i }); });
stamped.sort(function (x, y) { return x.t - y.t; });
var DAY = 864e5, gaps = [];
for (var s = 1; s < stamped.length; s++) { var g = (stamped[s].t - stamped[s - 1].t) / DAY; if (g > 0) gaps.push(g); }
gaps.sort(function (x, y) { return x - y; });
var med = gaps.length ? gaps[gaps.length >> 1] : null;
var grain = med == null ? null : med < 2 ? 'day' : med < 10 ? 'week' : med < 45 ? 'month' : med < 135 ? 'quarter' : 'year';
var step = function (d, k) {
return grain === 'day' ? d3.utcDay.offset(d, k) : grain === 'week' ? d3.utcDay.offset(d, 7 * k)
: grain === 'month' ? d3.utcMonth.offset(d, k) : grain === 'quarter' ? d3.utcMonth.offset(d, 3 * k) : d3.utcYear.offset(d, k);
};
var floorOf = function (d) {
return grain === 'day' || grain === 'week' ? Math.round(d.getTime() / DAY)
: grain === 'month' ? d.getUTCFullYear() * 12 + d.getUTCMonth()
: grain === 'quarter' ? d.getUTCFullYear() * 4 + Math.floor(d.getUTCMonth() / 3) : d.getUTCFullYear();
};
var periods = [], filled = 0;
if (!grain) stamped.forEach(function (p) { periods.push({ t: p.t, i: p.i, filled: false }); });
else {
var byKey = {};
stamped.forEach(function (p) { var k = floorOf(p.t); if (!(k in byKey)) byKey[k] = p; });
var first = stamped[0].t, lastKey = floorOf(stamped[stamped.length - 1].t);
for (var n = 0; n < 5000; n++) {
var t = step(first, n), k2 = floorOf(t);
if (grain === 'week') k2 = floorOf(t); // weeks walk in 7-day steps from the first stamp
if (k2 > lastKey + (grain === 'week' ? 3 : 0)) break;
var hit = byKey[k2];
if (!hit && grain === 'week') { for (var off = -3; off <= 3 && !hit; off++) hit = byKey[k2 + off]; }
if (hit) periods.push({ t: hit.t, i: hit.i, filled: false });
else { periods.push({ t: t, i: -1, filled: true }); filled++; }
}
}
var value = function (p, measure) {
var mi = idx(measure);
if (!p || mi < 0) return null;
if (p.filled) return counts.indexOf(measure) >= 0 ? 0 : null;
var v = rows[p.i][mi];
return v === null || v === undefined || v === '' || !isFinite(+v) ? null : +v;
};
var notes = [];
if (filled > 0) {
var unit = grain + (filled === 1 ? '' : 's');
var measures = cols.filter(function (c) { return c && c.isMeasure && String(c.name).indexOf('__') !== 0; }).map(function (c) { return c.name; });
var asZero = measures.filter(function (m) { return counts.indexOf(m) >= 0; }).map(name);
var asGap = measures.filter(function (m) { return counts.indexOf(m) < 0; }).map(name);
notes.push(filled + ' ' + unit + (filled === 1 ? ' has' : ' have') + ' no rows'
+ (asZero.length ? ': ' + asZero.join(', ') + ' ' + (asZero.length === 1 ? 'is' : 'are') + ' drawn as 0 there' : '')
+ (asGap.length ? (asZero.length ? ', ' : ': ') + asGap.join(', ') + ' as a gap' : ''));
}
var partial = { first: false, last: false };
var real = periods.filter(function (p) { return !p.filled; });
var countNames = counts.filter(function (m) { return idx(m) >= 0; });
if (real.length >= 4 && countNames.length) {
var fmtN = function (v) { try { return new Intl.NumberFormat('en-US', { maximumFractionDigits: 0 }).format(v); } catch (e) { return String(Math.round(v)); } };
var fmtD = function (d) { try { return d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' }); } catch (e) { return d.toISOString().slice(0, 10); } };
[['first', real[0], real.slice(1)], ['last', real[real.length - 1], real.slice(0, -1)]].forEach(function (e) {
var which = e[0], p = e[1], rest = e[2], says = [];
var cut = countNames.every(function (m) {
var others = rest.map(function (q) { return value(q, m); }).filter(function (v) { return v != null; }).sort(function (x, y) { return x - y; });
if (others.length < 3) return false;
var typical = others[others.length >> 1], v = value(p, m);
if (v == null || !(typical > 0) || !(v < typical / 2)) return false;
says.push(fmtN(v) + ' ' + name(m) + ' against a typical ' + fmtN(typical));
return true;
});
if (!cut) return;
partial[which] = true;
p.partial = true;
notes.push('the ' + which + ' ' + (grain || 'period') + ' (' + fmtD(p.t) + ') holds ' + says.join(' and ') + ' - it may be a partial ' + (grain || 'period'));
});
}
var edges = opts.edges === true || opts.edges === 'both' ? ['first', 'last'] : opts.edges === 'first' || opts.edges === 'last' ? [opts.edges] : [];
if (edges.length && real.length >= 2) {
var fmtE = function (d) { try { return d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short', year: 'numeric', timeZone: 'UTC' }); } catch (e) { return d.toISOString().slice(0, 10); } };
edges.forEach(function (which) {
if (partial[which]) return;
var p = which === 'first' ? real[0] : real[real.length - 1];
partial[which] = true;
p.partial = true;
notes.push('the ' + which + ' ' + (grain || 'period') + ' (' + fmtE(p.t) + ') may be a partial ' + (grain || 'period')
+ ': the data can ' + (which === 'first' ? 'start' : 'stop') + ' inside it');
});
}
var periodOf = function (d) { return d && d.p && typeof d.p === 'object' && 't' in d.p ? d.p : d; };
var isPartial = function (x) {
if (x instanceof Date || typeof x === 'number') {
var tx = +x;
for (var q = 0; q < periods.length; q++) if (+periods[q].t === tx) return !!periods[q].partial;
return false;
}
var p = periodOf(x);
return !!(p && p.partial);
};
var complete = periods.filter(function (p) { return !p.partial; });
var partialTag = function (x) { return isPartial(x) ? ' (partial ' + (grain || 'period') + ')' : ''; };
var markPartial = function (sel, pOf) {
if (!sel || typeof sel.each !== 'function') return sel;
var of = typeof pOf === 'function' ? pOf : periodOf;
sel.each(function (d) {
if (!isPartial(of(d))) return;
var el = d3.select(this), tag = String(this.tagName || '').toLowerCase();
el.classed('llm-period-partial', true);
if (tag === 'text' || tag === 'tspan') { el.attr('font-style', 'italic'); return; }
var fill = el.attr('fill'), stroke = el.attr('stroke');
if ((!stroke || stroke === 'none') && fill && fill !== 'none') el.attr('stroke', fill);
if (!(+el.attr('stroke-width') > 0)) el.attr('stroke-width', 1.5);
el.attr('stroke-dasharray', '3 2');
if (fill && fill !== 'none') {
var fo = el.attr('fill-opacity');
el.attr('fill-opacity', (fo == null || fo === '' || !isFinite(+fo) ? 1 : +fo) * 0.35);
}
});
return sel;
};
periods.forEach(function (q) { q.date = q.t; q.start = q.t; q.key = q.t; });
return {
grain: grain, periods: periods, value: value, filled: filled, notes: notes, counts: counts, partial: partial,
complete: complete, latestComplete: complete.length ? complete[complete.length - 1] : null,
firstComplete: complete.length ? complete[0] : null, isPartial: isPartial, partialTag: partialTag, markPartial: markPartial
};
};
d3.llmDisplayName = function (name) {
var s = name === null || name === undefined ? '' : String(name);
if (!s || /\s/.test(s)) return s.trim();
var t = s.replace(/[_]+/g, ' ');
if (/^[a-z0-9]+(?:-+[a-z0-9]+)+$/.test(t)) t = t.replace(/-+/g, ' ');
t = t.trim();
if (t !== s) return t.charAt(0).toUpperCase() + t.slice(1);
var parts = [];
var re = /[a-z][A-Z][a-z]+|[A-Z][a-z][A-Z](?![a-z])|[A-Z]+[0-9]+|[A-Z]+(?=[A-Z][a-z])|[A-Z]?[a-z]+|[A-Z]+|[0-9]+[A-Z](?![a-z0-9])|[0-9]+|[^A-Za-z0-9]+/g;
var m;
while ((m = re.exec(s)) !== null) {
if (m[0] === '') { re.lastIndex++; continue; }
parts.push(m[0]);
}
if (parts.length < 2 || parts.join('') !== s) return s;
var out = '';
for (var i = 0; i < parts.length; i++) {
var punct = /^[^A-Za-z0-9]+$/.test(parts[i]), prevPunct = i > 0 && /^[^A-Za-z0-9]+$/.test(parts[i - 1]);
out += i === 0 || punct || prevPunct ? parts[i] : ' ' + parts[i];
}
return out.trim();
};
d3.llmThemeColors = function (options) {
options = options || {};
var pick = function (v, d) { return (typeof v === 'string' && v && v !== 'transparent') ? v : d; };
var bg = pick(options.backgroundColor, pick(options.themeBg, '#ffffff'));
var fg = pick(options.themeFg, '#252423');
var hc = !!options.isHighContrast;
var pal = (options.palette && options.palette.length) ? options.palette.slice() : ['#4C78A8', '#F58518', '#54A24B', '#E45756', '#72B7B2', '#B279A2', '#FF9DA6', '#9D755D'];
var rgb = function (c) { var x = null; try { x = d3.rgb(c); } catch (e) { x = null; } return x && isFinite(x.r) ? x : d3.rgb(128, 128, 128); };
var lum = function (c) {
var r = rgb(c);
var f = function (v) { v /= 255; return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); };
return 0.2126 * f(r.r) + 0.7152 * f(r.g) + 0.0722 * f(r.b);
};
var contrast = function (a, b) { var x = lum(a) + 0.05, y = lum(b) + 0.05; return x > y ? x / y : y / x; };
var legible = function (col, floor) {
floor = floor || 3;
var c = d3.lab(rgb(col));
var step = lum(bg) > 0.5 ? -3 : 3; // a light background darkens the hue, a dark one lightens it
for (var i = 0; i < 34 && contrast(c.formatHex(), bg) < floor; i++) c.l = Math.max(0, Math.min(100, c.l + step));
return c.formatHex();
};
var good = hc ? pick(options.themeAccent, fg) : legible('#2e7d32');
var bad = hc ? fg : legible('#c62828');
var slot = function (value, n) {
var h = 2166136261, text = String(value);
for (var i = 0; i < text.length; i++) { h ^= text.charCodeAt(i); h = Math.imul(h, 16777619) >>> 0; }
return h % n;
};
var deltaE2000 = function (x, y) {
var rad = Math.PI / 180, L1 = x.l, a1 = x.a, b1 = x.b, L2 = y.l, a2 = y.a, b2 = y.b;
var C1 = Math.sqrt(a1 * a1 + b1 * b1), C2 = Math.sqrt(a2 * a2 + b2 * b2), Cm = (C1 + C2) / 2;
var G = 0.5 * (1 - Math.sqrt(Math.pow(Cm, 7) / (Math.pow(Cm, 7) + Math.pow(25, 7))));
var a1p = (1 + G) * a1, a2p = (1 + G) * a2;
var C1p = Math.sqrt(a1p * a1p + b1 * b1), C2p = Math.sqrt(a2p * a2p + b2 * b2);
var hp = function (bb, ap) { if (bb === 0 && ap === 0) return 0; var hh = Math.atan2(bb, ap) / rad; return hh < 0 ? hh + 360 : hh; };
var h1p = hp(b1, a1p), h2p = hp(b2, a2p);
var dLp = L2 - L1, dCp = C2p - C1p, dhp = 0;
if (C1p * C2p !== 0) { dhp = h2p - h1p; if (dhp > 180) dhp -= 360; else if (dhp < -180) dhp += 360; }
var dHp = 2 * Math.sqrt(C1p * C2p) * Math.sin(dhp * rad / 2);
var Lm = (L1 + L2) / 2, Cmp = (C1p + C2p) / 2, hm = h1p + h2p;
if (C1p * C2p !== 0) { if (Math.abs(h1p - h2p) > 180) hm += (hm < 360 ? 360 : -360); hm /= 2; }
var T = 1 - 0.17 * Math.cos((hm - 30) * rad) + 0.24 * Math.cos(2 * hm * rad) + 0.32 * Math.cos((3 * hm + 6) * rad) - 0.2 * Math.cos((4 * hm - 63) * rad);
var dTh = 30 * Math.exp(-Math.pow((hm - 275) / 25, 2));
var Rc = 2 * Math.sqrt(Math.pow(Cmp, 7) / (Math.pow(Cmp, 7) + Math.pow(25, 7)));
var Sl = 1 + 0.015 * Math.pow(Lm - 50, 2) / Math.sqrt(20 + Math.pow(Lm - 50, 2)), Sc = 1 + 0.045 * Cmp, Sh = 1 + 0.015 * Cmp * T;
var Rt = -Math.sin(2 * dTh * rad) * Rc;
var tl = dLp / Sl, tc = dCp / Sc, th = dHp / Sh;
return Math.sqrt(tl * tl + tc * tc + th * th + Rt * tc * th);
};
var order = null, pool = null, near = null;
var growOrder = function (count) {
if (!order) {
order = pal.map(function (c) { return rgb(c).formatHex(); });
var taken = order.map(function (c) { return d3.lab(c); });
var seenHex = {};
order.forEach(function (c) { seenHex[c] = 1; });
pool = [];
pal.forEach(function (c) {
var h = d3.hcl(rgb(c));
if (!isFinite(h.h)) h.h = 0;
var chroma = Math.max(isFinite(h.c) ? h.c : 0, 35);
[h.l, 38, 52, 66].forEach(function (L) {
for (var k = 1; k < 18; k++) {
var cc = d3.hcl((h.h + k * 20) % 360, chroma, L);
while (!cc.displayable() && cc.c > 20) cc.c -= 5;
if (!cc.displayable()) continue;
var hl = d3.hsl(cc).l;
if (!(hl > 0.15 && hl < 0.85)) continue;
var hx = cc.formatHex();
if (seenHex[hx]) continue;
seenHex[hx] = 1;
pool.push({ hex: hx, lab: d3.lab(hx) });
}
});
});
near = pool.map(function (q) {
var m = Infinity;
for (var t = 0; t < taken.length; t++) m = Math.min(m, deltaE2000(q.lab, taken[t]));
return m;
});
}
while (order.length < count && pool.length) {
var best = 0;
for (var q = 1; q < pool.length; q++) if (near[q] > near[best]) best = q;
var picked = pool.splice(best, 1)[0];
near.splice(best, 1);
order.push(picked.hex);
for (var r2 = 0; r2 < pool.length; r2++) near[r2] = Math.min(near[r2], deltaE2000(pool[r2].lab, picked.lab));
}
for (var round = 1; order.length < count && round < 40; round++) {
for (var e = 0; e < pal.length && order.length < count; e++) {
var hc = d3.hsl(pal[e]);
if (!isFinite(hc.h)) hc.h = 0;
var step = Math.ceil(round / 2) * 0.12 * (round % 2 ? 1 : -1);
hc.l = Math.max(0.12, Math.min(0.88, hc.l + step));
hc.h = (hc.h + round * 7) % 360;
var cx = hc.formatHex();
if (order.indexOf(cx) < 0) order.push(cx);
}
}
};
var extended = function (count) {
if (pal.length >= count) return pal.slice();
growOrder(count);
return pal.slice().concat(order.slice(pal.length, count));
};
var memory = function () {
var m = d3.__lchCategorySlots;
if (!m || !Array.isArray(m.groups)) { m = { groups: [] }; try { d3.__lchCategorySlots = m; } catch (e) { /* a frozen d3: no memory */ } }
return m;
};
var categories = function (values) {
var seen = {}, list = [];
(values || []).forEach(function (v) { var k = v === null || v === undefined ? '' : String(v); if (!seen[k]) { seen[k] = 1; list.push(k); } });
list.sort();
var mem = memory(), group = null, best = 0;
mem.groups.forEach(function (g) {
var shared = 0;
list.forEach(function (k) { if (Object.prototype.hasOwnProperty.call(g.slots, k)) shared++; });
if (shared > best) { best = shared; group = g; }
});
if (!group) {
group = { slots: {}, used: {}, size: 0 };
mem.groups.push(group);
if (mem.groups.length > 32) mem.groups.shift();
}
var fresh = list.filter(function (k) { return !Object.prototype.hasOwnProperty.call(group.slots, k); });
var total = group.size + fresh.length;
var cols = extended(Math.max(list.length, total));
var n = cols.length;
fresh.forEach(function (k) {
if (group.size >= 2000) return; // a category this long is not a palette's job: past it, a value is placed but not remembered
var i = 0;
while (group.used[i] && i < n) i++;
group.used[i] = 1;
group.slots[k] = i;
group.size++;
});
var map = {};
list.forEach(function (k) {
var i = Object.prototype.hasOwnProperty.call(group.slots, k) ? group.slots[k] : slot(k, n);
if (i >= cols.length) cols = extended(i + 1);
map[k] = cols[i % cols.length];
});
return function (v) {
var k = v === null || v === undefined ? '' : String(v);
return map[k] || cols[slot(k, n)];
};
};
return { bg: bg, fg: fg, good: good, bad: bad, categories: categories, legible: function (c) { return legible(c); }, contrast: contrast, palette: pal };
};
function render(container, data, options) {
data = d3.llmUtcDays(data, options);
container.replaceChildren();
const W = options.width, H = options.height;
const fg = options.themeFg || 'currentColor';
const culture = options.cultureCode || 'en-US';
const svg = d3.select(container).append('svg').attr('width', W).attr('height', H);
const noData = () => {
svg.append('text').attr('x', W / 2).attr('y', H / 2).attr('text-anchor', 'middle').attr('fill', fg)
.attr('font-size', 12).text((typeof options.noDataText === 'string' && options.noDataText) ? options.noDataText : 'No data to display');
};
const cols = data.columns;
const ti = cols.findIndex(c => c.name === 'Month');
const vi = cols.findIndex(c => c.name === 'Signups');
if (ti < 0) throw new Error('INVALID:column "Month" not found');
if (vi < 0) throw new Error('INVALID:column "Signups" not found');
if (!data.rows || data.rows.length < 1) { noData(); return; }
const G = d3.llmPeriodGrid(data, { time: 'Month', counts: ['Signups'], edges: true });
const periods = G.periods || [];
if (periods.length < 1) { noData(); return; }
const pd = p => { const d = p.start ?? p.date ?? p.key ?? p.d ?? p.t; return d instanceof Date ? d : new Date(d); };
// row indices per period, for cross-filter
const rowsByTime = new Map();
data.rows.forEach((r, i) => {
const t = new Date(r[ti]).getTime();
if (isNaN(t)) return;
if (!rowsByTime.has(t)) rowsByTime.set(t, []);
rowsByTime.get(t).push(i);
});
const pts = periods.map((p, i) => {
const v = +G.value(p, 'Signups');
return { p, i, d: pd(p), v: isFinite(v) ? v : 0, idxs: rowsByTime.get(pd(p).getTime()) || [] };
}).sort((a, b) => a.d - b.d);
const nf = new Intl.NumberFormat(culture, { maximumFractionDigits: 0 });
const nfc = new Intl.NumberFormat(culture, { notation: 'compact', maximumSignificantDigits: 3 });
const fmtVal = v => Math.abs(v) < 1 ? new Intl.NumberFormat(culture, { maximumSignificantDigits: 2 }).format(v) : nf.format(v);
const dfmt = new Intl.DateTimeFormat(culture, { month: 'short', year: 'numeric', timeZone: 'UTC' });
const fmtD = d => dfmt.format(d);
const pct = new Intl.NumberFormat(culture, { maximumFractionDigits: 1, signDisplay: 'exceptZero' });
const s = Math.max(0.8, Math.min(W / 790, H / 560));
const fs = Math.max(10, Math.round(11 * s));
const kpiH = Math.max(64, Math.round(H * 0.22));
const notes = (G.notes || []).map(String);
const noteLH = fs + 4;
const margin = { top: kpiH + 22, right: 20, bottom: 44 + notes.length * noteLH, left: 62 };
const plotW = W - margin.left - margin.right;
const plotH = H - margin.top - margin.bottom;
const x = d3.scaleUtc().domain(d3.extent(pts, p => p.d)).range([margin.left, margin.left + plotW]);
const maxV = d3.max(pts, p => p.v) || 1;
const y = d3.scaleLinear().domain([0, maxV]).nice().range([margin.top + plotH, margin.top]);
const tiles = [
{ key: 'latest', label: 'Latest' },
{ key: 'win', label: 'Window total' },
{ key: 'a', label: 'Point A' },
{ key: 'b', label: 'Point B' },
{ key: 'cmp', label: 'A to B change' }
];
const tw = (W - 16) / tiles.length;
const valFs = Math.max(14, Math.min(Math.round(24 * s), Math.round(kpiH * 0.36), Math.floor(tw / 7)));
const kg = svg.append('g').attr('class', 'kpi-strip');
const tileSel = {};
tiles.forEach((t, i) => {
const g = kg.append('g').attr('transform', `translate(${8 + i * tw},0)`);
if (i > 0) g.append('line').attr('x1', 0).attr('x2', 0).attr('y1', 8).attr('y2', kpiH - 8)
.attr('stroke', fg).attr('stroke-opacity', 0.2);
g.append('text').attr('x', 10).attr('y', 6 + fs).attr('fill', fg).attr('fill-opacity', 0.65).attr('font-size', fs).text(t.label);
const v = g.append('text').attr('x', 10).attr('y', 10 + fs + valFs).attr('fill', fg).attr('font-size', valFs).attr('font-weight', 600).text('');
const sub = g.append('text').attr('x', 10).attr('y', 14 + fs + valFs + fs).attr('fill', fg).attr('fill-opacity', 0.65).attr('font-size', fs).text('');
tileSel[t.key] = { v, sub };
});
const latestP = G.latestComplete || periods[periods.length - 1];
const latestPt = pts.find(q => q.p === latestP) || pts.find(q => q.d.getTime() === pd(latestP).getTime()) || pts[pts.length - 1];
const tag = q => { const t = G.partialTag ? G.partialTag(q.p) : ''; return t ? ' ' + t : ''; };
function computeKpis(a, b) {
const inWin = pts.filter(p => p.d >= a && p.d <= b);
const near = t => pts.reduce((m, p) => Math.abs(p.d - t) < Math.abs(m.d - t) ? p : m, pts[0]);
const pa = near(a), pb = near(b);
return {
latest: latestPt, windowAgg: d3.sum(inWin, p => p.v), n: inWin.length,
spanLabel: inWin.length + (inWin.length === 1 ? ' month' : ' months'),
pa, pb, va: pa.v, vb: pb.v,
deltaPct: pa.v === 0 ? 'n/a' : (pb.v - pa.v) / Math.abs(pa.v) * 100
};
}
function updateKpis(a, b) {
const k = computeKpis(a, b);
tileSel.latest.v.text(fmtVal(k.latest.v)); tileSel.latest.sub.text(fmtD(k.latest.d));
tileSel.win.v.text(fmtVal(k.windowAgg)); tileSel.win.sub.text(k.spanLabel);
tileSel.a.v.text(fmtVal(k.va)); tileSel.a.sub.text(fmtD(k.pa.d) + tag(k.pa));
tileSel.b.v.text(fmtVal(k.vb)); tileSel.b.sub.text(fmtD(k.pb.d) + tag(k.pb));
tileSel.cmp.v.text(k.deltaPct === 'n/a' ? 'n/a' : pct.format(k.deltaPct) + '%');
tileSel.cmp.sub.text('B vs A');
}
const gridG = svg.append('g');
gridG.selectAll('line').data(y.ticks(5)).join('line')
.attr('x1', margin.left).attr('x2', margin.left + plotW).attr('y1', d => y(d)).attr('y2', d => y(d))
.attr('stroke', fg).attr('stroke-opacity', 0.12).style('pointer-events', 'none');
const xAxis = svg.append('g').attr('transform', `translate(0,${margin.top + plotH})`)
.call(d3.axisBottom(x).ticks(Math.max(3, Math.min(6, Math.floor(plotW / 110)))).tickFormat(d => fmtD(d)));
const yAxis = svg.append('g').attr('transform', `translate(${margin.left},0)`)
.call(d3.axisLeft(y).ticks(5).tickFormat(v => nfc.format(v)));
[xAxis, yAxis].forEach(a => {
a.selectAll('text').attr('fill', fg).attr('font-size', fs);
a.selectAll('path,line').attr('stroke', fg).attr('stroke-opacity', 0.4);
});
svg.append('text').attr('transform', `translate(${14},${margin.top + plotH / 2}) rotate(-90)`)
.attr('text-anchor', 'middle').attr('fill', fg).attr('font-size', fs).text('Signups (monthly count)');
// notes inside the frame, one per line, counted in margin.bottom
notes.forEach((nt, i) => {
svg.append('text').attr('class', 'period-note').attr('x', margin.left)
.attr('y', margin.top + plotH + 44 + i * noteLH - 4)
.attr('fill', fg).attr('fill-opacity', 0.75).attr('font-size', fs).text(nt);
});
const area = d3.area().x(p => x(p.d)).y0(y(0)).y1(p => y(p.v));
const line = d3.line().x(p => x(p.d)).y(p => y(p.v));
const accent = d3.llmThemeColors(options).categories(['Signups'])('Signups');
svg.append('path').datum(pts).attr('d', area).attr('fill', accent).attr('fill-opacity', 0.18).style('pointer-events', 'none');
// solid line over complete periods, dashed segments into partial edges
const firstPt = pts.find(q => G.firstComplete && (q.p === G.firstComplete || q.d.getTime() === pd(G.firstComplete).getTime())) || pts[0];
const iF = pts.indexOf(firstPt), iL = pts.indexOf(latestPt);
const lo = Math.max(0, Math.min(iF, iL)), hi = Math.max(iF, iL);
svg.append('path').datum(pts.slice(lo, hi + 1)).attr('d', line).attr('fill', 'none')
.attr('stroke', accent).attr('stroke-width', 2).style('pointer-events', 'none');
if (hi < pts.length - 1) svg.append('path').datum(pts.slice(hi)).attr('d', line).attr('fill', 'none')
.attr('stroke', accent).attr('stroke-width', 2).attr('stroke-dasharray', '4,3').style('pointer-events', 'none');
if (lo > 0) svg.append('path').datum(pts.slice(0, lo + 1)).attr('d', line).attr('fill', 'none')
.attr('stroke', accent).attr('stroke-width', 2).attr('stroke-dasharray', '4,3').style('pointer-events', 'none');
const tip = options.allowTooltips !== false ? d3.llmTooltip(container) : null;
const marks = svg.append('g').selectAll('circle.d3-mark').data(pts).join('circle')
.attr('class', 'd3-mark')
.attr('data-row-idx', d => d.idxs.join(','))
.attr('cx', d => x(d.d)).attr('cy', d => y(d.v))
.attr('r', pts.length <= 120 ? 3.5 : 1.5)
.attr('fill', accent).attr('stroke', options.themeBg || '#fff').attr('stroke-width', 1)
.style('cursor', 'pointer');
if (G.markPartial) G.markPartial(marks);
if (tip) {
marks.on('mousemove', (event, d) => tip.show(`<b>${fmtD(d.d)}${tag(d)}</b><br/>Signups: ${fmtVal(d.v)}`, event))
.on('mouseleave', () => tip.hide());
}
const n0 = Math.floor(pts.length * 2 / 3);
const startD = pts[Math.min(n0, iL)].d;
updateKpis(startD, latestPt.d);
if (pts.length >= 2) {
d3.llmRangeBrush(svg, {
xScale: x, snapValues: pts.map(p => p.d),
x0: margin.left, x1: margin.left + plotW, y0: margin.top, y1: margin.top + plotH,
options: options,
initial: [startD, latestPt.d],
onWindow: function (a, b) { updateKpis(a, b); }
});
}
}Keep going
This chart was made by RegiaBI from the data above. Get it for Power BI or see pricing.
New articles in your inbox
Drop your email and we'll tell you when we publish something new. No spam — unsubscribe anytime.