1
1
'use strict' ;
2
- /* jshint camelcase: false */
3
2
4
3
// ---external global dependencies
5
4
/* global Promise:false */
6
5
7
-
8
6
var Plotly = require ( './plotly' ) ,
9
7
d3 = require ( 'd3' ) ,
10
8
m4FromQuat = require ( 'gl-mat4/fromQuat' ) ,
@@ -241,63 +239,13 @@ plots.redrawText = function(gd) {
241
239
} ) ;
242
240
} ;
243
241
244
- // where and how the background gets set can be overridden by context
245
- // so we define the default (plotlyjs) behavior here
246
- function defaultSetBackground ( gd , bgColor ) {
247
- try {
248
- gd . _fullLayout . _paper . style ( 'background' , bgColor ) ;
249
- }
250
- catch ( e ) { console . log ( e ) ; }
251
- }
252
-
253
242
function opaqueSetBackground ( gd , bgColor ) {
254
243
gd . _fullLayout . _paperdiv . style ( 'background' , 'white' ) ;
255
- defaultSetBackground ( gd , bgColor ) ;
244
+ Plotly . defaultConfig . setBackground ( gd , bgColor ) ;
256
245
}
257
246
258
- // this will be transfered over to gd and overridden by
259
- // config args to Plotly.plot
260
- // the defaults are the appropriate settings for plotly.js,
261
- // so we get the right experience without any config argument
262
- plots . defaultConfig = {
263
- // no interactivity, for export or image generation
264
- staticPlot : false ,
265
- // we're in the workspace, so need toolbar etc
266
- // TODO describe functionality instead?
267
- workspace : false ,
268
- // we can edit titles, move annotations, etc
269
- editable : false ,
270
- // plot will respect layout.autosize=true and infer its container size
271
- autosizable : false ,
272
- // if we DO autosize, do we fill the container or the screen?
273
- fillFrame : false ,
274
- // if we DO autosize, set the frame margins in percents of plot size
275
- frameMargins : 0 ,
276
- // mousewheel or two-finger scroll zooms the plot
277
- scrollZoom : false ,
278
- // double click interaction (false, 'reset', 'autosize' or 'reset+autosize')
279
- doubleClick : 'reset+autosize' ,
280
- // new users see some hints about interactivity
281
- showTips : true ,
282
- // link to open this plot in plotly
283
- showLink : true ,
284
- // if we show a link, does it contain data or just link to a plotly file?
285
- sendData : true ,
286
- // text appearing in the sendData link
287
- linkText : 'Edit chart' ,
288
- // display the modebar (true, false, or 'hover')
289
- displayModeBar : 'hover' ,
290
- // add the plotly logo on the end of the modebar
291
- displaylogo : true ,
292
- // increase the pixel ratio for Gl plot images
293
- plotGlPixelRatio : 2 ,
294
- // fn to add the background color to a different container
295
- // or 'opaque' to ensure there's white behind it
296
- setBackground : defaultSetBackground
297
- } ;
298
-
299
247
function setPlotContext ( gd , config ) {
300
- if ( ! gd . _context ) gd . _context = Plotly . Lib . extendFlat ( { } , plots . defaultConfig ) ;
248
+ if ( ! gd . _context ) gd . _context = Plotly . Lib . extendFlat ( { } , Plotly . defaultConfig ) ;
301
249
var context = gd . _context ;
302
250
303
251
if ( config ) {
@@ -323,7 +271,6 @@ function setPlotContext(gd, config) {
323
271
324
272
//staticPlot forces a bunch of others:
325
273
if ( context . staticPlot ) {
326
- context . workspace = false ;
327
274
context . editable = false ;
328
275
context . autosizable = false ;
329
276
context . scrollZoom = false ;
@@ -334,14 +281,20 @@ function setPlotContext(gd, config) {
334
281
}
335
282
}
336
283
337
- // the 'view in plotly' and source links - note that now plot() calls this
338
- // so it can regenerate whenever it replots
284
+ /**
285
+ * Adds the 'Edit chart' link.
286
+ * Note that now Plotly.plot() calls this so it can regenerate whenever it replots
287
+ *
288
+ * Add source links to your graph inside the 'showSources' config argument.
289
+ */
339
290
plots . addLinks = function ( gd ) {
340
291
var fullLayout = gd . _fullLayout ;
341
- var linkContainer = fullLayout . _paper . selectAll ( 'text.js-plot-link-container' ) . data ( [ 0 ] ) ;
292
+
293
+ var linkContainer = fullLayout . _paper
294
+ . selectAll ( 'text.js-plot-link-container' ) . data ( [ 0 ] ) ;
342
295
343
296
linkContainer . enter ( ) . append ( 'text' )
344
- . classed ( 'js-plot-link-container' , true )
297
+ . classed ( 'js-plot-link-container' , true )
345
298
. style ( {
346
299
'font-family' :'"Open Sans",Arial,sans-serif' ,
347
300
'font-size' :'12px' ,
@@ -350,9 +303,9 @@ plots.addLinks = function(gd) {
350
303
} )
351
304
. each ( function ( ) {
352
305
var links = d3 . select ( this ) ;
353
- links . append ( 'tspan' ) . classed ( 'js-link-to-tool' , true ) ;
354
- links . append ( 'tspan' ) . classed ( 'js-link-spacer' , true ) ;
355
- links . append ( 'tspan' ) . classed ( 'js-sourcelinks' , true ) ;
306
+ links . append ( 'tspan' ) . classed ( 'js-link-to-tool' , true ) ;
307
+ links . append ( 'tspan' ) . classed ( 'js-link-spacer' , true ) ;
308
+ links . append ( 'tspan' ) . classed ( 'js-sourcelinks' , true ) ;
356
309
} ) ;
357
310
358
311
// The text node inside svg
@@ -371,24 +324,23 @@ plots.addLinks = function(gd) {
371
324
// Align the text at the left
372
325
attrs [ 'text-anchor' ] = 'start' ;
373
326
attrs . x = 5 ;
374
- } else {
327
+ }
328
+ else {
375
329
// Align the text at the right
376
330
attrs [ 'text-anchor' ] = 'end' ;
377
331
attrs . x = fullLayout . _paper . attr ( 'width' ) - 7 ;
378
332
}
379
333
380
334
linkContainer . attr ( attrs ) ;
381
335
382
-
383
336
var toolspan = linkContainer . select ( '.js-link-to-tool' ) ,
384
337
spacespan = linkContainer . select ( '.js-link-spacer' ) ,
385
338
sourcespan = linkContainer . select ( '.js-sourcelinks' ) ;
386
339
387
- // data source links
388
- Plotly . Lib . showSources ( gd ) ;
340
+ if ( gd . _context . showSources ) gd . _context . showSources ( gd ) ;
389
341
390
342
// 'view in plotly' link for embedded plots
391
- if ( gd . _context . showLink ) positionPlayWithData ( gd , toolspan ) ;
343
+ if ( gd . _context . showLink ) positionPlayWithData ( gd , toolspan ) ;
392
344
393
345
// separator if we have both sources and tool link
394
346
spacespan . text ( ( toolspan . text ( ) && sourcespan . text ( ) ) ? ' - ' : '' ) ;
0 commit comments