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

Granular options for on-chart editing #1895

Merged
merged 4 commits into from
Jul 19, 2017
Merged

Granular options for on-chart editing #1895

merged 4 commits into from
Jul 19, 2017

Conversation

alexcjohnson
Copy link
Collaborator

Adds a new config option edits that's an object of all the separate editable interactions you want to enable or disable. The original config.editable should still be a boolean (default false as always) that sets the defaults for all our supported editable interactions, and config.edits can override pieces of it. For example if you only want to enable editing legend entries, and axis titles and moving the legend, you could do:

Plotly.newPlot(gd, data, layout, {
    edits: {legendText: true, axisTitleText: true, legendPosition: true}
})

closes #1872

cc @etpinard @geocosmite

I chose to be fairly granular - for example, annotations have three separate flags (annotationText, annotationPosition, and annotationTail, on the idea that for example you might want to allow someone to move an annotation but not change the length/direction of the arrow) but there are some other things we could segment further if desired (axisTitleText could be replaced by xaxisTitleText and yaxisTitleText for example). Did I strike the right balance?

@alexcjohnson alexcjohnson added this to the 1.29.0 milestone Jul 18, 2017
@@ -397,7 +397,7 @@ function opaqueSetBackground(gd, bgColor) {
}

function setPlotContext(gd, config) {
if(!gd._context) gd._context = Lib.extendFlat({}, Plotly.defaultConfig);
if(!gd._context) gd._context = Lib.extendDeep({}, Plotly.defaultConfig);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. Maybe config isn't as poorly tested than I thought.

var legendItem = d[0],
bg = d3.select(this).select('.legendtoggle');

bg.call(Drawing.setRect,
Copy link
Contributor

Choose a reason for hiding this comment

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

lovely commit 🎉

@@ -128,8 +130,11 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
var annTextGroup = annGroup.append('g')
.classed('annotation-text-g', true);

var editTextPosition = edits[options.showarrow ? 'annotationTail' : 'annotationPosition'];
var textEvents = options.captureevents || edits.annotationText || editTextPosition;
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to address this now, but this seems like the right place to reference #1750

});
})
.then(function() {
return Plotly.newPlot(gd, data, layout, {
Copy link
Contributor

Choose a reason for hiding this comment

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

For completeness, calling Plotly.plot instead of Plotly.newPlot would do the same here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, I guess since we don't remove gd._context on purge I could omit data and layout here and that would be equivalent, just changing the config. I've just been tending to avoid Plotly.plot since its effects on existing plots are a little strange.

gd = createGraphDiv();
});

function initPlot(editFlag) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice tests 🎉

@etpinard
Copy link
Contributor

(axisTitleText could be replaced by xaxisTitleText and yaxisTitleText for example). Did I strike the right balance?

I think so 👍

@etpinard
Copy link
Contributor

💃

@alexcjohnson alexcjohnson merged commit d97a659 into master Jul 19, 2017
@alexcjohnson alexcjohnson deleted the edit-parts branch July 19, 2017 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for the "config.editable" parameter as an object
2 participants