Skip to content
This repository was archived by the owner on Dec 10, 2021. It is now read-only.

fix(plugin-chart-echarts): improve ECharts visuals#806

Merged
villebro merged 5 commits intoapache-superset:masterfrom
preset-io:villebro/yaxis-scale
Oct 14, 2020
Merged

fix(plugin-chart-echarts): improve ECharts visuals#806
villebro merged 5 commits intoapache-superset:masterfrom
preset-io:villebro/yaxis-scale

Conversation

@villebro
Copy link
Contributor

@villebro villebro commented Oct 13, 2020

🏆 Enhancements

Improve ECharts plugin visuals. Changes:

Pie

  • Disable outside label line by default and add a control to enable it. Feature parity with NVD3 Pie.
  • Change label color to black by default (looks less messy when labels inside). Feature parity with NVD3 Pie.
  • Added customizable minimum percentage threshold (default: 5 %) to be able to remove labels for thin slices. Feature parity with NVD3 Pie.
  • hover now doesn't change font size, only bolds the text (less invasive). Feature parity with NVD3 Pie.

Timeseries

  • Add y-axis truncate option (default: enabled). Feature parity with NVD3 Line.
  • Add y-axis bounds (min, max). Feature parity with NVD3 Line.

Storybook

  • Add Pie Chart case (population) with multiple thin slices to demonstrate minimum percentage threshold.
  • Add missing controls to Pie and Timeseries.

Screenshot from Storybook demonstrating lower threshold with lots of thin slices:
image

Same with labels outside:
image

Screenshot of chart where a slice below the threshold is hovered above.
image

Truncate and bounds on y-axis:
truncate

@villebro villebro requested a review from a team as a code owner October 13, 2020 08:49
@vercel
Copy link

vercel bot commented Oct 13, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/superset/superset-ui/ilmqpv9ot
✅ Preview: https://superset-ui-git-villebro-yaxis-scale.superset.vercel.app

@codecov
Copy link

codecov bot commented Oct 13, 2020

Codecov Report

Merging #806 into master will increase coverage by 0.07%.
The diff coverage is 61.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #806      +/-   ##
==========================================
+ Coverage   25.50%   25.57%   +0.07%     
==========================================
  Files         358      359       +1     
  Lines        7937     7949      +12     
  Branches     1051     1056       +5     
==========================================
+ Hits         2024     2033       +9     
- Misses       5792     5796       +4     
+ Partials      121      120       -1     
Impacted Files Coverage Δ
...plugin-chart-echarts/src/BoxPlot/transformProps.ts 52.63% <ø> (ø)
...ugin-chart-echarts/src/Timeseries/controlPanel.tsx 100.00% <ø> (ø)
...gin-chart-echarts/src/Timeseries/transformProps.ts 27.08% <20.00%> (+0.41%) ⬆️
...ins/plugin-chart-echarts/src/Pie/transformProps.ts 73.80% <57.14%> (+0.12%) ⬆️
plugins/plugin-chart-echarts/src/Pie/buildQuery.ts 100.00% <100.00%> (ø)
...ugins/plugin-chart-echarts/src/Pie/controlPanel.ts 100.00% <100.00%> (ø)
plugins/plugin-chart-echarts/src/defaults.ts 100.00% <100.00%> (ø)

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 7671c65...674d1d6. Read the comment docs.

{
name: 'show_labels_threshold',
config: {
type: 'TextControl',
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT(optional/out-of-scope-for-this-pr): slider could be cool here eventually. I just discovered how cool the antd sliders are! https://ant.design/components/slider/

Copy link
Contributor Author

@villebro villebro Oct 14, 2020

Choose a reason for hiding this comment

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

Oh yeah, that Slider with input number looks perfect. I tinkered with the existing slider control, but it felt clunky as it doesn't allow for setting decimals, which in this case is often relevant. Let's refactor the SliderControl to use AntD in a follow-up PR and change this when that's in place.

Comment on lines 115 to 117
let [yAxisMin, yAxisMax] = yAxisBounds || [];
if (yAxisMin === undefined && contributionMode === 'row' && stack) yAxisMin = 0;
if (yAxisMax === undefined && contributionMode === 'row' && stack) yAxisMax = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

This section is fairly opaque and hard to read, wondering if/how much ts can help prevent issues around undef with more types hints here. Nothing outrageous though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, will refactor.

min: contributionMode === 'row' && stack ? 0 : undefined,
max: contributionMode === 'row' && stack ? 1 : undefined,
// these might be NaN which break the y axis
min: yAxisMin || undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

related to the comment above, but what else than int/undef could it be? Also I think 0 would be switched to undef here as 0 || undefined === undefined which seems like it's not desirable if someone wanted 0 to be the bound

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops!


// yAxisBounds sometimes starts returning NaNs, which messes up the u-axis
let [min, max] = (yAxisBounds || []).map((val?: number) =>
val !== undefined && Number.isNaN(val) ? undefined : val,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently TS doesn't allow for Number.isNaN(undefined), hence the seemingly unnecessary check for undefined here..

Copy link
Contributor

Choose a reason for hiding this comment

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

You can probably just do yAxisBounds.map(Number) and use Number.isNaN check later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, looks much better!

Copy link
Contributor

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

LGTM!

return buildQueryContext(formData, baseQueryObject => [
{
...baseQueryObject,
orderby: [[metric, false]],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now needed to do descending ordering by the chosen metric: apache/superset#11153

@villebro villebro merged commit 23c327c into apache-superset:master Oct 14, 2020
@villebro villebro deleted the villebro/yaxis-scale branch October 14, 2020 07:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants