-
Notifications
You must be signed in to change notification settings - Fork 272
feat: change font size on responsive for sankey and sunburst chart #977
feat: change font size on responsive for sankey and sunburst chart #977
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/superset/superset-ui/8h5E6QySGfU2pajt8MfGLpLUH5D9 |
Codecov Report
@@ Coverage Diff @@
## master #977 +/- ##
==========================================
+ Coverage 28.04% 28.10% +0.06%
==========================================
Files 408 413 +5
Lines 8345 8473 +128
Branches 1166 1198 +32
==========================================
+ Hits 2340 2381 +41
- Misses 5861 5939 +78
- Partials 144 153 +9
Continue to review full report at Codecov.
|
Thank you for the PR!
For Sankey,
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great step forward for making charts adapt to their size! Let's keep iterating on these and try to establish a good pattern that we can start applying to all charts.
} | ||
.dashboard .superset-legacy-chart-sankey.l text, .dashboard .superset-legacy-chart-sankey .sankey-tooltip { | ||
font-size: 0.8em; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: line change
@@ -187,7 +204,7 @@ function Sankey(element, props) { | |||
.attr('dy', '.35em') | |||
.attr('text-anchor', 'end') | |||
.attr('transform', null) | |||
.text(d => d.name) | |||
.text(d => (responsiveClass === 'xs' ? '' : d.name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have a class name for hiding the labels other than xs
(no good ideas to propose right now, but thinking out loud)
Screen.Recording.2021-02-26.at.15.48.48.mov |
Screen.Recording.2021-03-02.at.11.51.38.mov |
@maloun96 Thanks Victor, can you confirm |
@@ -22,6 +22,8 @@ import d3 from 'd3'; | |||
import PropTypes from 'prop-types'; | |||
import { sankey as d3Sankey } from 'd3-sankey'; | |||
import { getNumberFormatter, NumberFormats, CategoricalColorNamespace } from '@superset-ui/core'; | |||
import './Sankey.css'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use styled components instead of adding new CSS files.
E.g.
superset-ui/plugins/legacy-plugin-chart-parallel-coordinates/src/ReactParallelCoordinates.jsx
Line 36 in 482da21
export default styled(ParallelCoordianes)` |
Then you can pass width
to the styled component to calculate a responsive font-size directly.
Here is demo for dashboard, edit dashboard and explore mode. Screen.Recording.2021-03-03.at.14.24.30.movScreen.Recording.2021-03-03.at.14.27.45.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments. I think this is a great step forward, but the problem main problem I feel is that we're too eagerly disabling labels here; I believe it would be very important to only disable the labels that occupy space that has already been taken. It should be possible by collecting all labels that have been determined not to overlap with previous rectangles in an array, and then check for collisions with the next element until the full list of elements have been processed. At worst it will be O(n^2), but perhaps we could put some hard limit on maximum amount of elements to be tested for overlap. Also, even with 100 elements, it would be 100*99/2=4950 iterations at maximum, which I feel should be quite manageable.
const areOverlapping = elementsAreOverlapping(elements); | ||
|
||
if (!areOverlapping) { | ||
elements.forEach(el => el.classList.remove('opacity-0')); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if this only disabled the elements that occupy space that has already been taken. It would be nice if elementsAreOverlapping
would return the elements that need to be visible/invisible, and those would then have their opacity changed.
Screen.Recording.2021-03-05.at.14.26.48.movScreen.Recording.2021-03-05.at.14.24.37.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good, much better than before! One minor observation: it appears that on some collisions, both elements get wiped out despite only one really needing to be hidden (See "Land Use Change" vs "Deforestation", where "Deforestation" probably wouldn't need to be hidden). I wonder if the hiding logic could somehow be refined to take this into consideration?
@villebro The solution is to hide both elements if they overlap, we can adjust the code to hide only 1 element if needed but will cost performance. |
@maloun96 ok, let's leave it for the backlog if this becomes a problem. |
…pache-superset#977) * feat: change font size on responsive * remove logs * Sunburst * WIP * Sankey label hide * Format correct object * add styled components * Replace document with container * Return overlapping elements * Drag * Fix lint * Fix test & make tooltip absoliute based on cursor position * Update storybook for charts * Resizable in separate page * Fix responsive class for sunburst * type
Make sunburst and sankey chart responsive
BEFORE
Screen.Recording.2021-02-25.at.14.33.02.mov
AFTER
Screen.Recording.2021-03-04.at.15.16.42.mov
STORYBOOK
Screen.Recording.2021-03-05.at.14.26.48.mov
Screen.Recording.2021-03-05.at.14.24.37.mov