Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const plot2 = Plot.plot({…, color: plot1.scale("color")});

The returned scale object represents the actual (or “materialized”) values encountered in the plot, including the domain, range, interpolate function, *etc.* The scale’s label, if any, is also returned; however, note that other axis properties are not currently exposed.

For convenience, an apply method is exposed, which returns the scale’s output for any given input. When applicable, an invert method is exposed, which returns the corresponding input from the scale’s domain for any given output.
For convenience, an apply method is exposed, which returns the scale’s output for any given input. When applicable, an invert method is exposed, which returns the corresponding input from the scale’s domain for any given output. Point and band scales also expose their materialized bandwidth and step.

The scale object is undefined if the associated plot has no scale with the given *name*, and throws an error if the *name* is invalid (*i.e.*, not one of the known scale names: *x*, *y*, *fx*, *fy*, *r*, *color*, or *opacity*).

Expand Down
1 change: 1 addition & 0 deletions src/scales.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ function exposeScale({
// band, point
...scale.align && {align: scale.align(), round: scale.round()},
...scale.padding && (scale.paddingInner ? {paddingInner: scale.paddingInner(), paddingOuter: scale.paddingOuter()} : {padding: scale.padding()}),
...scale.bandwidth && {bandwidth: scale.bandwidth(), step: scale.step()},

// utilities
apply: t => scale(t),
Expand Down
20 changes: 20 additions & 0 deletions test/scales/scales-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ it("plot(…).scale('x') can return a point scale", () => {
range: [20, 620],
padding: 0.5,
align: 0.5,
bandwidth: 0,
step: 300,
round: true
});
});
Expand All @@ -113,6 +115,8 @@ it("plot(…).scale('x') can return a point scale, respecting the specified alig
range: [20, 620],
padding: -0.2,
align: 1,
bandwidth: 0,
step: 600,
round: true
});
});
Expand All @@ -125,6 +129,8 @@ it("plot(…).scale('x') can promote a reversed point scale to a point scale wit
range: [20, 620],
padding: 0.5,
align: 0.5,
bandwidth: 0,
step: 300,
round: true
});
});
Expand All @@ -138,6 +144,8 @@ it("plot(…).scale('x') can return a band scale", () => {
paddingInner: 0.1,
paddingOuter: 0.1,
align: 0.5,
bandwidth: 257,
step: 285,
round: true
});
});
Expand All @@ -151,6 +159,8 @@ it("plot(…).scale('x') can return an explicit band scale", () => {
paddingInner: 0.1,
paddingOuter: 0.1,
align: 0.5,
bandwidth: 257,
step: 285,
round: true
});
});
Expand All @@ -164,6 +174,8 @@ it("plot(…).scale('x') can promote a reversed band scale to a band scale with
paddingInner: 0.1,
paddingOuter: 0.1,
align: 0.5,
bandwidth: 257,
step: 285,
round: true
});
});
Expand All @@ -188,6 +200,8 @@ it("plot(…).scale('y') can return a band scale", () => {
paddingInner: 0.1,
paddingOuter: 0.1,
align: 0.5,
bandwidth: 25,
step: 28,
round: true
});
});
Expand All @@ -201,6 +215,8 @@ it("plot(…).scale('y') can return a band scale, respecting the specified align
paddingInner: 0.1,
paddingOuter: -0.2,
align: 1,
bandwidth: 36,
step: 40,
round: true
});
});
Expand All @@ -227,6 +243,8 @@ it("plot(…).scale('fx') can return a band scale", () => {
align: 0.5,
paddingInner: 0.1,
paddingOuter: 0,
bandwidth: 275,
step: 305,
round: true
});
});
Expand All @@ -241,6 +259,8 @@ it("plot(…).scale('fy') can return a band scale", () => {
align: 0.5,
paddingInner: 0.1,
paddingOuter: 0,
bandwidth: 170,
step: 189,
round: true
});
});
Expand Down