Skip to content

Commit 03cd939

Browse files
committed
prettier --write
1 parent 87a6bcc commit 03cd939

File tree

317 files changed

+4940
-3123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

317 files changed

+4940
-3123
lines changed

src/axes.js

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,53 @@ import {position, registry} from "./scales/index.js";
66

77
export function Axes(
88
{x: xScale, y: yScale, fx: fxScale, fy: fyScale},
9-
{x = {}, y = {}, fx = {}, fy = {}, axis = true, grid, line, label, facet: {axis: facetAxis = axis, grid: facetGrid, label: facetLabel = label} = {}} = {}
9+
{
10+
x = {},
11+
y = {},
12+
fx = {},
13+
fy = {},
14+
axis = true,
15+
grid,
16+
line,
17+
label,
18+
facet: {axis: facetAxis = axis, grid: facetGrid, label: facetLabel = label} = {}
19+
} = {}
1020
) {
1121
let {axis: xAxis = axis} = x;
1222
let {axis: yAxis = axis} = y;
1323
let {axis: fxAxis = facetAxis} = fx;
1424
let {axis: fyAxis = facetAxis} = fy;
15-
if (!xScale) xAxis = null; else if (xAxis === true) xAxis = "bottom";
16-
if (!yScale) yAxis = null; else if (yAxis === true) yAxis = "left";
17-
if (!fxScale) fxAxis = null; else if (fxAxis === true) fxAxis = xAxis === "bottom" ? "top" : "bottom";
18-
if (!fyScale) fyAxis = null; else if (fyAxis === true) fyAxis = yAxis === "left" ? "right" : "left";
25+
if (!xScale) xAxis = null;
26+
else if (xAxis === true) xAxis = "bottom";
27+
if (!yScale) yAxis = null;
28+
else if (yAxis === true) yAxis = "left";
29+
if (!fxScale) fxAxis = null;
30+
else if (fxAxis === true) fxAxis = xAxis === "bottom" ? "top" : "bottom";
31+
if (!fyScale) fyAxis = null;
32+
else if (fyAxis === true) fyAxis = yAxis === "left" ? "right" : "left";
1933
return {
20-
...xAxis && {x: new AxisX({grid, line, label, fontVariant: inferFontVariant(xScale), ...x, axis: xAxis})},
21-
...yAxis && {y: new AxisY({grid, line, label, fontVariant: inferFontVariant(yScale), ...y, axis: yAxis})},
22-
...fxAxis && {fx: new AxisX({name: "fx", grid: facetGrid, label: facetLabel, fontVariant: inferFontVariant(fxScale), ...fx, axis: fxAxis})},
23-
...fyAxis && {fy: new AxisY({name: "fy", grid: facetGrid, label: facetLabel, fontVariant: inferFontVariant(fyScale), ...fy, axis: fyAxis})}
34+
...(xAxis && {x: new AxisX({grid, line, label, fontVariant: inferFontVariant(xScale), ...x, axis: xAxis})}),
35+
...(yAxis && {y: new AxisY({grid, line, label, fontVariant: inferFontVariant(yScale), ...y, axis: yAxis})}),
36+
...(fxAxis && {
37+
fx: new AxisX({
38+
name: "fx",
39+
grid: facetGrid,
40+
label: facetLabel,
41+
fontVariant: inferFontVariant(fxScale),
42+
...fx,
43+
axis: fxAxis
44+
})
45+
}),
46+
...(fyAxis && {
47+
fy: new AxisY({
48+
name: "fy",
49+
grid: facetGrid,
50+
label: facetLabel,
51+
fontVariant: inferFontVariant(fyScale),
52+
...fy,
53+
axis: fyAxis
54+
})
55+
})
2456
};
2557
}
2658

