Skip to content

Range Area ​

An area from low to high, points at v2 and a line at v3. The extra channels in cm.encode name the y scale, so all three marks share it. After G2.

js
const rows = await d3.json("/data/range-spline-area.json");
const data = rows.map(([x, low, high, v2, v3]) => ({x: +x, low, high, v2, v3}));

const renderer = cm.svg({width: 640, height: 400});
const root = cm.flow().renderer(renderer);

root
  .data(data)
  .transform(cm.encode, {
    x: "x",
    y: "high",
    y1: "low",
    v2: {value: "v2", scale: "y"},
    v3: {value: "v3", scale: "y"},
  })
  .transform(cm.plane, {y: {label: null}})
  .add(cm.areaY, {curve: "natural", fill: "#64b5f6", fillOpacity: 0.65, stroke: "#64b5f6"})
  .add(cm.circle, {y: "v2", r: 2, fill: "currentColor"})
  .add(cm.lineY, {y: "v3", stroke: "#FF6B3B", curve: "natural"});

root.render();
document.body.append(renderer.node());