Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
Granular options for on-chart editing#1895
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -312,7 +312,7 @@ module.exports = function draw(gd) { | ||
| }); | ||
| } | ||
| if(gd._context.editable) { | ||
| if(gd._context.edits.legendPosition) { | ||
| var xf, yf, x0, y0; | ||
| legend.classed('cursor-move', true); | ||
| @@ -385,7 +385,7 @@ function drawTexts(g, gd) { | ||
| }); | ||
| } | ||
| if(gd._context.editable && !isPie) { | ||
| if(gd._context.edits.legendText && !isPie) { | ||
| text.call(svgTextUtils.makeEditable, {gd: gd}) | ||
| .call(textLayout) | ||
| .on('edit', function(text) { | ||
| @@ -597,10 +597,15 @@ function computeTextDimensions(g, gd) { | ||
| } | ||
| function computeLegendDimensions(gd, groups, traces) { | ||
| var fullLayout = gd._fullLayout, | ||
| opts = fullLayout.legend, | ||
| borderwidth = opts.borderwidth, | ||
| isGrouped = helpers.isGrouped(opts); | ||
| var fullLayout = gd._fullLayout; | ||
| var opts = fullLayout.legend; | ||
| var borderwidth = opts.borderwidth; | ||
| var isGrouped = helpers.isGrouped(opts); | ||
| var extraWidth = 0; | ||
| opts.width = 0; | ||
| opts.height = 0; | ||
| if(helpers.isVertical(opts)) { | ||
| if(isGrouped) { | ||
| @@ -609,9 +614,6 @@ function computeLegendDimensions(gd, groups, traces) { | ||
| }); | ||
| } | ||
| opts.width = 0; | ||
| opts.height = 0; | ||
| traces.each(function(d) { | ||
| var legendItem = d[0], | ||
| textHeight = legendItem.height, | ||
| @@ -632,26 +634,9 @@ function computeLegendDimensions(gd, groups, traces) { | ||
| opts.height += (opts._lgroupsLength - 1) * opts.tracegroupgap; | ||
| } | ||
| // make sure we're only getting full pixels | ||
| opts.width = Math.ceil(opts.width); | ||
| opts.height = Math.ceil(opts.height); | ||
| traces.each(function(d) { | ||
| var legendItem = d[0], | ||
| bg = d3.select(this).select('.legendtoggle'); | ||
| bg.call(Drawing.setRect, | ||
| 0, | ||
| -legendItem.height / 2, | ||
| (gd._context.editable ? 0 : opts.width) + 40, | ||
| legendItem.height | ||
| ); | ||
| }); | ||
| extraWidth = 40; | ||
| } | ||
| else if(isGrouped) { | ||
| opts.width = 0; | ||
| opts.height = 0; | ||
| var groupXOffsets = [opts.width], | ||
| groupData = groups.data(); | ||
| @@ -692,26 +677,8 @@ function computeLegendDimensions(gd, groups, traces) { | ||
| opts.height += 10 + borderwidth * 2; | ||
| opts.width += borderwidth * 2; | ||
| // make sure we're only getting full pixels | ||
| opts.width = Math.ceil(opts.width); | ||
| opts.height = Math.ceil(opts.height); | ||
| traces.each(function(d) { | ||
| var legendItem = d[0], | ||
| bg = d3.select(this).select('.legendtoggle'); | ||
| bg.call(Drawing.setRect, | ||
| 0, | ||
| -legendItem.height / 2, | ||
| (gd._context.editable ? 0 : opts.width), | ||
| legendItem.height | ||
| ); | ||
| }); | ||
| } | ||
| else { | ||
| opts.width = 0; | ||
| opts.height = 0; | ||
| var rowHeight = 0, | ||
| maxTraceHeight = 0, | ||
| maxTraceWidth = 0, | ||
| @@ -750,22 +717,23 @@ function computeLegendDimensions(gd, groups, traces) { | ||
| opts.width += borderwidth * 2; | ||
| opts.height += 10 + borderwidth * 2; | ||
| // make sure we're only getting full pixels | ||
| opts.width = Math.ceil(opts.width); | ||
| opts.height = Math.ceil(opts.height); | ||
| } | ||
| traces.each(function(d) { | ||
| var legendItem = d[0], | ||
| bg = d3.select(this).select('.legendtoggle'); | ||
| // make sure we're only getting full pixels | ||
| opts.width = Math.ceil(opts.width); | ||
| opts.height = Math.ceil(opts.height); | ||
| bg.call(Drawing.setRect, | ||
| 0, | ||
| -legendItem.height / 2, | ||
| (gd._context.editable ? 0 : opts.width), | ||
| legendItem.height | ||
| ); | ||
| }); | ||
| } | ||
| traces.each(function(d) { | ||
| var legendItem = d[0], | ||
| bg = d3.select(this).select('.legendtoggle'); | ||
| bg.call(Drawing.setRect, | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lovely commit 🎉 | ||
| 0, | ||
| -legendItem.height / 2, | ||
| (gd._context.edits.legendText ? 0 : opts.width) + extraWidth, | ||
| legendItem.height | ||
| ); | ||
| }); | ||
| } | ||
| function expandMargin(gd) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -397,28 +397,57 @@ 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); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. Maybe | ||
| var context = gd._context; | ||
| var i, keys, key; | ||
| if(config) { | ||
| Object.keys(config).forEach(function(key) { | ||
| keys = Object.keys(config); | ||
| for(i = 0; i < keys.length; i++) { | ||
| key = keys[i]; | ||
| if(key === 'editable' || key === 'edits') continue; | ||
| if(key in context) { | ||
| if(key === 'setBackground' && config[key] === 'opaque') { | ||
| context[key] = opaqueSetBackground; | ||
| } | ||
| else context[key] = config[key]; | ||
| } | ||
| }); | ||
| } | ||
| // map plot3dPixelRatio to plotGlPixelRatio for backward compatibility | ||
| if(config.plot3dPixelRatio && !context.plotGlPixelRatio) { | ||
| context.plotGlPixelRatio = context.plot3dPixelRatio; | ||
| } | ||
| // now deal with editable and edits - first editable overrides | ||
| // everything, then edits refines | ||
| var editable = config.editable; | ||
| if(editable !== undefined) { | ||
| // we're not going to *use* context.editable, we're only going to | ||
| // use context.edits... but keep it for the record | ||
| context.editable = editable; | ||
| keys = Object.keys(context.edits); | ||
| for(i = 0; i < keys.length; i++) { | ||
| context.edits[keys[i]] = editable; | ||
| } | ||
| } | ||
| if(config.edits) { | ||
| keys = Object.keys(config.edits); | ||
| for(i = 0; i < keys.length; i++) { | ||
| key = keys[i]; | ||
| if(key in context.edits) { | ||
| context.edits[key] = config.edits[key]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| // staticPlot forces a bunch of others: | ||
| if(context.staticPlot) { | ||
| context.editable = false; | ||
| context.edits = {}; | ||
| context.autosizable = false; | ||
| context.scrollZoom = false; | ||
| context.doubleClick = false; | ||
| @@ -487,7 +516,7 @@ function plotPolar(gd, data, layout) { | ||
| var title = polarPlotSVG.select('.title-group text') | ||
| .call(titleLayout); | ||
| if(gd._context.editable) { | ||
| if(gd._context.edits.titleText) { | ||
| if(!txt || txt === placeholderText) { | ||
| opacity = 0.2; | ||
| // placeholder is not going through convertToTspans | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
No need to address this now, but this seems like the right place to reference #1750