@@ -83,7 +115,8 @@ export function autoScaleLabels(channels, scales, {x, y, fx, fy}, dimensions, op
83115
}
84116
}
85117
for (const [key, type] of registry) {
86-
if (type !== position && scales[key]) { // not already handled above
118+
if (type !== position && scales[key]) {
119+
// not already handled above
87120
autoScaleLabel(key, scales[key], channels.get(key), options[key]);
88121
}
89122
}
@@ -92,9 +125,7 @@ export function autoScaleLabels(channels, scales, {x, y, fx, fy}, dimensions, op
92125
// Mutates axis.labelAnchor, axis.label, scale.label!
93126
function autoAxisLabelsX(axis, scale, channels) {
94127
if (axis.labelAnchor === undefined) {
95-
axis.labelAnchor = isOrdinalScale(scale) ? "center"
96-
: scaleOrder(scale) < 0 ? "left"
97-
: "right";
128+
axis.labelAnchor = isOrdinalScale(scale) ? "center" : scaleOrder(scale) < 0 ? "left" : "right";
98129
}
99130
if (axis.label === undefined) {
100131
axis.label = inferLabel(channels, scale, axis, "x");
@@ -105,8 +136,10 @@ function autoAxisLabelsX(axis, scale, channels) {
105136
// Mutates axis.labelAnchor, axis.label, scale.label!
106137
function autoAxisLabelsY(axis, opposite, scale, channels) {
107138
if (axis.labelAnchor === undefined) {
108-
axis.labelAnchor = isOrdinalScale(scale) ? "center"
109-
: opposite && opposite.axis === "top" ? "bottom" // TODO scaleOrder?
139+
axis.labelAnchor = isOrdinalScale(scale)
140+
? "center"
141+
: opposite && opposite.axis === "top"
142+
? "bottom" // TODO scaleOrder?
110143
: "top";
111144
}
112145
if (axis.label === undefined) {
@@ -145,7 +178,7 @@ function inferLabel(channels = [], scale, axis, key) {
145178
const order = scaleOrder(scale);
146179
if (order) {
147180
if (key === "x" || (axis && axis.labelAnchor === "center")) {
148-
candidate = key === "x" === order < 0 ? `← ${candidate}` : `${candidate} →`;
181+
candidate = (key === "x") === order < 0 ? `← ${candidate}` : `${candidate} →`;
149182
} else {
150183
candidate = `${order < 0 ? "↑ " : "↓ "}${candidate}`;
151184
}

src/axis.js

Lines changed: 99 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -57,44 +57,43 @@ export class AxisX {
5757
},
5858
context
5959
) {
60-
const {
61-
axis,
62-
fontVariant,
63-
grid,
64-
label,
65-
labelAnchor,
66-
labelOffset,
67-
line,
68-
name,
69-
tickRotate
70-
} = this;
60+
const {axis, fontVariant, grid, label, labelAnchor, labelOffset, line, name, tickRotate} = this;
7161
const offset = name === "x" ? 0 : axis === "top" ? marginTop - facetMarginTop : marginBottom - facetMarginBottom;
7262
const offsetSign = axis === "top" ? -1 : 1;
7363
const ty = offsetSign * offset + (axis === "top" ? marginTop : height - marginBottom);
7464
return create("svg:g", context)
75-
.call(applyAria, this)
76-
.attr("transform", `translate(${offsetLeft},${ty})`)
77-
.call(createAxis(axis === "top" ? axisTop : axisBottom, x, this))
78-
.call(maybeTickRotate, tickRotate)
79-
.attr("font-size", null)
80-
.attr("font-family", null)
81-
.attr("font-variant", fontVariant)
82-
.call(!line ? g => g.select(".domain").remove() : () => {})
83-
.call(!grid ? () => {}
84-
: fy ? gridFacetX(index, fy, -ty)
85-
: gridX(offsetSign * (marginBottom + marginTop - height)))
86-
.call(!label ? () => {} : g => g.append("text")
87-
.attr("fill", "currentColor")
88-
.attr("transform", `translate(${
89-
labelAnchor === "center" ? (width + marginLeft - marginRight) / 2
90-
: labelAnchor === "right" ? width + labelMarginRight
91-
: -labelMarginLeft
92-
},${labelOffset * offsetSign})`)
93-
.attr("dy", axis === "top" ? "1em" : "-0.32em")
94-
.attr("text-anchor", labelAnchor === "center" ? "middle"
95-
: labelAnchor === "right" ? "end"
96-
: "start")
97-
.text(label))
65+
.call(applyAria, this)
66+
.attr("transform", `translate(${offsetLeft},${ty})`)
67+
.call(createAxis(axis === "top" ? axisTop : axisBottom, x, this))
68+
.call(maybeTickRotate, tickRotate)
69+
.attr("font-size", null)
70+
.attr("font-family", null)
71+
.attr("font-variant", fontVariant)
72+
.call(!line ? (g) => g.select(".domain").remove() : () => {})
73+
.call(
74+
!grid ? () => {} : fy ? gridFacetX(index, fy, -ty) : gridX(offsetSign * (marginBottom + marginTop - height))
75+
)
76+
.call(
77+
!label
78+
? () => {}
79+
: (g) =>
80+
g
81+
.append("text")
82+
.attr("fill", "currentColor")
83+
.attr(
84+
"transform",
85+
`translate(${
86+
labelAnchor === "center"
87+
? (width + marginLeft - marginRight) / 2
88+
: labelAnchor === "right"
89+
? width + labelMarginRight
90+
: -labelMarginLeft
91+
},${labelOffset * offsetSign})`
92+
)
93+
.attr("dy", axis === "top" ? "1em" : "-0.32em")
94+
.attr("text-anchor", labelAnchor === "center" ? "middle" : labelAnchor === "right" ? "end" : "start")
95+
.text(label)
96+
)
9897
.node();
9998
}
10099
}
@@ -136,106 +135,93 @@ export class AxisY {
136135
render(
137136
index,
138137
{[this.name]: y, fx},
139-
{
140-
width,
141-
height,
142-
marginTop,
143-
marginRight,
144-
marginBottom,
145-
marginLeft,
146-
offsetTop = 0,
147-
facetMarginLeft,
148-
facetMarginRight
149-
},
138+
{width, height, marginTop, marginRight, marginBottom, marginLeft, offsetTop = 0, facetMarginLeft, facetMarginRight},
150139
context
151140
) {
152-
const {
153-
axis,
154-
fontVariant,
155-
grid,
156-
label,
157-
labelAnchor,
158-
labelOffset,
159-
line,
160-
name,
161-
tickRotate
162-
} = this;
141+
const {axis, fontVariant, grid, label, labelAnchor, labelOffset, line, name, tickRotate} = this;
163142
const offset = name === "y" ? 0 : axis === "left" ? marginLeft - facetMarginLeft : marginRight - facetMarginRight;
164143
const offsetSign = axis === "left" ? -1 : 1;
165144
const tx = offsetSign * offset + (axis === "right" ? width - marginRight : marginLeft);
166145
return create("svg:g", context)
167-
.call(applyAria, this)
168-
.attr("transform", `translate(${tx},${offsetTop})`)
169-
.call(createAxis(axis === "right" ? axisRight : axisLeft, y, this))
170-
.call(maybeTickRotate, tickRotate)
171-
.attr("font-size", null)
172-
.attr("font-family", null)
173-
.attr("font-variant", fontVariant)
174-
.call(!line ? g => g.select(".domain").remove() : () => {})
175-
.call(!grid ? () => {}
176-
: fx ? gridFacetY(index, fx, -tx)
177-
: gridY(offsetSign * (marginLeft + marginRight - width)))
178-
.call(!label ? () => {} : g => g.append("text")
179-
.attr("fill", "currentColor")
180-
.attr("font-variant", fontVariant == null ? null : "normal")
181-
.attr("transform", `translate(${labelOffset * offsetSign},${
182-
labelAnchor === "center" ? (height + marginTop - marginBottom) / 2
183-
: labelAnchor === "bottom" ? height - marginBottom
184-
: marginTop
185-
})${labelAnchor === "center" ? ` rotate(-90)` : ""}`)
186-
.attr("dy", labelAnchor === "center" ? (axis === "right" ? "-0.32em" : "0.75em")
187-
: labelAnchor === "bottom" ? "1.4em"
188-
: "-1em")
189-
.attr("text-anchor", labelAnchor === "center" ? "middle"
190-
: axis === "right" ? "end"
191-
: "start")
192-
.text(label))
146+
.call(applyAria, this)
147+
.attr("transform", `translate(${tx},${offsetTop})`)
148+
.call(createAxis(axis === "right" ? axisRight : axisLeft, y, this))
149+
.call(maybeTickRotate, tickRotate)
150+
.attr("font-size", null)
151+
.attr("font-family", null)
152+
.attr("font-variant", fontVariant)
153+
.call(!line ? (g) => g.select(".domain").remove() : () => {})
154+
.call(!grid ? () => {} : fx ? gridFacetY(index, fx, -tx) : gridY(offsetSign * (marginLeft + marginRight - width)))
155+
.call(
156+
!label
157+
? () => {}
158+
: (g) =>
159+
g
160+
.append("text")
161+
.attr("fill", "currentColor")
162+
.attr("font-variant", fontVariant == null ? null : "normal")
163+
.attr(
164+
"transform",
165+
`translate(${labelOffset * offsetSign},${
166+
labelAnchor === "center"
167+
? (height + marginTop - marginBottom) / 2
168+
: labelAnchor === "bottom"
169+
? height - marginBottom
170+
: marginTop
171+
})${labelAnchor === "center" ? ` rotate(-90)` : ""}`
172+
)
173+
.attr(
174+
"dy",
175+
labelAnchor === "center"
176+
? axis === "right"
177+
? "-0.32em"
178+
: "0.75em"
179+
: labelAnchor === "bottom"
180+
? "1.4em"
181+
: "-1em"
182+
)
183+
.attr("text-anchor", labelAnchor === "center" ? "middle" : axis === "right" ? "end" : "start")
184+
.text(label)
185+
)
193186
.node();
194187
}
195188
}
196189

197-
function applyAria(selection, {
198-
name,
199-
label,
200-
ariaLabel = `${name}-axis`,
201-
ariaDescription = label
202-
}) {
190+
function applyAria(selection, {name, label, ariaLabel = `${name}-axis`, ariaDescription = label}) {
203191
applyAttr(selection, "aria-label", ariaLabel);
204192
applyAttr(selection, "aria-description", ariaDescription);
205193
}
206194

207195
function gridX(y2) {
208-
return g => g.selectAll(".tick line")
209-
.clone(true)
210-
.attr("stroke-opacity", 0.1)
211-
.attr("y2", y2);
196+
return (g) => g.selectAll(".tick line").clone(true).attr("stroke-opacity", 0.1).attr("y2", y2);
212197
}
213198

214199
function gridY(x2) {
215-
return g => g.selectAll(".tick line")
216-
.clone(true)
217-
.attr("stroke-opacity", 0.1)
218-
.attr("x2", x2);
200+
return (g) => g.selectAll(".tick line").clone(true).attr("stroke-opacity", 0.1).attr("x2", x2);
219201
}
220202

221203
function gridFacetX(index, fy, ty) {
222204
const dy = fy.bandwidth();
223205
const domain = fy.domain();
224-
return g => g.selectAll(".tick")
225-
.append("path")
206+
return (g) =>
207+
g
208+
.selectAll(".tick")
209+
.append("path")
226210
.attr("stroke", "currentColor")
227211
.attr("stroke-opacity", 0.1)
228-
.attr("d", (index ? take(domain, index) : domain).map(v => `M0,${fy(v) + ty}v${dy}`).join(""));
212+
.attr("d", (index ? take(domain, index) : domain).map((v) => `M0,${fy(v) + ty}v${dy}`).join(""));
229213
}
230214

231215
function gridFacetY(index, fx, tx) {
232216
const dx = fx.bandwidth();
233217
const domain = fx.domain();
234-
return g => g.selectAll(".tick")
235-
.append("path")
218+
return (g) =>
219+
g
220+
.selectAll(".tick")
221+
.append("path")
236222
.attr("stroke", "currentColor")
237223
.attr("stroke-opacity", 0.1)
238-
.attr("d", (index ? take(domain, index) : domain).map(v => `M${fx(v) + tx},0h${dx}`).join(""));
224+
.attr("d", (index ? take(domain, index) : domain).map((v) => `M${fx(v) + tx},0h${dx}`).join(""));
239225
}
240226

241227
function maybeTicks(ticks) {
@@ -250,10 +236,13 @@ function maybeTickFormat(tickFormat) {
250236
// an ordinal domain is numbers or dates, and we want null to mean the empty
251237
// string, not the default identity format.
252238
export function maybeAutoTickFormat(tickFormat, domain) {
253-
return tickFormat === undefined ? (isTemporal(domain) ? formatIsoDate : string)
254-
: typeof tickFormat === "function" ? tickFormat
255-
: (typeof tickFormat === "string" ? (isTemporal(domain) ? utcFormat : format)
256-
: constant)(tickFormat);
239+
return tickFormat === undefined
240+
? isTemporal(domain)
241+
? formatIsoDate
242+
: string
243+
: typeof tickFormat === "function"
244+
? tickFormat
245+
: (typeof tickFormat === "string" ? (isTemporal(domain) ? utcFormat : format) : constant)(tickFormat);
257246
}
258247

259248
function createAxis(axis, scale, {ticks, tickSize, tickPadding, tickFormat}) {
@@ -280,7 +269,10 @@ function maybeTickRotate(g, rotate) {
280269
text.setAttribute("text-anchor", Math.abs(rotate) < 10 ? "middle" : (rotate < 0) ^ (s > 0) ? "start" : "end");
281270
} else {
282271
const s = Math.sign(x);
283-
text.setAttribute("transform", `translate(${x + s * 4 * Math.abs(Math.sin(rotate * radians))}, 0) rotate(${rotate})`);
272+
text.setAttribute(
273+
"transform",
274+
`translate(${x + s * 4 * Math.abs(Math.sin(rotate * radians))}, 0) rotate(${rotate})`
275+
);
284276
text.setAttribute("text-anchor", Math.abs(rotate) > 60 ? "middle" : s > 0 ? "start" : "end");
285277
}
286278
text.removeAttribute("x");

0 commit comments

Comments
 (0)