codelion commited on
Commit
4db2af3
路
verified 路
1 Parent(s): 859a42c

Visualize: box plot labels get their own band in narrow charts, so dots no longer cover them; label halo

Browse files
Files changed (2) hide show
  1. static/app.css +1 -0
  2. static/visualize.js +4 -4
static/app.css CHANGED
@@ -278,6 +278,7 @@ textarea.in.vq { min-height: 64px; font-size: 19px; }
278
  .chart.small { margin-top: 8px; min-height: 80px; }
279
  .svgwrap svg { display: block; max-width: 100%; height: auto; overflow: visible; }
280
  .chart text { font: 13px var(--ui); fill: var(--ink); }
 
281
  .chart .tick { font-size: 11.5px; fill: var(--slate); font-variant-numeric: tabular-nums; }
282
  .chart .val { font-weight: 600; font-variant-numeric: tabular-nums; }
283
  .chart .ink { fill: var(--blue); }
 
278
  .chart.small { margin-top: 8px; min-height: 80px; }
279
  .svgwrap svg { display: block; max-width: 100%; height: auto; overflow: visible; }
280
  .chart text { font: 13px var(--ui); fill: var(--ink); }
281
+ .chart .lab { paint-order: stroke; stroke: var(--paper); stroke-width: 3px; stroke-linejoin: round; }
282
  .chart .tick { font-size: 11.5px; fill: var(--slate); font-variant-numeric: tabular-nums; }
283
  .chart .val { font-weight: 600; font-variant-numeric: tabular-nums; }
284
  .chart .ink { fill: var(--blue); }
static/visualize.js CHANGED
@@ -89,16 +89,16 @@
89
  }
90
  function jitter(id) { const s = Math.sin(id * 12.9898) * 43758.5453; return s - Math.floor(s) - 0.5; }
91
  function svgBox(c, w, key) {
92
- const marks = sorted(c, key), nar = c.x && narrow(marks, w), row = nar ? 48 : 38, top = 6, lw = c.x && !nar ? labelW(marks.map((m) => m.key), w) : 8, bw = Math.max(80, w - lw - 16), by = nar ? 8 : 0;
93
  const all = marks.flatMap((m) => m.points.map((p) => p[1])), ticks = niceTicks(Math.min(...all), Math.max(...all));
94
  const lo = ticks[0], hi = ticks[ticks.length - 1], X = (v) => lw + ((v - lo) / (hi - lo || 1)) * bw, h = top + marks.length * row + 26;
95
  const grid = ticks.map((t) => `<line class="grid" x1="${X(t)}" x2="${X(t)}" y1="${top}" y2="${h - 22}"></line><text class="tick" x="${X(t)}" y="${h - 6}" text-anchor="middle">${fmt(t)}</text>`).join("");
96
  const body = marks.map((m, i) => {
97
  const y = top + i * row, mid = y + row / 2 - 2 + by, thin = m.n < 3 ? " thin" : "";
98
- const dots = m.points.map(([id, v]) => `<circle class="dot mk1" cx="${X(v)}" cy="${mid + jitter(id) * (row - 16)}" r="3.4" data-vzsel="row ${id}" data-vzids="${id}" tabindex="-1"><title>Row ${id}: ${fmt(v)}</title></circle>`).join("");
99
  return `<g class="grow-o${thin}" style="--d:${i * 50}ms">${mark("", `${c.x ? `${c.x} = ${m.key}: ` : ""}median ${fmt(m.median)}, middle half ${fmt(m.q1)} to ${fmt(m.q3)}, ${plural(m.n, "row")}`, m.ids,
100
- `${c.x ? (nar ? labText(m.key, 0, y - 2, true, w) : `<text class="lab" x="${lw - 10}" y="${mid + 4}" text-anchor="end">${esc(clip(m.key, lw - 12))}</text>`) : ""}${m.n >= 4 ? `<line class="whisk" x1="${X(m.lo)}" x2="${X(m.hi)}" y1="${mid}" y2="${mid}"></line>
101
- <rect class="bx" x="${X(m.q1)}" y="${mid - 9}" width="${Math.max(2, X(m.q3) - X(m.q1))}" height="18"></rect>` : ""}<rect class="hit" x="0" y="${nar ? y - 2 : y}" width="${nar ? w : lw}" height="${nar ? 14 : row}"></rect>`)}
102
  ${dots}<line class="med" x1="${X(m.median)}" x2="${X(m.median)}" y1="${mid - 11}" y2="${mid + 11}"></line></g>`;
103
  }).join("");
104
  return { svg: `<svg viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" role="img" aria-label="Box plot of ${esc(c.y)}${c.x ? ` by ${esc(c.x)}` : ""}">${grid}${body}</svg>`, axis: `${c.y}${c.x ? ` by ${c.x}` : ""} 路 each dot is a row` };
 
89
  }
