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

Fix: area chart stacking doesn't work #1061

Merged
merged 6 commits into from
Jun 1, 2016
Merged

Fix: area chart stacking doesn't work #1061

merged 6 commits into from
Jun 1, 2016

Conversation

machira
Copy link

@machira machira commented May 17, 2016

This PR addresses issue #948 as recommended by Plotly maintainers here.

Specifically, we recalculate the data appearance when the legend is clicked. This ensures that we show existing series at the updated heights.

We also fix the behaviour of percentage area plots. Here, if the legend is clicked to disable a given series, the visualization is refreshed so that only enabled series are plotted. The percentage total is still calculated over the all series. This is designed to be consistent with the percentage bar charts, where after disabling a given series, the plotted visualizations add up to less than 100%.

Raymond Machira added 2 commits May 17, 2016 15:49
This fixes issue #948 where stacked area plots do not update once series are enabled/disabled using the legend.
It also fixes the behaviour of percentage stack area plots, so as to have similar behaviour to percentage stacked bar charts.
};

var getEnabledSeries = function(seriesList){
return _.filter(seriesList, function(series) {
Copy link
Member

Choose a reason for hiding this comment

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

You can write this as _.filter(seriesList, 'visible');.

Copy link
Author

Choose a reason for hiding this comment

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

Actually, this would not be the same. Because of Javascript truthiness, when series.visible = 'legendonly' would evaluate to true.

Copy link
Member

Choose a reason for hiding this comment

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

👍

@arikfr arikfr changed the title Fix/area plots Fix: area chart stacking doesn't work May 23, 2016
@arikfr
Copy link
Member

arikfr commented May 23, 2016

Overall looks good. Did you test it with a chart having multiple types of series (bars & line, for example)?

element.on('plotly_afterplot', function(d) {
if(scope.options.globalSeriesType === 'area' && (scope.options.series.stacking === 'normal' || scope.options.series.stacking === 'percent')){
d3.selectAll('.legendtoggle').each(function(d, i) {
// override plotly's default legend item on-click behaviour
Copy link
Member

Choose a reason for hiding this comment

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

What's the default behavior? Do we "un-override" it when the types changes?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the suggestion. We went back and took a look at it. It turns out we can use a custom listener through d3, and remove it when chart type changes.

Raymond Machira added 2 commits May 24, 2016 17:54
… the event may be used. Also removes the event listener when type of chart changes.
@machira
Copy link
Author

machira commented May 24, 2016

It looks like multiple series (bar and Area) breaks the stacking. I will keep looking at it, and update you if I find a workaround.

@arikfr
Copy link
Member

arikfr commented May 25, 2016

@machira ok, let me know if you find a solution. We can merge as is if you prefer, because it's still better than current situation.

…acking. - selects legend divs from current graph only (instead of selecting from the entire dom)
@vorakumar
Copy link
Contributor

Hey Arik, we have updated the PR with some new changes. Some additional tests here showed some edge cases we hadn't thought of- such as edit mode. The most recent push works as expected. And multiple series (area and line) also seem to work appropriately.

@@ -121,7 +144,6 @@
angular.module('plotly', [])
.constant('ColorPalette', ColorPalette)
.directive('plotlyChart', function () {
var bottomMargin = 50;
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean to remove this and the related code?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

@arikfr, No, we didn't mean to do that. It's now fixed.

@arikfr
Copy link
Member

arikfr commented May 26, 2016

@vorakumar thanks! I appreciate the effort you put here.

@vorakumar
Copy link
Contributor

major work has been done by @machira

@arikfr
Copy link
Member

arikfr commented May 26, 2016

By "you" I meant all of you at ThoughtWorks :-)

@rohanpd
Copy link

rohanpd commented May 29, 2016

I have seen splunk do this in a different way that might be worth considering:

image

When you hover over the legend it just highlights the slice that you are analysing:

image

In saying that, I'm happy with what you guys have suggested.

# Conflicts:
#	rd_ui/app/scripts/directives/plotly.js
@arikfr arikfr merged commit 2bc0b27 into getredash:master Jun 1, 2016
@arikfr
Copy link
Member

arikfr commented Jun 1, 2016

Merged 🎉

simo7 pushed a commit to pubnative/redash that referenced this pull request Sep 22, 2016
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.

4 participants