Skip to content

Commit 06640b4

Browse files
committed
Update plotting calls to work agnostically using registered modules
1 parent 71db785 commit 06640b4

File tree

5 files changed

+39
-58
lines changed

5 files changed

+39
-58
lines changed

src/plots/geo/geo.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
var Plotly = require('../../plotly');
1515
var d3 = require('d3');
1616

17+
var Plots = require('../../plots/plots');
18+
1719
var addProjectionsToD3 = require('./projections');
1820
var createGeoScale = require('./set_scale');
1921
var createGeoZoom = require('./zoom');
2022
var createGeoZoomReset = require('./zoom_reset');
2123

22-
var plotScatterGeo = require('../../traces/scattergeo/plot');
23-
var plotChoropleth = require('../../traces/choropleth/plot');
24-
2524
var constants = require('../../constants/geo_constants');
2625
var topojsonUtils = require('../../lib/topojson_utils');
2726
var topojsonFeature = require('topojson').feature;
@@ -136,21 +135,20 @@ proto.plot = function(geoData, fullLayout, promises) {
136135
};
137136

138137
proto.onceTopojsonIsLoaded = function(geoData, geoLayout) {
139-
var scattergeoData = [],
140-
choroplethData = [];
138+
var traceData = {};
141139

142140
this.drawLayout(geoLayout);
143141

144142
for(var i = 0; i < geoData.length; i++) {
145143
var trace = geoData[i];
146-
var traceType = trace.type;
147144

148-
if(traceType === 'scattergeo') scattergeoData.push(trace);
149-
else if(traceType === 'choropleth') choroplethData.push(trace);
145+
traceData[trace.type] = traceData[trace.type] || [];
146+
traceData[trace.type].push(trace);
150147
}
151148

152-
if(scattergeoData.length>0) plotScatterGeo.plot(this, scattergeoData);
153-
if(choroplethData.length>0) plotChoropleth.plot(this, choroplethData, geoLayout);
149+
for(var traceType in traceData){
150+
Plots.getModule(traceType).plot(this, traceData[traceType], geoLayout);
151+
}
154152

155153
this.render();
156154
};

src/plots/geo/zoom_reset.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
'use strict';
1111

12-
var loneUnhover = require('../../plotly').Fx.loneUnhover;
13-
12+
var Fx = require('../cartesian/graph_interact');
1413

