Skip to content

Add the ability to use aggregate values for box plots #138

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

Closed
wants to merge 4 commits into from

Conversation

dkrahmer
Copy link

Add a new calcdataOverride property for box plot objects which will allow calculated box plot values to be replaced. To use, pass the aggregate values as the main data along with calcdataOverride property. Plotly will calculate all of the values so it is only necessary to override some of the values. Look at the calculateStats function in Plotly.js to see the properties that can be overridden.

This is useful if an application only needs Ployly to display the chart but not aggregate all of the raw data points.

Add a new calcdataOverride property for box plot objects which will
allow calculated box plot values to be replaced. To use, pass the
aggregate values as the main data along with calcdataOverride property.
Plotly will calculate all of the values so it is only necessary to
override some of the values. Look at the calculateStats function in
Plotly.js to see the properties that can be overridden.
@etpinard
Copy link
Contributor

@Lepricon49 Thanks for submitting a PR 🍻

I'm afraid that your calcdata-hook solution is too hacky to be merged in.

One alternative would be to wait for the completion of modular milestone where requiring trace module individually will make it possible to override the box calc step.

Another alternative would be to incorporate your calcdataOverride routine into the plotly.js code together with an box trace attribute to turn it on e.g. boxmode: 'aggregate'.

Could you show me your calcdataOverride routine?

@dkrahmer
Copy link
Author

Thank you for your feedback. I agree my change is a bit hacky. The aggregate data I am using comes from a web API written in C# and SQL that calculates all of the data points for each box. This it much more efficient than sending all of the data to the client to be parsed by Plotly.

I like the idea of using boxmode: 'aggregate'. Hopefully I find some time to refactor in the near future. The following code snippet shows how I am using calcdataOverride where plotData is an array of arrays that contain aggregate plot data.

var data = _.map(plotData, function (aggregateDataPointArray) {
    return {
        type: 'box',
        y: aggregateDataPointArray.slice(2),
        calcdataOverride: {
            q1: aggregateDataPointArray[3],
            q3: aggregateDataPointArray[5],
        },
        name: aggregateDataPointArray[0]
    };
})

data is passed to Plotly.newPlot()

"xtext" will cause the text to show in the x-axis hover box instead of
the y-axis
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.

2 participants