90
  function jitter(id) { const s = Math.sin(id * 12.9898) * 43758.5453; return s - Math.floor(s) - 0.5; }
91
  function svgBox(c, w, key) {
92
+ const marks = sorted(c, key), nar = c.x && narrow(marks, w), row = nar ? 54 : 38, top = 6, lw = c.x && !nar ? labelW(marks.map((m) => m.key), w) : 8, bw = Math.max(80, w - lw - 16), by = nar ? 12 : 0, amp = nar ? 16 : row - 16;
93
  const all = marks.flatMap((m) => m.points.map((p) => p[1])), ticks = niceTicks(Math.min(...all), Math.max(...all));
94
  const lo = ticks[0], hi = ticks[ticks.length - 1], X = (v) => lw + ((v - lo) / (hi - lo || 1)) * bw, h = top + marks.length * row + 26;
95
  const grid = ticks.map((t) => `<line class="grid" x1="${X(t)}" x2="${X(t)}" y1="${top}" y2="${h - 22}"></line><text class="tick" x="${X(t)}" y="${h - 6}" text-anchor="middle">${fmt(t)}</text>`).join("");
96
  const body = marks.map((m, i) => {
97
  const y = top + i * row, mid = y + row / 2 - 2 + by, thin = m.n < 3 ? " thin" : "";
98
+ const dots = m.points.map(([id, v]) => `<circle class="dot mk1" cx="${X(v)}" cy="${mid + jitter(id) * amp}" r="3.4" data-vzsel="row ${id}" data-vzids="${id}" tabindex="-1"><title>Row ${id}: ${fmt(v)}</title></circle>`).join("");
99
  return `<g class="grow-o${thin}" style="--d:${i * 50}ms">${mark("", `${c.x ? `${c.x} = ${m.key}: ` : ""}median ${fmt(m.median)}, middle half ${fmt(m.q1)} to ${fmt(m.q3)}, ${plural(m.n, "row")}`, m.ids,
100
+ `${c.x ? (nar ? labText(m.key, 0, y, true, w) : `<text class="lab" x="${lw - 10}" y="${mid + 4}" text-anchor="end">${esc(clip(m.key, lw - 12))}</text>`) : ""}${m.n >= 4 ? `<line class="whisk" x1="${X(m.lo)}" x2="${X(m.hi)}" y1="${mid}" y2="${mid}"></line>
101
+ <rect class="bx" x="${X(m.q1)}" y="${mid - 9}" width="${Math.max(2, X(m.q3) - X(m.q1))}" height="18"></rect>` : ""}<rect class="hit" x="0" y="${y}" width="${nar ? w : lw}" height="${nar ? 16 : row}"></rect>`)}
102
  ${dots}<line class="med" x1="${X(m.median)}" x2="${X(m.median)}" y1="${mid - 11}" y2="${mid + 11}"></line></g>`;
103
  }).join("");
104
  return { svg: `<svg viewBox="0 0 ${w} ${h}" width="${w}" height="${h}" role="img" aria-label="Box plot of ${esc(c.y)}${c.x ? ` by ${esc(c.x)}` : ""}">${grid}${body}</svg>`, axis: `${c.y}${c.x ? ` by ${c.x}` : ""} 路 each dot is a row` };