1514
function createGeoZoomReset(geo, geoLayout) {
1615
var projection = geo.projection,
@@ -23,7 +22,7 @@ function createGeoZoomReset(geo, geoLayout) {
2322
zoom.scale(projection.scale());
2423
zoom.translate(projection.translate());
2524

26-
loneUnhover(geo.hoverContainer);
25+
Fx.loneUnhover(geo.hoverContainer);
2726

2827
geo.render();
2928
};

src/plots/gl2d/scene2d.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
12+
var Plots = require('../../plots/plots');
13+
var Axes = require('../../plots/cartesian/axes');
14+
var Fx = require('../../plots/cartesian/graph_interact');
15+
1316
var createPlot2D = require('gl-plot2d');
1417
var createSpikes = require('gl-spikes2d');
1518
var createSelectBox = require('gl-select-box');
1619

1720
var createOptions = require('./convert');
1821
var createCamera = require('./camera');
1922

20-
var createLineWithMarkers = require('../../traces/scattergl/convert');
21-
2223
var htmlToUnicode = require('../../lib/html2unicode');
2324
var showNoWebGlMsg = require('../../lib/show_no_webgl_msg');
2425

@@ -223,8 +224,8 @@ proto.computeTickMarks = function() {
223224
this.glplot.viewBox[3] - this.glplot.viewBox[1];
224225

225226
var nextTicks = [
226-
Plotly.Axes.calcTicks(this.xaxis),
227-
Plotly.Axes.calcTicks(this.yaxis)
227+
Axes.calcTicks(this.xaxis),
228+
Axes.calcTicks(this.yaxis)
228229
];
229230

230231
for(var j = 0; j < 2; ++j) {
@@ -254,7 +255,7 @@ function compareTicks(a, b) {
254255
}
255256

256257
proto.updateAxes = function(options) {
257-
var spmatch = Plotly.Axes.subplotMatch,
258+
var spmatch = Axes.subplotMatch,
258259
xaxisName = 'xaxis' + this.id.match(spmatch)[1],
259260
yaxisName = 'yaxis' + this.id.match(spmatch)[2];
260261

@@ -325,11 +326,8 @@ proto.plot = function(fullData, fullLayout) {
325326

326327
if(trace) trace.update(traceData);
327328
else {
328-
switch(traceData.type) {
329-
case 'scattergl':
330-
trace = createLineWithMarkers(this, traceData);
331-
break;
332-
}
329+
var traceModule = Plots.getModule(traceData.type);
330+
trace = traceModule.plot(this, traceData);
333331
}
334332
this.traces[traceData.uid] = trace;
335333
}
@@ -392,7 +390,7 @@ proto.plot = function(fullData, fullLayout) {
392390
ax = this[AXES[i]];
393391
ax._length = options.viewBox[i+2] - options.viewBox[i];
394392

395-
Plotly.Axes.doAutoRange(ax);
393+
Axes.doAutoRange(ax);
396394
}
397395

398396
options.ticks = this.computeTickMarks();
@@ -475,7 +473,7 @@ proto.draw = function() {
475473
if(parts.indexOf('name') === -1) selection.name = undefined;
476474
}
477475

478-
Plotly.Fx.loneHover({
476+
Fx.loneHover({
479477
x: selection.screenCoord[0],
480478
y: selection.screenCoord[1],
481479
xLabel: this.hoverFormatter('xaxis', selection.traceCoord[0]),
@@ -493,7 +491,7 @@ proto.draw = function() {
493491
else if(!result && this.lastPickResult) {
494492
this.spikes.update({});
495493
this.lastPickResult = null;
496-
Plotly.Fx.loneUnhover(this.svgContainer);
494+
Fx.loneUnhover(this.svgContainer);
497495
}
498496
}
499497

@@ -504,5 +502,5 @@ proto.hoverFormatter = function(axisName, val) {
504502
if(val === undefined) return undefined;
505503

506504
var axis = this[axisName];
507-
return Plotly.Axes.tickText(axis, axis.c2l(val), 'hover').text;
505+
return Axes.tickText(axis, axis.c2l(val), 'hover').text;
508506
};

src/plots/gl3d/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010
'use strict';
1111

12-
var Plotly = require('../../plotly');
13-
1412
var Scene = require('./scene');
13+
var Plots = require('../plots');
1514

16-
var plots = Plotly.Plots;
1715
var axesNames = ['xaxis', 'yaxis', 'zaxis'];
1816

1917

@@ -32,7 +30,7 @@ exports.supplyLayoutDefaults = require('./layout/defaults');
3230
exports.plot = function plotGl3d(gd) {
3331
var fullLayout = gd._fullLayout,
3432
fullData = gd._fullData,
35-
sceneIds = plots.getSubplotIds(fullLayout, 'gl3d');
33+
sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d');
3634

3735
fullLayout._paperdiv.style({
3836
width: fullLayout.width + 'px',
@@ -43,7 +41,7 @@ exports.plot = function plotGl3d(gd) {
4341

4442
for(var i = 0; i < sceneIds.length; i++) {
4543
var sceneId = sceneIds[i],
46-
fullSceneData = plots.getSubplotData(fullData, 'gl3d', sceneId),
44+
fullSceneData = Plots.getSubplotData(fullData, 'gl3d', sceneId),
4745
scene = fullLayout[sceneId]._scene; // ref. to corresp. Scene instance
4846

4947
// If Scene is not instantiated, create one!
@@ -83,7 +81,7 @@ exports.initAxes = function(gd) {
8381
delete fullLayout.xaxis;
8482
delete fullLayout.yaxis;
8583

86-
var sceneIds = Plotly.Plots.getSubplotIds(fullLayout, 'gl3d');
84+
var sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d');
8785

8886
for(var i = 0; i < sceneIds.length; ++i) {
8987
var sceneId = sceneIds[i];

src/plots/gl3d/scene.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
'use strict';
1414

15-
var Plotly = require('../../plotly');
1615
var createPlot = require('gl-plot3d');
1716

18-
var createScatterTrace = require('../../traces/scatter3d/convert');
19-
var createSurfaceTrace = require('../../traces/surface/convert');
20-
var createMeshTrace = require('../../traces/mesh3d/convert');
17+
var Lib = require('../../lib');
18+
19+
var Plots = require('../../plots/plots');
20+
var Axes = require('../../plots/cartesian/axes');
21+
var Fx = require('../../plots/cartesian/graph_interact');
22+
2123
var str2RGBAarray = require('../../lib/str2rgbarray');
2224
var showNoWebGlMsg = require('../../lib/show_no_webgl_msg');
2325

@@ -30,7 +32,6 @@ var computeTickMarks = require('./layout/tick_marks');
3032

3133
var STATIC_CANVAS, STATIC_CONTEXT;
3234

33-
3435
function render(scene) {
3536

3637
//Update size of svg container
@@ -62,7 +63,7 @@ function render(scene) {
6263
if(typeof val === 'string') return val;
6364

6465
var axis = scene.fullSceneLayout[axisName];
65-
return Plotly.Axes.tickText(axis, axis.c2l(val), 'hover').text;
66+
return Axes.tickText(axis, axis.c2l(val), 'hover').text;
6667
}
6768

6869
if(lastPicked !== null) {
@@ -78,7 +79,7 @@ function render(scene) {
7879
if(hoverinfoParts.indexOf('name') === -1) lastPicked.name = undefined;
7980
}
8081

81-
Plotly.Fx.loneHover({
82+
Fx.loneHover({
8283
x: (0.5 + 0.5 * pdata[0]/pdata[3]) * width,
8384
y: (0.5 - 0.5 * pdata[1]/pdata[3]) * height,
8485
xLabel: formatter('xaxis', selection.traceCoordinate[0]),
@@ -91,7 +92,7 @@ function render(scene) {
9192
container: svgContainer
9293
});
9394
}
94-
else Plotly.Fx.loneUnhover(svgContainer);
95+
else Fx.loneUnhover(svgContainer);
9596
}
9697

9798
function initializeGLPlot(scene, fullLayout, canvas, gl) {
@@ -351,21 +352,8 @@ proto.plot = function(sceneData, fullLayout, layout) {
351352
if(trace) {
352353
trace.update(data);
353354
} else {
354-
switch(data.type) {
355-
case 'scatter3d':
356-
trace = createScatterTrace(this, data);
357-
break;
358-
359-
case 'surface':
360-
trace = createSurfaceTrace(this, data);
361-
break;
362-
363-
case 'mesh3d':
364-
trace = createMeshTrace(this, data);
365-
break;
366-
367-
default:
368-
}
355+
var traceModule = Plots.getModule(data.type);
356+
trace = traceModule.plot(this, data);
369357
this.traces[data.uid] = trace;
370358
}
371359
trace.name = data.name;
@@ -569,7 +557,7 @@ proto.setCamera = function setCamera(cameraData) {
569557
// save camera to user layout (i.e. gd.layout)
570558
proto.saveCamera = function saveCamera(layout) {
571559
var cameraData = this.getCamera(),
572-
cameraNestedProp = Plotly.Lib.nestedProperty(layout, this.id + '.camera'),
560+
cameraNestedProp = Lib.nestedProperty(layout, this.id + '.camera'),
573561
cameraDataLastSave = cameraNestedProp.get(),
574562
hasChanged = false;
575563

0 commit comments

Comments
 (0)