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

Improve xAxis ticks, thinner bottom margin #4756

Merged
merged 3 commits into from
Apr 10, 2018

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Apr 4, 2018

Introducing a new control X Tick Layout with options ['auto', 'flat', '45°', 'staggered'] for nvd3 visualizations.

nvd3 visualizations now do a much better job at minimizing the bottom margin in auto mode, and give more control to the user.

Also refactored quite a bit and aligned the controls across charts.

closes #4751

margins

@codecov-io
Copy link

codecov-io commented Apr 4, 2018

Codecov Report

Merging #4756 into master will decrease coverage by 0.24%.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #4756      +/-   ##
=========================================
- Coverage   72.64%   72.4%   -0.25%     
=========================================
  Files         205     207       +2     
  Lines       15402   15494      +92     
  Branches     1183    1194      +11     
=========================================
+ Hits        11189   11218      +29     
- Misses       4210    4273      +63     
  Partials        3       3
Impacted Files Coverage Δ
superset/assets/javascripts/utils/reducerUtils.js 0% <ø> (ø)
...set/assets/javascripts/explore/stores/controls.jsx 39.25% <ø> (ø) ⬆️
...rset/assets/javascripts/explore/stores/visTypes.js 70.58% <ø> (ø) ⬆️
...ascripts/explore/components/URLShortLinkButton.jsx 86.95% <100%> (ø) ⬆️
.../javascripts/SqlLab/components/CopyQueryTabUrl.jsx 78.57% <100%> (ø) ⬆️
superset/assets/javascripts/utils/common.js 48.27% <100%> (ø)
...ssets/javascripts/SqlLab/components/QueryTable.jsx 84.28% <100%> (ø) ⬆️
...ssets/javascripts/explore/components/SaveModal.jsx 93.82% <100%> (ø) ⬆️
superset/assets/javascripts/chart/Chart.jsx 65.25% <33.33%> (+0.29%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ee15fc8...e6ea1f7. Read the comment docs.

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

LGTM, but it seems like superset/assets/visualizations/nvd3_vis.js is becoming (already is?) unmanageable... should we split each nvd3 chart into a separate file?

} else if (fd.x_ticks_layout === 'staggered') {
staggerLabels = true;
} else if (fd.x_ticks_layout === '45°') {
if (fd.show_brush === true || fd.show_brush === 'yes') {
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be a common pattern when we add more options to a control (usually when "auto" is added to an on/off control). Maybe we should have a function called isTruthy, eg:

function isTruthy(obj) {
    if (typeof variable === 'boolean') {
        return obj;
    } else if (typeof variable === 'string') {
        return obj.toLowerCase() !== 'no';
    } else {
        return !!obj;
    }
}

Or maybe not. Just thinking out loud. :)

}
const showBrush = (
fd.show_brush === true ||
fd.show_brush === 'yes' ||
Copy link
Member

Choose a reason for hiding this comment

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

^ here it is, the other use for isTruthy

@mistercrunch
Copy link
Member Author

I agree on the [un] manageability of this file. The challenge is that the different visualizations both from a controls and API standpoint have a lot in common. A lot of code is shared in odd intricate ways. It's a though puzzle.

A balanced way to evolve this would be to refactor out portion of the code into smaller functions an unit test those.

We've been talking about moving to data-ui / vx for a while, and maybe that's the end game and justify not spending too many cycles on nvd3.

@mistercrunch
Copy link
Member Author

@graceguo-supercat @michellethomas would love for someone at Airbnb to sign off on this as it will affects a million line charts over there, but that should be for the best.

@williaster
Copy link
Contributor

great addition. my only suggestion at this point is setting flat as the default because staggered isn't as polished / adds visual noise to the chart. thoughts @elibrumbaugh?

as discussed offline, in the future it'd be useful to add a "concise"/"compact" version of the auto time format to help fix this problem. this could be used for axes and the "detailed" version could be used in tooltips.

@mistercrunch
Copy link
Member Author

I'd also prefer flat to staggered as a default, but with the current default time formatter the labels overlap in some situation, depending on the time grain (some are wider) and on the width (d3.axis fits more or less tick density in ways we don't control).

Maybe next PR on this we'd go:

  • new default auto format that's shorter than current Adaptive formatting
  • use flat as new default
  • somehow squeeze Adaptive formatting as the tooltip formatter (should be possible)

The magic formatting is the part where the devil is in the detail and people may not agree on the exact layout. Here's a link to the code we have now:
https://github.com/apache/incubator-superset/blob/master/superset/assets/javascripts/modules/dates.js#L15

Oh and we haven't even talked about locales :(

@williaster
Copy link
Contributor

is there a rush to merge this? would it be worthwhile to add the shorter date formatting in this PR and set the default to flat?

