Transformations

Data transforms are defined with msc.transform(...) and applied with scene.derive(...):

let scene = msc.scene();
let table = await msc.csv("data.csv");
let spec = msc.transform("filter", { attribute: "year", type: "interval", value: [1955, 1955] });
let filtered = scene.derive(table, spec);

scene.derive(...) always returns a new DataTable.

Binning

The binning transformation assigns each input row to a numeric interval. This is used in visualizations such as histograms (example demos: histogram, dynamic binning).

let binSpec = msc.transform("bin", { attribute: "weight(lbs)", numBins: 8 });
let binned = scene.derive(table, binSpec);

The binning transformation exposes generated attribute names you can use in encodings:

  • binSpec.binIdAttr: bin id attribute (for grouping/repeat)
  • binSpec.startAttr: bin start value
  • binSpec.endAttr: bin end value
  • binSpec.actualNumBins: final number of bins after boundary adjustment
propertyrequired?explanation
attributerequirednumeric attribute to bin
numBinsoptionaltarget number of bins
minoptionallower bound override
maxoptionalupper bound override

Filtering

The filtering transformation keeps only rows that satisfy a predicate spec. Example demos: tower chart and DimpVis

let yearFilter = msc.transform("filter", {
    attribute: "year",
    type: "interval",
    value: [1955, 1955]
});
let yearData = scene.derive(table, yearFilter);
propertyrequired?explanation
attributerequiredattribute to filter
typeoptionalfilter mode (for example "interval")
valueoptionalfilter value (for interval: [min, max])

Kernel Density Estimation

The KDE transformation estimates a density curve for a numeric attribute. Example demos: density plot and ridgeline plot.

let density = scene.derive(table, msc.transform("kde", {
    attribute: "weight(lbs)",
    newAttribute: "weight_density",
    min: 1500,
    max: 5000,
    interval: 100,
    bandwidth: 10
}));
propertyrequired?explanation
attributerequirednumeric attribute to estimate density for
newAttributerequiredoutput density attribute name
bandwidthrequiredsmoothing bandwidth
intervalrequiredsampling step
minoptionallower sampling bound
maxoptionalupper sampling bound
groupByoptionalcompute separate densities per group

Custom transform

The custom transformation lets you define transform logic directly. Example demos: histograms cross filtering and index chart. The callback receives the input table, output table, and mutable spec object:

let tableSpec = msc.transform("custom", (inTbl, outTbl, spec) => {
    let rows = spec.selectedRows ? spec.selectedRows.slice(0, 25) : inTbl.rows().slice(0, 25);
    outTbl.load(rows);
}, { selectedRows: null });

let derived = scene.derive(table, tableSpec);