Comments (3)
I've tried to address this issue, but I'm not sure what is considered to be broken.
Here's my current test https://observablehq.com/d/d36850d4bd824097
data = [{l: "A", n: 1}, {l: "B", n: 3},{l: "C", n: 2}];
Plot.plot({
facet: { data, y: "l" },
marks: [
Plot.ruleY(data, {y: "n", stroke: ["red", "blue", "orange"]})
]
})
With no faceting, this creates three rules, with the three colors.
Once we activate faceting, each facet has 1 rule, but only the "red" stroke is ever used. I don't think it's wrong ("red" goes to the first line of the facet, "blue" to the second, etc. And if I want to join the stroke array with the data I should do it before feeding them to plot (?).)
But this probably only shows that I didn't understand the issue :) You probably have a different example in mind?
from plot.
Aside: the stroke values here are abstract, not literal colors, so I changed your test to use ["foo", "bar", "baz"]
for clarity. These are then assigned colors through the color scale, whose range defaults to tableau10 for ordinal values.
The behavior that I was imagining should be equivalent to the data having an additional stroke property:
data = [
{l: "A", n: 1, stroke: "foo"},
{l: "B", n: 3, stroke: "bar"},
{l: "C", n: 2, stroke: "baz"}
]
And then referencing that property:
Plot.plot({
facet: {data, y: "l"},
marks: [
Plot.ruleY(data, {y: "n", stroke: "stroke"})
]
})
The intent of specifying channel values as an array is to support columnar data such as this:
flatdata = ({
i: [0, 1, 2],
l: ["A", "B", "C"],
n: [1, 2, 3],
stroke: ["foo", "bar", "baz"]
})
This works fine without faceting, e.g.:
Plot.plot({
marks: [
Plot.ruleY(flatdata.i, {y: flatdata.n, stroke: flatdata.stroke})
]
})
But it is not consistent with row-oriented data with faceting. This should be equivalent to the above example using the stroke field:
Plot.plot({
facet: {data: flatdata.i, y: flatdata.l},
marks: [
Plot.ruleY(flatdata.i, {y: flatdata.n, stroke: flatdata.stroke})
]
})
from plot.
The reason the function definition of stroke works, while the array definition does not, is that mark.initialize is called repeatedly for each facet’s data:
Lines 29 to 31 in 4bb8198
However, if the channel’s value is already an array, it is returned as-is here, and thus all facets share the same channel values, rather than faceting them:
Lines 36 to 42 in 4bb8198
My guess is that we need to do something like pass the facetIndex to mark.initialize, and when present and the channel is specified as an array, the Channel constructor should take the corresponding values (Array.from(index, i => values[i])
) from the channel definition for each facet.
from plot.
Related Issues (20)
- x and y clip modes HOT 1
- differenceX and shiftY
- monotone X for lineY?
- Plot.auto - TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event' HOT 1
- Add a function to Object.prototype cause Plot to generate empty chart HOT 5
- Selection of plot data using sliders HOT 1
- Clamp option for tooltip?
- "element" transform to complement pointer transform
- The interval option for line and area perhaps should round down rather than center
- Save / export stand-alone SVG-file with legend
- Density reducer
- Disabling the stroke channel from the tooltip does not work for Plot.line() HOT 1
- tip: true is not working on vue3 ssr HOT 1
- Download option for embedded plot HOT 3
- Bug: areaY tip/pointer position wrong for stacked data
- remove the dark mode toggle?
- The group & bin transform sort option should support descending shorthand
- Stack overlapping, non-aligned intervals? HOT 2
- Position of the axis label with `labelAnchor: right` HOT 5
- Documentation page about axis mark turns empty if an interactive selection is made HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plot.