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

Rounded Tick Values in Declarative charts #33619

Conversation

Anush2303
Copy link
Contributor

@Anush2303 Anush2303 commented Jan 13, 2025

New Behavior

  1. Added functionality of Rounded tick values in Declarative chart controls:

image

image

  1. Show forecast as dashed line.

image

Related Issue(s)

  • Fixes #

@Anush2303 Anush2303 marked this pull request as ready for review January 13, 2025 04:56
@Anush2303 Anush2303 requested a review from a team as a code owner January 13, 2025 04:56
Copy link

📊 Bundle size report

✅ No changes found

@Anush2303 Anush2303 assigned Anush2303 and AtishayMsft and unassigned Anush2303 Jan 13, 2025
Copy link

Pull request demo site: URL

@Anush2303 Anush2303 changed the base branch from master to user/atisjai/stronglyTypePlotly January 13, 2025 06:36
@srmukher
Copy link
Contributor

@Anush2303 you can add few tests for the changes

@Anush2303
Copy link
Contributor Author

@Anush2303 you can add few tests for the changes

Okay sure.

@AtishayMsft
Copy link
Contributor

Lets get the playwright screenshot diffs for this change

@@ -422,6 +422,7 @@ export class CartesianChartBase
this.isIntegralDataset,
false,
this.props.supportNegativeData!,
this.props.roundedTicks!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roundedTicks

use the same for secondary y axis also

const finalYmin = supportNegativeData
const finalYmax = roundedTicks ? yMaxValue : tempVal > yMaxValue ? tempVal : yMaxValue!;
const finalYmin = roundedTicks
? yMinValue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yMinValue

there is no logic needed when negative y values are present?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think roundedTicks prop is capable of handling the negative y values also. It is taking into account the minimum and maximum y values and passing that from the adapter itself.

): number[] {
if (roundedTicks) {
const ticks = d3Ticks(minVal, maxVal, splitInto);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

splitInto

i think this should be splitInto - 1

Copy link
Contributor Author

@Anush2303 Anush2303 Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the documentation, they mention that approximately count+1 ticks will be produced. In our case, it is working well with 'splitInto'.
For eg. d3.ticks(1, 9, 5) // [2, 4, 6, 8] . Count is 5, but in result it gives only 4.

): number[] {
if (roundedTicks) {
const ticks = d3Ticks(minVal, maxVal, splitInto);
const gap = ticks.length > 1 ? ticks[1] - ticks[0] : 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

How are you determining 1? Ticks can be of any magnitude

Copy link
Contributor Author

@Anush2303 Anush2303 Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is 1 for the case, ticks.length = 1. And we will be having ticks.length=1 when there is only 1 y value. So in that case actually, the default value doesn't matter. I have set it to 1 just to handle the edge case.

ticks.push(ticks[ticks.length - 1] + gap);
}
return ticks;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add UTs for this change.
Move this logic in a separate function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

const ticks = d3Ticks(minVal, maxVal, splitInto);
const gap = ticks.length > 1 ? ticks[1] - ticks[0] : 1;
if (ticks[0] !== minVal) {
ticks.unshift(ticks[0] - gap);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unshift

Does nice ticks solve your purpose.
https://d3js.org/d3-array/ticks#nice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check

): number[] {
if (roundedTicks) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

roundedTicks

Can you share what validations have been performed

@Anush2303
Copy link
Contributor Author

The target branch is already merged. I will be creating a new PR from master with all the comments taken into account.

@AtishayMsft AtishayMsft deleted the branch user/atisjai/stronglyTypePlotly January 27, 2025 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants