blockcharts alpha

Gallery / Distributions /

Boxplot

Spread and outliers of raw samples per category.

70.4 KB of code · core 29.5 + 11 blocks 41.0

Response time by service

Worker requests take the longest, 230 ms at the median; api has one outlier at 390 ms and web one at 12 ms.

How it is made: transform.quartiles computes one min/Q1/median/Q3/max (Tukey whiskers, 1.5x IQR) per service and reports points further out as separate rows instead of stretching the whisker to them (api has one at 390ms, web one at 12ms). mark.boxplot draws the box and whiskers from the summary rows; a plain mark.point layered on top, reading the same value field, draws the outliers — the two marks tell their rows apart because the fields they read are NaN on the rows meant for the other one.

What the report is made of

The composer reads the JSON below and puts into the page the core and only the blocks its chart uses: 11 of the 59, 70.4 KB of code, minified, which is 33% of the 215.9 KB that the core and every block weigh together. The report file is 77.5 KB: that code, the data, the styles and the page around them.

BlockWhat it doesShare of the codeKB
core.composed-plain
A report with plain data: no checks, no decoder. Most reports.
A report with plain data: no checks, no decoder. Most reports. 29.5
lib.pointer
Where the pointer is on the chart, and following a mouse or a finger once a frame. Shared by tooltip, crosshair, zoom and brush.
Where the pointer is on the chart, and following a mouse or a finger once a frame. Shared by tooltip, crosshair, zoom and brush. 1.7
lib.ticks
Round steps and ticks (1, 2 or 5 × 10ⁿ). Shared by the number scales and the histogram bins.
Round steps and ticks (1, 2 or 5 × 10ⁿ). Shared by the number scales and the histogram bins. 0.7
scale.band
One band per category: the axis of bar charts.
One band per category: the axis of bar charts. 1.2
scale.linear
Numbers to positions, with round ticks.
Numbers to positions, with round ticks. 1.6
transform.quartiles
The five-number summary of each group: box plots.
The five-number summary of each group: box plots. 2.2
mark.boxplot
Box and whiskers.
Box and whiskers. 2.8
mark.point
Dots, bubbles and beeswarms.
Dots, bubbles and beeswarms. 3.9
guide.axis
Axes: formatted labels, a title, long categories wrapped.
Axes: formatted labels, a title, long categories wrapped. 11.7
guide.grid
Grid lines at the ticks.
Grid lines at the ticks. 0.6
interaction.tooltip
The values under the pointer.
The values under the pointer. 10.7
renderer.svg
Draws into SVG: sharp, selectable, prints well. The default.
Draws into SVG: sharp, selectable, prints well. The default. 3.9
TotalThe core 29.5 and 11 blocks 41.070.4

The JSON

This is the whole input. data holds the datasets, each chart is a spec that names one. In a checkout of the repository: node scripts/compose.js skills/blockcharts/recipes/boxplot.json report.html. Saved as page.json, it composes the same with the skill's own runtime/compose.js.

boxplot.json

{
  "title": "Boxplot",
  "data": {
    "latency": [
      { "service": "api", "ms": 120 }, { "service": "api", "ms": 135 }, { "service": "api", "ms": 128 },
      { "service": "api", "ms": 142 }, { "service": "api", "ms": 118 }, { "service": "api", "ms": 155 },
      { "service": "api", "ms": 131 }, { "service": "api", "ms": 126 }, { "service": "api", "ms": 149 },
      { "service": "api", "ms": 390 },
      { "service": "web", "ms": 60 }, { "service": "web", "ms": 65 }, { "service": "web", "ms": 58 },
      { "service": "web", "ms": 72 }, { "service": "web", "ms": 61 }, { "service": "web", "ms": 69 },
      { "service": "web", "ms": 64 }, { "service": "web", "ms": 12 },
      { "service": "worker", "ms": 210 }, { "service": "worker", "ms": 240 }, { "service": "worker", "ms": 225 },
      { "service": "worker", "ms": 260 }, { "service": "worker", "ms": 205 }, { "service": "worker", "ms": 275 },
      { "service": "worker", "ms": 230 }, { "service": "worker", "ms": 248 }, { "service": "worker", "ms": 215 }
    ]
  },
  "charts": [
    {
      "title": "Response time by service",
      "note": "Worker requests take the longest, 230 ms at the median; api has one outlier at 390 ms and web one at 12 ms.",
      "how": "transform.quartiles computes one min/Q1/median/Q3/max (Tukey whiskers, 1.5x IQR) per service and reports points further out as separate rows instead of stretching the whisker to them (api has one at 390ms, web one at 12ms). mark.boxplot draws the box and whiskers from the summary rows; a plain mark.point layered on top, reading the same `value` field, draws the outliers — the two marks tell their rows apart because the fields they read are NaN on the rows meant for the other one.",
      "spec": {
        "data": "latency",
        "size": [560, 320],
        "transforms": [{ "type": "quartiles", "field": "ms", "group": "service" }],
        "scales": {
          "x": { "type": "band" },
          "y": { "type": "linear", "zero": true }
        },
        "guides": [
          { "type": "grid", "scale": "y" },
          { "type": "axis", "scale": "x" },
          { "type": "axis", "scale": "y" }
        ],
        "marks": [
          { "type": "boxplot", "x": "service", "low": "low", "q1": "q1", "median": "median", "q3": "q3", "high": "high" },
          { "type": "point", "x": "service", "y": "value", "r": 3.5, "fill": "#e15759" }
        ],
        "interaction": [
          {
            "type": "tooltip",
            "fields": ["low", "q1", "median", "q3", "high", "count", "value"],
            "formats": {
              "low": { "maximumFractionDigits": 1, "suffix": " ms" },
              "q1": { "maximumFractionDigits": 1, "suffix": " ms" },
              "median": { "maximumFractionDigits": 1, "suffix": " ms" },
              "q3": { "maximumFractionDigits": 1, "suffix": " ms" },
              "high": { "maximumFractionDigits": 1, "suffix": " ms" },
              "value": { "maximumFractionDigits": 1, "suffix": " ms" }
            }
          }
        ]
      }
    }
  ]
}

The report the composer makes from it is one standalone file (77.5 KB): open it from disk, mail it, print it.

In a page of your own

The charts above use the composition kit (54.9 KB gzipped), the smallest one that has the blocks this example needs: lib.pointer, lib.ticks, scale.band, scale.linear, transform.quartiles, mark.boxplot, mark.point, guide.axis, guide.grid, interaction.tooltip, renderer.svg. The HTML below loads it from the jsDelivr CDN, pinned to version 0.0.5; to serve it from your own site, put its file there (the files of a release) and change the address.

HTML

<script src="https://cdn.jsdelivr.net/npm/blockcharts@0.0.5/release/kits/composition.js"></script>

<script type="application/json" id="bc-data">
{"latency":[{"service":"api","ms":120},{"service":"api","ms":135},{"service":"api","ms":128},{"service":"api","ms":142},{"service":"api","ms":118},{"service":"api","ms":155},{"service":"api","ms":131},{"service":"api","ms":126},{"service":"api","ms":149},{"service":"api","ms":390},{"service":"web","ms":60},{"service":"web","ms":65},{"service":"web","ms":58},{"service":"web","ms":72},{"service":"web","ms":61},{"service":"web","ms":69},{"service":"web","ms":64},{"service":"web","ms":12},{"service":"worker","ms":210},{"service":"worker","ms":240},{"service":"worker","ms":225},{"service":"worker","ms":260},{"service":"worker","ms":205},{"service":"worker","ms":275},{"service":"worker","ms":230},{"service":"worker","ms":248},{"service":"worker","ms":215}]}
</script>

<script type="application/json" data-bc-chart>
{
  "data": "latency",
  "size": [
    560,
    320
  ],
  "transforms": [
    {
      "type": "quartiles",
      "field": "ms",
      "group": "service"
    }
  ],
  "scales": {
    "x": {
      "type": "band"
    },
    "y": {
      "type": "linear",
      "zero": true
    }
  },
  "guides": [
    {
      "type": "grid",
      "scale": "y"
    },
    {
      "type": "axis",
      "scale": "x"
    },
    {
      "type": "axis",
      "scale": "y"
    }
  ],
  "marks": [
    {
      "type": "boxplot",
      "x": "service",
      "low": "low",
      "q1": "q1",
      "median": "median",
      "q3": "q3",
      "high": "high"
    },
    {
      "type": "point",
      "x": "service",
      "y": "value",
      "r": 3.5,
      "fill": "#e15759"
    }
  ],
  "interaction": [
    {
      "type": "tooltip",
      "fields": [
        "low",
        "q1",
        "median",
        "q3",
        "high",
        "count",
        "value"
      ],
      "formats": {
        "low": {
          "maximumFractionDigits": 1,
          "suffix": " ms"
        },
        "q1": {
          "maximumFractionDigits": 1,
          "suffix": " ms"
        },
        "median": {
          "maximumFractionDigits": 1,
          "suffix": " ms"
        },
        "q3": {
          "maximumFractionDigits": 1,
          "suffix": " ms"
        },
        "high": {
          "maximumFractionDigits": 1,
          "suffix": " ms"
        },
        "value": {
          "maximumFractionDigits": 1,
          "suffix": " ms"
        }
      }
    }
  ],
  "alt": "Response time by service"
}
</script>