plot icon indicating copy to clipboard operation
plot copied to clipboard

Plot.initialize

Open mbostock opened this issue 4 years ago • 6 comments

A debugging routine, e.g.,

function Plot_initialize(data, {transform, ...channels} = {}) {
  data = arrayify(data);
  let index = data == null ? undefined : Uint32Array.from(data, (d, i) => i);
  if (transform !== undefined) {
    ({facets: index, data} = transform(data, [index]));
    if (index.length) ([index] = index);
  }
  return {
    data,
    index,
    ...Object.fromEntries(
      Object.entries(channels)
        .map(([name, value]) => [name, Plot.valueof(data, value)])
    )
  };
}

mbostock avatar Mar 17 '21 22:03 mbostock

I think this is closer to what we want:

Plot.barY(data, Plot.groupX({x: "species"})).initialize()

Though, it could be made a little easier to inspect: you’d like to see both the Mark options and the channels.

mbostock avatar Mar 18 '21 14:03 mbostock

Yes. Also would like a way to inspect what happens with faceting.

Fil avatar Mar 18 '21 15:03 Fil

A version with faceting:

viewTransform = (data = [], {transform, ...channels}, facets = [Uint32Array.from(data, (d, i) => i)]) => {
  if (transform !== undefined) {
    ({data, facets} = transform(data, facets));
  }
  return {
    data,
    facets,
    ...Object.fromEntries(
      Object.entries(channels)
        .map(([name, value]) => [name, Plot.valueof(data, value)])
    )
  };
}

(used in https://next.observablehq.com/d/61ca1967e419b882 with @enjalot)

Fil avatar Mar 28 '21 10:03 Fil

I wrote up a notebook detailing how & why I want to use viewTransform in more depth: https://observablehq.com/@enjalot/plot-spot

it also serves as a light "plugin" that could be used today to inspect and debug transforms. it's really just a rebrand of @fil's viewTransform

enjalot avatar May 09 '21 15:05 enjalot

Here's an alternative / complementary approach, to read scales, dimensions, axes. https://observablehq.com/d/9e826c4659c798e8

Fil avatar May 18 '21 20:05 Fil

I’m not really sure what, if anything, we want to do here.

mbostock avatar Feb 26 '22 20:02 mbostock