-
Notifications
You must be signed in to change notification settings - Fork 196
expose instantiated scales descriptors in the render API #1810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
0726989
9803451
604c6e0
8cdc66e
a52a16f
ebc1604
4282d7a
ad43e42
ded5734
422c6ba
a77c0a2
63f9af5
a7a3537
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,17 +97,21 @@ export function createScales( | |
| return scales; | ||
| } | ||
|
|
||
| export function createScaleFunctions(scales) { | ||
| return Object.fromEntries( | ||
| Object.entries(scales) | ||
| .filter(([, {scale}]) => scale) // drop identity scales | ||
| .map(([name, {scale, type, interval, label}]) => { | ||
| scale.type = type; // for axis | ||
| if (interval != null) scale.interval = interval; // for axis | ||
| if (label != null) scale.label = label; // for axis | ||
| return [name, scale]; | ||
| }) | ||
| ); | ||
| export function createScaleFunctions(descriptors) { | ||
| const scales = {}; | ||
| const scaleFunctions = {scales}; | ||
| for (const [key, desc] of Object.entries(descriptors)) { | ||
| const {scale, type, interval, label} = desc; | ||
| scales[key] = exposeScale(desc); | ||
|
||
| if (scale) { | ||
| scaleFunctions[key] = scale; // drop identity scales | ||
| // TODO: pass these properties, which are needed for axes, in the descriptor. | ||
| scale.type = type; | ||
| if (interval != null) scale.interval = interval; | ||
| if (label != null) scale.label = label; | ||
| } | ||
| } | ||
| return scaleFunctions; | ||
| } | ||
|
|
||
| // Mutates scale.range! | ||
|
|
@@ -513,21 +517,22 @@ export function scale(options = {}) { | |
| return scale; | ||
| } | ||
|
|
||
| export function exposeScales(scaleDescriptors) { | ||
| export function exposeScales(scales) { | ||
| return (key) => { | ||
| if (!registry.has((key = `${key}`))) throw new Error(`unknown scale: ${key}`); | ||
| return key in scaleDescriptors ? exposeScale(scaleDescriptors[key]) : undefined; | ||
| return scales[key]; | ||
| }; | ||
| } | ||
|
|
||
| // Note: axis- and legend-related properties (such as label, ticks and | ||
| // tickFormat) are not included here as they do not affect the scale’s behavior. | ||
| function exposeScale({scale, type, domain, range, interpolate, interval, transform, percent, pivot}) { | ||
| if (type === "identity") return {type: "identity", apply: (d) => d, invert: (d) => d}; | ||
| if (type === "identity") | ||
| return {type: "identity", apply: (d) => d, invert: (d) => d, ...(range !== undefined && {range})}; | ||
| const unknown = scale.unknown ? scale.unknown() : undefined; | ||
| return { | ||
| type, | ||
| domain: slice(domain), // defensive copy | ||
| domain: [...new Set(domain)], // defensive copy, ensure uniqueness | ||
Fil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ...(range !== undefined && {range: slice(range)}), // defensive copy | ||
| ...(transform !== undefined && {transform}), | ||
| ...(percent && {percent}), // only exposed if truthy | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.