the main concern I have is with saved slices, by merging this staggered is set for any slices saved for the foreseeable future and I'd guess users wouldn't go to the trouble to update them after the new concise time is added. another option would be a migration script to change them to flat, but that seems tricky?

@mistercrunch
Copy link
Member Author

Actually the default setting is auto, which turns into staggered for time series. We can change what auto means in the future. Same goes with Adaptive formatting.

@mistercrunch
Copy link
Member Author

But yeah, while this doesn't fix everything, it addresses many visualizations defects and bugs with the xAxis and makes much better use of real estate. It also does not change the content of the labels which could be controversial and could be considered breaking backwards compatibility.

It also improves the organization of axis-related controls for many chart types, making more consistent.

@williaster
Copy link
Contributor

ah, that's nice about the auto setting. I'd like to get the flat in asap so users see staggered for the minimum amount of time, I'll begin work on the concise date logic!

@mistercrunch
Copy link
Member Author

@williaster I agree with flat but didn't want to drive it myself as it may upset some users since we have to redefine/shorten Adaptive formatting as a prerequisite (I think the current definition was fine tuned by data scientists at Airbnb, forgot who but it's in the git history). It will also change the way thousands of line charts look like at Airbnb...

You have my blessing to figure out better defaults that will please a majority of users. One key point is that day-of-week is very important to both Airbnb and Lyft given the strong weekly cycles, I wouldn't kick this out, better removing YYYY than removing 3-letters day-of-week.

@mistercrunch
Copy link
Member Author

I'll wait on @graceguo-supercat's review before merging this

@@ -86,3 +86,12 @@ export function getShortUrl(longUrl, callback) {
},
});
}

export function isTruthy(obj) {
Copy link
Contributor

Choose a reason for hiding this comment

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

acknowledging I have very little context here- this seems like a bad road to go down. We use YAML for plenty of stuff over here and there have been many issues caused by someone not expecting True/t/yes to be true...

Copy link
Member Author

Choose a reason for hiding this comment

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

It has to do with backward compatibility here. There's been a few instances of CheckboxControl becoming a SelectControl. In this case the show_brush used to be checkbox and now is auto, Yes or 'No'.

Since it's not the first time and won't be the last, we decided to go this route.

The alternatives would be to either:

  • write database migrations to alter all slices and replace True with 'Yes' but that's more work and db migration have maintenance overhead.
  • systematically use if (fd.show_brush === true || fd.show_brush === 'yes') everywhere

@graceguo-supercat
Copy link

@mistercrunch This PR works good in airbnb data! please merge whenever you feel comfortable. Thanks!

@mistercrunch mistercrunch merged commit 1e7a294 into apache:master Apr 10, 2018
mistercrunch added a commit to mistercrunch/superset that referenced this pull request Apr 12, 2018
* Improve xAxis ticks, thinner bottom margin

* Moving utils folder

* Add isTruthy
mistercrunch added a commit that referenced this pull request Apr 13, 2018
* Improve xAxis ticks, thinner bottom margin (#4756)

* Improve xAxis ticks, thinner bottom margin

* Moving utils folder

* Add isTruthy

* Addressing comments

* Set cell_padding to 0

* merging db migrations
michellethomas pushed a commit to michellethomas/panoramix that referenced this pull request May 24, 2018
* Improve xAxis ticks, thinner bottom margin

* Moving utils folder

* Add isTruthy
michellethomas pushed a commit to michellethomas/panoramix that referenced this pull request May 24, 2018
* Improve xAxis ticks, thinner bottom margin (apache#4756)

* Improve xAxis ticks, thinner bottom margin

* Moving utils folder

* Add isTruthy

* Addressing comments

* Set cell_padding to 0

* merging db migrations
timifasubaa pushed a commit to timifasubaa/incubator-superset that referenced this pull request May 31, 2018
* Improve xAxis ticks, thinner bottom margin

* Moving utils folder

* Add isTruthy
timifasubaa pushed a commit to timifasubaa/incubator-superset that referenced this pull request May 31, 2018
* Improve xAxis ticks, thinner bottom margin (apache#4756)

* Improve xAxis ticks, thinner bottom margin

* Moving utils folder

* Add isTruthy

* Addressing comments

* Set cell_padding to 0

* merging db migrations
wenchma pushed a commit to wenchma/incubator-superset that referenced this pull request Nov 16, 2018
* Improve xAxis ticks, thinner bottom margin

* Moving utils folder

* Add isTruthy
wenchma pushed a commit to wenchma/incubator-superset that referenced this pull request Nov 16, 2018
* Improve xAxis ticks, thinner bottom margin (apache#4756)

* Improve xAxis ticks, thinner bottom margin

* Moving utils folder

* Add isTruthy

* Addressing comments

* Set cell_padding to 0

* merging db migrations
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.25.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.25.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[P00 - Dashboard] Chart whitespace customization
6 participants