Skip to content

Commit 3a26e73

Browse files
committed
add showSources Plotly.plot config arg:
- defaults to false (no source link in default plotlyjs - attach showSources addon to gd._context.showSources - use that in Plots.addLinks
1 parent a109fd0 commit 3a26e73

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

shelly/plotlyjs/static/plotlyjs/src/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ module.exports = {
4747
// text appearing in the sendData link
4848
linkText: 'Edit chart',
4949

50+
// false or function adding source to linkText <text>
51+
showSource: false,
52+
5053
// display the modebar (true, false, or 'hover')
5154
displayModeBar: 'hover',
5255

shelly/plotlyjs/static/plotlyjs/src/graph_obj.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// ---external global dependencies
44
/* global Promise:false */
55

6-
76
var Plotly = require('./plotly'),
87
d3 = require('d3'),
98
m4FromQuat = require('gl-mat4/fromQuat'),
@@ -242,7 +241,7 @@ plots.redrawText = function(gd) {
242241

243242
function opaqueSetBackground(gd, bgColor) {
244243
gd._fullLayout._paperdiv.style('background', 'white');
245-
defaultSetBackground(gd, bgColor);
244+
Plotly.defaultConfig.setBackground(gd, bgColor);
246245
}
247246

248247
function setPlotContext(gd, config) {
@@ -283,14 +282,20 @@ function setPlotContext(gd, config) {
283282
}
284283
}
285284

286-
// the 'view in plotly' and source links - note that now plot() calls this
287-
// so it can regenerate whenever it replots
285+
/**
286+
* Adds the 'Edit chart' link.
287+
* Note that now Plotly.plot() calls this so it can regenerate whenever it replots
288+
*
289+
* Add source links to your graph inside the 'showSources' config argument.
290+
*/
288291
plots.addLinks = function(gd) {
289292
var fullLayout = gd._fullLayout;
290-
var linkContainer = fullLayout._paper.selectAll('text.js-plot-link-container').data([0]);
293+
294+
var linkContainer = fullLayout._paper
295+
.selectAll('text.js-plot-link-container').data([0]);
291296

292297
linkContainer.enter().append('text')
293-
.classed('js-plot-link-container',true)
298+
.classed('js-plot-link-container', true)
294299
.style({
295300
'font-family':'"Open Sans",Arial,sans-serif',
296301
'font-size':'12px',
@@ -299,9 +304,9 @@ plots.addLinks = function(gd) {
299304
})
300305
.each(function(){
301306
var links = d3.select(this);
302-
links.append('tspan').classed('js-link-to-tool',true);
303-
links.append('tspan').classed('js-link-spacer',true);
304-
links.append('tspan').classed('js-sourcelinks',true);
307+
links.append('tspan').classed('js-link-to-tool', true);
308+
links.append('tspan').classed('js-link-spacer', true);
309+
links.append('tspan').classed('js-sourcelinks', true);
305310
});
306311

307312
// The text node inside svg
@@ -320,24 +325,23 @@ plots.addLinks = function(gd) {
320325
// Align the text at the left
321326
attrs['text-anchor'] = 'start';
322327
attrs.x = 5;
323-
} else {
328+
}
329+
else {
324330
// Align the text at the right
325331
attrs['text-anchor'] = 'end';
326332
attrs.x = fullLayout._paper.attr('width') - 7;
327333
}
328334

329335
linkContainer.attr(attrs);
330336

331-
332337
var toolspan = linkContainer.select('.js-link-to-tool'),
333338
spacespan = linkContainer.select('.js-link-spacer'),
334339
sourcespan = linkContainer.select('.js-sourcelinks');
335340

336-
// data source links
337-
Plotly.Lib.showSources(gd);
341+
if(gd._context.showSources) gd._context.showSources();
338342

339343
// 'view in plotly' link for embedded plots
340-
if(gd._context.showLink) positionPlayWithData(gd,toolspan);
344+
if(gd._context.showLink) positionPlayWithData(gd, toolspan);
341345

342346
// separator if we have both sources and tool link
343347
spacespan.text((toolspan.text() && sourcespan.text()) ? ' - ' : '');

shelly/plotlyjs/static/plotlyjs/src/plotly.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ exports.Scene2D = require('./gl2d/scene2d');
6161
// plot schema
6262
exports.PlotSchema = require('./plotschema');
6363

64-
6564
// imaging Routines
6665
exports.Snapshot = require('./snapshot/snapshot');
6766

@@ -71,6 +70,12 @@ exports.Queue = require('./queue');
7170
// exports d3 used in the bundle
7271
exports.d3 = require('d3');
7372

73+
// --- above will be in the plotly.js repo,
74+
// below will be in the streambed plotlyjs only
75+
76+
// override defaultConfig
77+
exports.defaultConfig.showSource = require('./addons/show_sources');
78+
7479
// custom styling injected via envify/uglifyify
7580
if(process.env.PLOTLY_CUSTOM_STYLE === "open-office-2015") {
7681
require('./styles/open_office_2015')();

0 commit comments

Comments
 (0)