Skip to content
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

[charts] Allow basic customization of Sparkline y-axis #13316

Closed
marvinruder opened this issue May 30, 2024 · 8 comments · Fixed by #15294
Closed

[charts] Allow basic customization of Sparkline y-axis #13316

marvinruder opened this issue May 30, 2024 · 8 comments · Fixed by #15294
Labels
component: charts This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@marvinruder
Copy link
Contributor

marvinruder commented May 30, 2024

Summary

Right now the scaling mechanism of the y-axis in sparkline charts is somewhat obscure to me, and there are no parameters that influence that scale. It would be great to at least have a way to set the min and max values on the y-axis.

Examples

The following two sparklines have the same parameters except for color and dataset:

image

(The numbers below the slider on the left show the min and max values in the datasets)

Both svgs have a height of 42px. The upper one’s line is 32px high, the lower one’s line is 14px high. Why? How are the min and max values of the y axis calculated?

Motivation

I want my sparklines to fill the entire area made available to the svg element, i.e., the min and max values of the dataset should match the min and max values of the y-axis. A property for configuring those axis values would allow such customization.

Search keywords: sparkline

@marvinruder marvinruder added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 30, 2024
@alexfauquette
Copy link
Member

Both svgs have a height of 42px. The upper one’s line is 32px high, the lower one’s line is 14px high. Why? How are the min and max values of the y axis calculated?

Surprising that you don't have access to the y-axis config. That's definitely something we could fix.

The reason why the chart does not fill the entire space is the use of .nice() from D3js to define ranges. We use it it to ensure ticks will have nice values, but in your use case, the value varies between 189 and 267, I assume it extends the range to 100, 300 which leaves a lot of white space.

We coudl propagate the yAxis in sparkline, and add a parameter skipNice that would skip this step

@alexfauquette alexfauquette added enhancement This is not a bug, nor a new feature component: charts This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 31, 2024
@jisotalo
Copy link

+1 The min and max values for y-axis would definetely be an important feature!

For example, if plotting percentage data (0...100%) now with dataset containing only small values (say between 0...20%), the plot scales between that range and user could get an idea of high values.

By setting y-axis to always be 0...100%, it would make more sense.

@alexfauquette
Copy link
Member

The next release will allow you to specify the min/max of y-axis.

We are still thinking about what could be a good DX to take control of this nice() step

@alexfauquette
Copy link
Member

alexfauquette commented Jul 22, 2024

@JCQuintas what do you think about this property?

/**
 * Defines the axis scale domain based on the min/max values of series linked to it.
 * - 'nice': Uses the `.nice()` method from d3-scale to round the domain at human friendly values.
 * - 'strict': Set the domain to the min/max value displayed. No extras space is added.
 * - function: takes as an argument an array with the min/max displayed values, and return the domain.
 */
domainDefinition?: 'nice' | 'strict' | ([Value, Value]) => [Value, Value]

@JCQuintas
Copy link
Member

Seems promising. Not sure about the naming, maybe domainRange? domainLimit?

@alexfauquette
Copy link
Member

Will go with domainLimit since domainRange mixes two notions of D3: domain (the values) and range (the px)

@alexfauquette alexfauquette added the good first issue Great for first contributions. Enable to learn the contribution process. label Jul 25, 2024
@alexfauquette
Copy link
Member

alexfauquette commented Jul 25, 2024

If someone wants to pick this issue, here are the file of interest

// TODO: move nice to prop? Disable when there is zoom?
const scale = getScale(scaleType, axisExtremums, zoomedRange).nice(rawTickNumber);
const [minDomain, maxDomain] = scale.domain();
const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];

Copy link

github-actions bot commented Nov 7, 2024

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@marvinruder How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: charts This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants