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

Closes #374: Truncating x-axis should be done to ticktext not x values. #378

Merged
merged 1 commit into from
Apr 20, 2018

Conversation

emtwo
Copy link

@emtwo emtwo commented Apr 19, 2018

For some context/background:

  1. This commit originally did x-axis truncation but only for pie charts: 3087822
  2. A similar method of truncation was used in this commit to also be applied to other charts: eb1b3cb
  3. Issue Redash visualizations not rendering for some number types #374 came up because when x-axis values were numeric, the attempt to truncate them failed. This turned out to be the case for pie charts too but I suppose they aren't used as often so the issue was not filed sooner.
  4. This PR keeps tickvals as the original numeric values but adds an additional array of truncated text, ticktext. The truncation issue should still be resolved as well as the ability to have numeric x-axis values.

Here are a couple of queries to test with:

For numeric x-axis:

WITH sample AS
    (select 26191 as a, 121370 as b, 21.58 as c union
     select 26591 as a, 121170 as b, 11.53 as c union
     select 26598 as a, 121170 as b, 22.58 as c union
     select 26594 as a, 121170 as b, 41.58 as c union
     select 26592 as a, 121170 as b, 51.58 as c union
     select 16596 as a, 121170 as b, 11.58 as c union
     select 26593 as a, 121170 as b, 31.58 as c union
     select 26597 as a, 121170 as b, 81.58 as c union
     select 56599 as a, 121170 as b, 21.58 as c)
select a, b, c from sample

For correctly truncated x-axis:

WITH sample as (
    select '2017-12-10 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-11 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-12 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-13 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-14 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-15 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-16 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-17 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-18 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-19 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-20 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-21 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-22 00:00' as x, 'US' as type, 8215767 as foo union
    select '2017-12-23 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-24 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-25 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-26 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-27 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-28 00:00' as x, 'US' as type, 8215767 as foo union
    select '2017-12-29 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-30 00:00' as x, 'US' as type, 8215767 as foo union
    select '2017-12-31 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-32 00:00' as x, 'US' as type, 8215767 as foo union
    select '2017-12-33 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-34 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-35 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-36 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-37 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-38 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-39 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-40 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-41 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-42 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-43 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-44 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-45 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-46 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-47 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-48 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-49 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-50 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-51 00:00' as x, 'US' as type, 574047 as foo union
    select '2017-12-52 00:00' as x, 'ROW' as type, 8215767 as foo)
select * from sample

@jezdez jezdez self-requested a review April 19, 2018 18:29
Copy link

@jezdez jezdez left a comment

Choose a reason for hiding this comment

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

rwc+

}
if (ticktext && tickvals) {
result.xaxis.ticktext = ticktext;
result.xaxis.tickvals = tickvals;
Copy link

Choose a reason for hiding this comment

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

Looks good to me, I didn't know about ticktext, looking at https://plot.ly/javascript/axes/#enumerated-ticks-with-tickvals-and-ticktext made it more clear what it looks like. Maybe add a comment on where that comes from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants