-
Notifications
You must be signed in to change notification settings - Fork 14k
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
feat(timeseries-chart): add percentage threshold input control #17758
feat(timeseries-chart): add percentage threshold input control #17758
Conversation
superset-frontend/plugins/plugin-chart-echarts/test/Timeseries/transformProps.test.ts
Show resolved
Hide resolved
@@ -49,8 +53,8 @@ describe('EchartsTimeseries tranformProps', () => { | |||
}; | |||
|
|||
it('should tranform chart props for viz', () => { | |||
const chartProps = new ChartProps(chartPropsConfig); | |||
expect(transformProps(chartProps)).toEqual( | |||
const chartProps: unknown = new ChartProps(chartPropsConfig); |
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.
There are a few prop types described in this component, would any of those work here instead of unknown
? I see unknown
in other spots in your PR and I'm assuming it's because the props change type, but I'm wondering if you might be able to make it work with a thisTypeOfProps | thatTypeOfProps
type of description.
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 am actually not sure what is going on with these. I set it to unknown because TS said I had to before it would let me do the type assertion here chartProps as EchartsTimeseriesChartProps
. It throws an error when I try to set the type of chartProps to EchartsTimeseriesChartProps when it is defined because their formData prop types are incompatible. This is all strange because they don't actually appear to be incompatible because EchartsTimeseriesChartProps is an extension of ChartProps and ChartProps formData prop is set to be an ambiguous object.
This all appears to be done intentionally and I am not sure what I should do to get rid of the errors because I haven't found a similar test file where this isn't causing TS errors. Give me a little time to look into this more because I am not sure what to do at the moment
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.
This specific line should be something like
const chartProps = new ChartProps<EchartsTimeseriesChartProps>(chartPropsConfig);
However, it seems these types are slightly tangled up right now, and should probably be addressed in a follow-up PR, as I believe it's going to require some more type fixing. I'd also want to enable proper type checking for the test folders, but that also requires a separate PR.
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.
This is really nice work @corbinrobb ! Tested to work well, and the code looks really solid, along with very nice tests! One minor nit, but apart from that this looks good to go 👍
@@ -49,8 +53,8 @@ describe('EchartsTimeseries tranformProps', () => { | |||
}; | |||
|
|||
it('should tranform chart props for viz', () => { | |||
const chartProps = new ChartProps(chartPropsConfig); | |||
expect(transformProps(chartProps)).toEqual( | |||
const chartProps: unknown = new ChartProps(chartPropsConfig); |
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.
This specific line should be something like
const chartProps = new ChartProps<EchartsTimeseriesChartProps>(chartPropsConfig);
However, it seems these types are slightly tangled up right now, and should probably be addressed in a follow-up PR, as I believe it's going to require some more type fixing. I'd also want to enable proper type checking for the test folders, but that also requires a separate PR.
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts
Outdated
Show resolved
Hide resolved
…e, and other minor changes
Codecov Report
@@ Coverage Diff @@
## master #17758 +/- ##
==========================================
- Coverage 67.77% 66.32% -1.45%
==========================================
Files 1602 1568 -34
Lines 64151 61455 -2696
Branches 6773 6237 -536
==========================================
- Hits 43476 40759 -2717
- Misses 18822 19099 +277
+ Partials 1853 1597 -256
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
/testenv up |
@lyndsiWilliams Ephemeral environment spinning up at http://34.221.152.42:8080. Credentials are |
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.
Just checked this out on the test environment and it runs just as described - great testing instructions by the way! Since we'll be moving the TS technicalities to another PR, this looks great! Nice job on this! ✨
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.
This look great, amazing job!
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.
One last comment, other than that LGTM!
superset-frontend/plugins/plugin-chart-echarts/src/controls.tsx
Outdated
Show resolved
Hide resolved
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.
LGTM, thanks for the awesome work here!
Ephemeral environment shutdown and build artifacts deleted. |
…e#17758) * feat(timeseries-chart): add percentage threshold control for stack series labels * feat: move threshold vlues to an array * add tests for showValue, onlyTotal, and percentThreshold * feat: add another test * revert ChartProps typesetting, fix misnamed variable on form data type, and other minor changes * fix percentage threshold push equation * fix percentage threshold push equation in tests * change default on control to match form * attempt fix form defaults import Co-authored-by: Corbin Robb <[email protected]>
…e#17758) * feat(timeseries-chart): add percentage threshold control for stack series labels * feat: move threshold vlues to an array * add tests for showValue, onlyTotal, and percentThreshold * feat: add another test * revert ChartProps typesetting, fix misnamed variable on form data type, and other minor changes * fix percentage threshold push equation * fix percentage threshold push equation in tests * change default on control to match form * attempt fix form defaults import Co-authored-by: Corbin Robb <[email protected]>
SUMMARY
Implementation of the feature request in issue #17281
The time-series chart controls have the option to set show values
SHOW VALUE
and stack the seriesSTACK SERIES
. When both are checked there is also the option to show only the series totalsONLY TOTAL
but if you want to see all of the values in the stacks you can uncheckONLY TOTAL
.When
ONLY TOTAL
is unchecked and the data that's being displayed have small or similar values, the chart labels can become cluttered and tend to sit on top of each other making them difficult to read.The enhancement is to add an input where you can enter a minimum percentage threshold that would only display labels for values at or above the threshold.
There is an input just like this over in Pie Chart controls as mentioned and shown in the issue that is referenced at the top of this PR.
SHORT DESCRIPTION
TextControl
Input for the percentage threshold to the Time-series echarts controlstransformProps
to conditionally render the labels if above that thresholdtransformProps
for theshowValue
,onlyTotal
, andpercentageThreshold
propsDETAILED DESCRIPTION
Control Config:
There was already a configuration called
showValueSection
that holds the other controls mentioned so I added the new control to that.I set the visibility to only be true if show_value is true, stack is true, and only_total is false. I also set the default to be 5% matching the control in the Pie Chart plugin because it seemed reasonable.
The
showValueSection
controls are used in these Time Series Charts.All of these charts appear to benefit from this and they all share the same
transformProps
which is where the logic for these controls exist.The logic:
We grab the prop that is passed through
transformProps
by adding it to the list of variables deconstructed out of theformData
prop.Create an array matching the totalStackedValues array but with the calculated threshold value instead of the total.
Pass that down to
transformSeries
when it is gets called on all the series. Then within that function go on down to where theonlyTotal
prop is being checkedBEFORE:
Breaking it down super simply, this
With our
thresholdValues
we can take separate out!onlyTotal
. Then check if the value is greater than or equal to the matching threshold value and return the value or an empty string accordingly.AFTER:
Test cases
Added tests for transformProps to test whether props are being successfully transformed. I couldn't find tests for the other showValue controls so I added a couple for them because I was in the area.
Added test cases for:
Another thing with the tests is that there were a few different TypeScript errors already in
Timeseries/transformProps.test.ts
so I did what I could to get them to calm down.Moving Forward
I wanted to share more thoughts that I had on this feature but feel free to skip over this because it is just ideas.
The TextControl, which is an Antd Input component, works perfectly well but I would say that ideally, we wouldn't want to use a plain input for this control. A percentage can only be between 0 and 100 and the input allows the opportunity to put any numbers into but there isn't a built-in way to add a min and max.
We could add this to the TextControl but I am not the biggest fan of doing this because Antd has the InputNumber component that does have the ability to set a min and max number value. While InputNumber is used in some other places in other controls like with the Y axis bounds, it doesn't appear to have its own control component like the plain Input does with TextControl. I could be wrong about this and if I am please let me know because I would love to try and utilize it for this.
Antd InputNumber link
I also did a version of this with the SliderControl because it felt like it could be a good choice because it has a set range. I ended up deciding against suggesting it for now because it updates the state on
onChange
and that will update on every 'step' in between the starting number and where it ends. Those state updates rerender the chart and it happens a lot it which makes an unpleasantly sluggish experience.I believe we could easily get around this by using the prop
onAfterChange
which is present on Antd slide. The component is currently only usingonChange
but it wouldn't be too hard to have it take the function passed toonChange
and move it toonAfterChange
if needed. We could do this by adding an optional boolean value called something likeupdateAfterChange
and if that is true then change the function to run after the change. I haven't tested this so it might not be quite that simple.I should probably note that
onAfterChange
runs afteronmousup
fires. So it would run when the user is done dragging the slider to the desired value and not for every value in between.Antd Slider link
There is also another option that is shown in the examples on the Slider page where it uses both Slider and InputNumber at the same time while sharing the same state and min/maxes. I liked this one the best because it has both an input and a slider at the same time.
This would require a new control to be made that would combine the two as shown in the Antd Slider examples. I am not sure if this would be useful outside of the Pie Chart and the Time-series charts so it might not be worth making.
Final thoughts for percentage threshold control are:
These are just ideas though and I am probably wrong about the way to implement them but I figured it wouldn't hurt to share.
BEFORE - BAR
AFTER - BAR
BEFORE - LINE
AFTER - LINE
Doesn't show when stacked is false
Doesn't show when stacked is true and only total is true
Shows when stacked is true and only total is false
---
TESTING INSTRUCTIONS
groupby
value set to something with a lot of values. If using Rise & Fall of Video Game Consoles you can leave it on platform or change it to publisher if you are feeling extra spicyCustomize
tab at the top and scroll toChart Options
Bar
SHOW VALUE
andSTACK SERIES
, then uncheckONLY TOTAL
PERCENTAGE THRESHOLD
input appear with a value of 5I would turn on
DATA ZOOM
too so you can get a better look at the values.Other than that check it out however you see fit. Maybe check out all the charts mentioned above.
I found it most useful with the bar chart but it seems to be useful on all of them
ADDITIONAL INFORMATION