Skip to content

Commit 2438b02

Browse files
committed
Update CHANGELOG
1 parent 0c5e7e8 commit 2438b02

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

CHANGELOG.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,41 @@ Plot.plot({
4646
})
4747
```
4848

49-
The [bin transform](./README.md#bin) now coerces the input channel (the quantity being binned) to numbers as necessary. In addition, the bin transform now correctly handles typed array input channels representing temporal data.
50-
5149
The [stack transform](./README.md#stack) now allows the **offset** option to be specified as a function. For example, this can be used to visualize Likert survey results with a neutral category as a diverging stacked bar chart.
5250

51+
<img src="./img/likert.png" width="640" alt="a diverging bar chart of responses to a Likert survey question">
52+
53+
```js
54+
function Likert(
55+
responses = [
56+
["Strongly Disagree", -1],
57+
["Disagree", -1],
58+
["Neutral", 0],
59+
["Agree", 1],
60+
["Strongly Agree", 1]
61+
]
62+
) {
63+
const map = new Map(responses);
64+
return {
65+
order: Array.from(map.keys()),
66+
offset(facetstacks, X1, X2, Z) {
67+
for (const stacks of facetstacks) {
68+
for (const stack of stacks) {
69+
const k = d3.sum(stack, i => (X2[i] - X1[i]) * (1 - map.get(Z[i]))) / 2;
70+
for (const i of stack) {
71+
X1[i] -= k;
72+
X2[i] -= k;
73+
}
74+
}
75+
}
76+
}
77+
};
78+
}
79+
```
80+
5381
The new [_quantize_ scale type](./README.md#color-options) transforms a continuous domain into discrete, evenly-spaced thresholds. The _threshold_ scale type now supports descending domains.
5482

55-
The [rect mark](./README.md#rect) now promotes the _x_ channel to _x1_ and _x2_ if the latter two are not specified, and likewise the _y_ channel to _y1_ and _y2_.
83+
The [bin transform](./README.md#bin) now coerces the input channel (the quantity being binned) to numbers as necessary. In addition, the bin transform now correctly handles typed array input channels representing temporal data. The [rect mark](./README.md#rect) now promotes the _x_ channel to _x1_ and _x2_ if the latter two are not specified, and likewise the _y_ channel to _y1_ and _y2_.
5684

5785
Fix crash when **text** or **title** channels contain heterogenous types; each value is now independently formatted in a type-appropriate default formatter. Fix a rendering bug with one-dimensional rects whose opposite dimension is a band scale. Fix a rendering bug with swoopy arrows. Improve error messages to give more context.
5886

img/likert.png

85.5 KB
Loading

test/plots/likert-survey.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import * as Plot from "@observablehq/plot";
22
import * as d3 from "d3";
33

4-
function Likert(responses) {
4+
function Likert(responses = [
5+
["Strongly Disagree", -1],
6+
["Disagree", -1],
7+
["Neutral", 0],
8+
["Agree", 1],
9+
["Strongly Agree", 1]
10+
]) {
511
const map = new Map(responses);
612
return {
713
order: Array.from(map.keys()),
@@ -21,13 +27,7 @@ function Likert(responses) {
2127

2228
export default async function() {
2329
const survey = await d3.csv("data/survey.csv");
24-
const {order, offset} = Likert([
25-
["Strongly Disagree", -1],
26-
["Disagree", -1],
27-
["Neutral", 0],
28-
["Agree", 1],
29-
["Strongly Agree", 1]
30-
]);
30+
const {order, offset} = Likert();
3131
return Plot.plot({
3232
x: {
3333
tickFormat: Math.abs,

0 commit comments

Comments
 (0)