Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/components/annotations/click.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,8 +9,6 @@

'use strict';

var Plotly = require('../../plotly');


module.exports = {
hasClickToShow: hasClickToShow,
Expand DownExpand Up@@ -59,7 +57,7 @@ function onClick(gd, hoverData) {
update['annotations[' + offSet[i] + '].visible'] = false;
}

return Plotly.update(gd, {}, update);
return gd._plotAPI.update({}, update);
}

/*
Expand Down
7 changes: 3 additions & 4 deletions src/components/annotations/draw.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@

var d3 = require('d3');

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
Expand DownExpand Up@@ -594,7 +593,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
},
doneFn: function(dragged) {
if(dragged) {
Plotly.relayout(gd, update);
gd._plotAPI.relayout(update);
var notesBox = document.querySelector('.js-notes-box-panel');
if(notesBox) notesBox.redraw(notesBox.selectedObj);
}
Expand DownExpand Up@@ -675,7 +674,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
doneFn: function(dragged) {
setCursor(annTextGroupInner);
if(dragged) {
Plotly.relayout(gd, update);
gd._plotAPI.relayout(update);
var notesBox = document.querySelector('.js-notes-box-panel');
if(notesBox) notesBox.redraw(notesBox.selectedObj);
}
Expand All@@ -701,7 +700,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
update[ya._name + '.autorange'] = true;
}

Plotly.relayout(gd, update);
gd._plotAPI.relayout(update);
});
}
else annText.call(textLayout);
Expand Down
3 changes: 1 addition & 2 deletions src/components/colorbar/draw.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,6 @@
var d3 = require('d3');
var tinycolor = require('tinycolor2');

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Registry = require('../../registry');
var Axes = require('../../plots/cartesian/axes');
Expand DownExpand Up@@ -584,7 +583,7 @@ module.exports = function draw(gd, id) {
setCursor(container);

if(dragged && xf !== undefined && yf !== undefined) {
Plotly.restyle(gd,
gd._plotAPI.restyle(
{'colorbar.x': xf, 'colorbar.y': yf},
getTrace().index);
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/dragelement/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,7 +12,6 @@
var mouseOffset = require('mouse-event-offset');
var hasHover = require('has-hover');

var Plotly = require('../../plotly');
var Lib = require('../../lib');

var constants = require('../../plots/cartesian/constants');
Expand DownExpand Up@@ -216,7 +215,7 @@ dragElement.coverSlip = coverSlip;

function finishDrag(gd) {
gd._dragging = false;
if(gd._replotPending) Plotly.plot(gd);
if(gd._replotPending) gd._plotAPI.plot();
}

function pointerOffset(e) {
Expand Down
5 changes: 2 additions & 3 deletions src/components/legend/draw.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@

var d3 = require('d3');

var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Plots = require('../../plots/plots');
var Registry = require('../../registry');
Expand DownExpand Up@@ -336,7 +335,7 @@ module.exports = function draw(gd) {
},
doneFn: function(dragged, numClicks, e) {
if(dragged && xf !== undefined && yf !== undefined) {
Plotly.relayout(gd, {'legend.x': xf, 'legend.y': yf});
gd._plotAPI.relayout({'legend.x': xf, 'legend.y': yf});
} else {
var clickedTrace =
fullLayout._infolayer.selectAll('g.traces').filter(function() {
Expand DownExpand Up@@ -425,7 +424,7 @@ function drawTexts(g, gd) {
update.name = text;
}

return Plotly.restyle(gd, update, traceIndex);
return gd._plotAPI.restyle(update, traceIndex);
});
} else {
text.call(textLayout);
Expand Down
5 changes: 2 additions & 3 deletions src/components/legend/handle_click.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,6 @@

'use strict';

var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Registry = require('../../registry');

Expand DownExpand Up@@ -112,7 +111,7 @@ module.exports = function handleClick(g, gd, numClicks) {
}
}

Plotly.relayout(gd, 'hiddenlabels', hiddenSlices);
gd._plotAPI.relayout('hiddenlabels', hiddenSlices);
} else {
var hasLegendgroup = legendgroup && legendgroup.length;
var traceIndicesInGroup = [];
Expand DownExpand Up@@ -218,6 +217,6 @@ module.exports = function handleClick(g, gd, numClicks) {
}
}

Plotly.restyle(gd, attrUpdate, attrIndices);
gd._plotAPI.restyle(attrUpdate, attrIndices);
}
};
15 changes: 7 additions & 8 deletions src/components/modebar/buttons.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,6 @@

'use strict';

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Axes = require('../../plots/cartesian/axes');
var Lib = require('../../lib');
Expand DownExpand Up@@ -251,7 +250,7 @@ function handleCartesian(gd, ev) {
aobj[astr] = val;
}

Plotly.relayout(gd, aobj);
gd._plotAPI.relayout(aobj);
}

modeBarButtons.zoom3d = {
Expand DownExpand Up@@ -304,7 +303,7 @@ function handleDrag3d(gd, ev) {
layoutUpdate[sceneIds[i] + '.' + parts[1]] = val;
}

Plotly.relayout(gd, layoutUpdate);
gd._plotAPI.relayout(layoutUpdate);
}

modeBarButtons.resetCameraDefault3d = {
Expand DownExpand Up@@ -343,7 +342,7 @@ function handleCamera3d(gd, ev) {
}
}

Plotly.relayout(gd, aobj);
gd._plotAPI.relayout(aobj);
}

modeBarButtons.hoverClosest3d = {
Expand DownExpand Up@@ -404,7 +403,7 @@ function handleHover3d(gd, ev) {
button._previousVal = Lib.extendDeep({}, currentSpikes);
}

Plotly.relayout(gd, layoutUpdate);
gd._plotAPI.relayout(layoutUpdate);
}

modeBarButtons.zoomInGeo = {
Expand DownExpand Up@@ -498,7 +497,7 @@ function toggleHover(gd) {

var newHover = gd._fullLayout.hovermode ? false : onHoverVal;

Plotly.relayout(gd, 'hovermode', newHover);
gd._plotAPI.relayout('hovermode', newHover);
}

// buttons when more then one plot types are present
Expand DownExpand Up@@ -555,7 +554,7 @@ modeBarButtons.toggleSpikelines = {
var aobj = setSpikelineVisibility(gd);

aobj.hovermode = 'closest';
Plotly.relayout(gd, aobj);
gd._plotAPI.relayout(aobj);
}
};

Expand DownExpand Up@@ -597,6 +596,6 @@ modeBarButtons.resetViewMapbox = {
}
}

Plotly.relayout(gd, aObj);
gd._plotAPI.relayout(aObj);
}
};
3 changes: 1 addition & 2 deletions src/components/rangeselector/draw.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@

var d3 = require('d3');

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var Color = require('../color');
var Drawing = require('../drawing');
Expand DownExpand Up@@ -66,7 +65,7 @@ module.exports = function draw(gd) {
button.on('click', function() {
if(gd._dragged) return;

Plotly.relayout(gd, update);
gd._plotAPI.relayout(update);
});

button.on('mouseover', function() {
Expand Down
3 changes: 1 addition & 2 deletions src/components/rangeslider/draw.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,6 @@

var d3 = require('d3');

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');

var Lib = require('../../lib');
Expand DownExpand Up@@ -247,7 +246,7 @@ function setDataRange(rangeSlider, gd, axisOpts, opts) {
dataMax = clamp(opts.p2d(opts._pixelMax));

window.requestAnimationFrame(function() {
Plotly.relayout(gd, axisOpts._name + '.range', [dataMin, dataMax]);
gd._plotAPI.relayout(axisOpts._name + '.range', [dataMin, dataMax]);
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/shapes/draw.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,7 +9,6 @@

'use strict';

var Plotly = require('../../plotly');
var Lib = require('../../lib');
var Axes = require('../../plots/cartesian/axes');
var Color = require('../color');
Expand DownExpand Up@@ -214,7 +213,7 @@ function setupDragElement(gd, shapePath, shapeOptions, index) {
function endDrag(dragged) {
setCursor(shapePath);
if(dragged) {
Plotly.relayout(gd, update);
gd._plotAPI.relayout(update);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/titles/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,8 @@
var d3 = require('d3');
var isNumeric = require('fast-isnumeric');

var Plotly = require('../../plotly');
var Plots = require('../../plots/plots');
var previousPromises = require('../../plots/previous_promises');
var fontWeight = require('../../plots/font_weight');
var Lib = require('../../lib');
var Drawing = require('../drawing');
var Color = require('../color');
Expand DownExpand Up@@ -124,12 +124,12 @@ Titles.draw = function(gd, titleClass, options) {
'font-size': d3.round(fontSize, 2) + 'px',
fill: Color.rgb(fontColor),
opacity: opacity * Color.opacity(fontColor),
'font-weight': Plots.fontWeight
'font-weight': fontWeight
})
.attr(attributes)
.call(svgTextUtils.convertToTspans, gd);

return Plots.previousPromises(gd);
return previousPromises(gd);
}

function scootTitle(titleElIn) {
Expand DownExpand Up@@ -222,8 +222,8 @@ Titles.draw = function(gd, titleClass, options) {

el.call(svgTextUtils.makeEditable, {gd: gd})
.on('edit', function(text) {
if(traceIndex !== undefined) Plotly.restyle(gd, prop, text, traceIndex);
else Plotly.relayout(gd, prop, text);
if(traceIndex !== undefined) gd._plotAPI.restyle(prop, text, traceIndex);
else gd._plotAPI.relayout(prop, text);
})
.on('cancel', function() {
this.text(this.attr('data-unformatted'))
Expand Down
44 changes: 44 additions & 0 deletions src/plot_api/bind_plot_api.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';


module.exports = function bindPlotAPI(gd, Plotly) {
var i;

if(gd._plotAPI) return;

gd._plotAPI = {};
var methods = [
'plot', 'newPlot', 'restyle', 'relayout', 'redraw',
'update', 'extendTraces', 'prependTraces', 'addTraces',
'deleteTraces', 'moveTraces', 'purge', 'addFrames',
'deleteFrames', 'animate'
];

function bindMethod(method) {
return function() {
var i;
var args = [gd];
for(i = 0; i < arguments.length; i++) {
args[i + 1] = arguments[i];
}
return method.apply(null, args);
};
}

for(i = 0; i < methods.length; i++) {
gd._plotAPI[methods[i]] = bindMethod(Plotly[methods[i]]);
}

// This is needed for snapshot/toimage, which needs to plot to a *different* gd.
// In other words, it's just regular Plotly plot:
gd._plotAPI.plotWithGd = Plotly.plot;
};
Loading