Skip to content

Commit c8382fa

Browse files
committed
an example of the bin filter feature
1 parent 228a465 commit c8382fa

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,25 @@ When the facet *data* is null, a better error message is thrown.
131131

132132
### Transforms
133133

134-
The bin and group transforms now support new *filter*, *sort* and *reverse* options on the *outputs* object. By setting the *filter* to null, the bin transform will now return empty bins; this is useful with marks such as lines and areas that require zeroes to be present, rather than interpolating across the missing bins. (The *z*, *fill* or *stroke* channels, when used for grouping, are propagated to empty bins.) The *outputs* argument to the bin and group transforms is now optional; it defaults to the *count* reducer for *y*, *x* and *fill* for Plot.binX, Plot.binY, and Plot.bin respectively, and the same for the group transforms.
134+
The bin and group transforms now support new *filter*, *sort* and *reverse* options on the *outputs* object. By setting the *filter* to null, the bin transform will now return all bins, including the empty ones; this is useful with marks such as lines and areas that require zeroes to be present, rather than interpolating across the missing bins. (The *z*, *fill* or *stroke* channels, when used for grouping, are propagated to empty bins.) The *outputs* argument to the bin and group transforms is now optional; it defaults to the *count* reducer for *y*, *x* and *fill* for Plot.binX, Plot.binY, and Plot.bin respectively, and the same for the group transforms.
135+
136+
<img width="640" alt="a one-dimensional scatterplot hightlighting empty bins" src="https://user-images.githubusercontent.com/7001/130244527-6b3191c3-4d8f-4cb7-8209-7ab47f02e871.png">
137+
138+
```js
139+
Plot.plot({
140+
marks: [
141+
Plot.rect(
142+
penguins,
143+
Plot.binX(
144+
{ filter: (bin) => !bin.length },
145+
{ x: "bill_length", thresholds: 100, fill: "#ddd" }
146+
)
147+
),
148+
Plot.dotX(penguins, { x: "bill_length", y: Math.random, fill: "#aaa", r: 2 })
149+
],
150+
height: 80
151+
})
152+
```
135153

136154
The bin and group transforms now support new *distinct*, *mode*, *min-index*, and *max-index* reducers. The *distinct* reducer counts the number of distinct values in each group, while the *mode* reducer returns the most frequent value in each group. The *min-index* and *max-index* reducers are similar to *min* and *max*, except they return the zero-based index of the minimum and maximum value, respectively; for example, this is useful to sort time series by the date of each series’ peak.
137155

0 commit comments

Comments
 (0)