From c8bc6e47f0e24d4440c5b57331a0b17579e45f00 Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:44:00 -0500 Subject: [PATCH 01/16] make Plots.registerSubplot take a module as argument --- src/plots/plots.js | 51 ++++++++++++++++++-------------- test/jasmine/tests/plots_test.js | 11 +++++-- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index f82051e2f93..fc12dfb1203 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -107,12 +107,14 @@ plots.traceIs = function traceIs(traceType, category) { /** * plots.registerSubplot: register a subplot type * - * @param {string} subplotType subplot type - * (these must also be categories defined with plots.register) - * @param {string or array of strings} attr attribute name in traces and layout - * @param {string or array of strings} idRoot root of id - * (setting the possible value for attrName) - * @param {object} attributes attribute(s) for traces of this subplot type + * @param {object} _module subplot module: + * + * @param {string or array of strings} attr + * attribute name in traces and layout + * @param {string or array of strings} idRoot + * root of id (setting the possible value for attrName) + * @param {object} attributes + * attribute(s) for traces of this subplot type * * In trace objects `attr` is the object key taking a valid `id` as value * (the set of all valid ids is generated below and stored in idRegex). @@ -123,33 +125,36 @@ plots.traceIs = function traceIs(traceType, category) { * * TODO use these in Lib.coerce */ -plots.registerSubplot = function(subplotType, attr, idRoot, attributes) { - if(subplotsRegistry[subplotType]) { - throw new Error('subplot ' + subplotType + ' already registered'); +plots.registerSubplot = function(_module) { + var plotType = _module.type; + + if(subplotsRegistry[plotType]) { + throw new Error('plot type' + plotType + ' already registered'); } + var attr = _module.attr, + idRoot = _module.idRoot; + var regexStart = '^', regexEnd = '([2-9]|[1-9][0-9]+)?$', - hasXY = (subplotType === 'cartesian' || subplotsRegistry === 'gl2d'); + hasXY = (plotType === 'cartesian' || subplotsRegistry === 'gl2d'); function makeRegex(mid) { return new RegExp(regexStart + mid + regexEnd); } // not sure what's best for the 'cartesian' type at this point - subplotsRegistry[subplotType] = { - attr: attr, - idRoot: idRoot, - attributes: attributes, - // register the regex representing the set of all valid attribute names - attrRegex: hasXY ? - { x: makeRegex(attr[0]), y: makeRegex(attr[1]) } : - makeRegex(attr), - // register the regex representing the set of all valid attribute ids - idRegex: hasXY ? - { x: makeRegex(idRoot[0]), y: makeRegex(idRoot[1]) } : - makeRegex(idRoot) - }; + subplotsRegistry[plotType] = _module; + + // register the regex representing the set of all valid attribute names + subplotsRegistry[plotType].attrRegex = hasXY ? + { x: makeRegex(attr[0]), y: makeRegex(attr[1]) } : + makeRegex(attr); + + // register the regex representing the set of all valid attribute ids + subplotsRegistry[plotType].idRegex = hasXY ? + { x: makeRegex(idRoot[0]), y: makeRegex(idRoot[1]) } : + makeRegex(idRoot); }; // TODO separate the 'find subplot' step (which looks in layout) diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index bf413008892..1a963e6fb0d 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -234,9 +234,14 @@ describe('Test Plotly.Plots', function () { }); describe('Plotly.Plots.registerSubplot', function() { - Plotly.Plots.registerSubplot('fake', 'abc', 'cba', { - stuff: { 'more stuff': 102102 } - }); + var fake = { + type: 'fake', + attr: 'abc', + idRoot: 'cba', + attributes: { stuff: { 'more stuff': 102102 } } + } + + Plotly.Plots.registerSubplot(fake); var subplotsRegistry = Plotly.Plots.subplotsRegistry; From 812691432404d93aafabf189df7c80d10a14696d Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:45:07 -0500 Subject: [PATCH 02/16] add cartesian plot index + register it in plotly.js --- src/plotly.js | 5 ++++- src/plots/cartesian/axes.js | 4 ---- src/plots/cartesian/index.js | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/plots/cartesian/index.js diff --git a/src/plotly.js b/src/plotly.js index 4b195b1a24f..9d2e0133f87 100644 --- a/src/plotly.js +++ b/src/plotly.js @@ -33,7 +33,10 @@ exports.MathJaxConfig = require('./fonts/mathjax_config'); exports.defaultConfig = require('./plot_api/plot_config'); // plots -exports.Plots = require('./plots/plots'); +var Plots = exports.Plots = require('./plots/plots'); + +var Cartesian = require('./plots/cartesian'); +Plots.registerSubplot(Cartesian); exports.Axes = require('./plots/cartesian/axes'); exports.Fx = require('./plots/cartesian/graph_interact'); exports.Scene = require('./plots/gl3d/scene'); diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 6e2f0877b5f..1b960ab4178 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -15,10 +15,6 @@ var isNumeric = require('fast-isnumeric'); var axes = module.exports = {}; -axes.attributes = require('./attributes'); - -Plotly.Plots.registerSubplot('cartesian', ['xaxis', 'yaxis'], ['x', 'y'], axes.attributes); - axes.layoutAttributes = require('./layout_attributes'); var xAxisMatch = /^xaxis[0-9]*$/, diff --git a/src/plots/cartesian/index.js b/src/plots/cartesian/index.js new file mode 100644 index 00000000000..b37c070ea51 --- /dev/null +++ b/src/plots/cartesian/index.js @@ -0,0 +1,21 @@ +/** +* Copyright 2012-2016, 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'; + +var Plotly = require('../../plotly'); + + +exports.type = 'cartesian'; + +exports.attr = ['xaxis', 'yaxis']; + +exports.idRoot = ['x', 'y']; + +exports.attributes = require('./attributes'); From d5e894d29d045b8a137099fa7fdea7e7daf00008 Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:47:10 -0500 Subject: [PATCH 03/16] add geo plot index + register it in plotly.js + rm GeoLayout module --- src/plotly.js | 5 ++- src/plots/geo/index.js | 62 ++++++++++++++++++++++++++++ src/plots/geo/layout/index.js | 18 -------- src/plots/layout_attributes.js | 2 +- test/jasmine/tests/geolayout_test.js | 33 ++++++++------- 5 files changed, 83 insertions(+), 37 deletions(-) create mode 100644 src/plots/geo/index.js delete mode 100644 src/plots/geo/layout/index.js diff --git a/src/plotly.js b/src/plotly.js index 9d2e0133f87..37ba6b746f1 100644 --- a/src/plotly.js +++ b/src/plotly.js @@ -39,10 +39,11 @@ var Cartesian = require('./plots/cartesian'); Plots.registerSubplot(Cartesian); exports.Axes = require('./plots/cartesian/axes'); exports.Fx = require('./plots/cartesian/graph_interact'); + +var Geo = require('./plots/geo'); +Plots.registerSubplot(Geo); exports.Scene = require('./plots/gl3d/scene'); exports.Gl3dLayout = require('./plots/gl3d/layout'); -exports.Geo = require('./plots/geo/geo'); -exports.GeoLayout = require('./plots/geo/layout'); exports.Scene2D = require('./plots/gl2d/scene2d'); exports.micropolar = require('./plots/polar/micropolar'); diff --git a/src/plots/geo/index.js b/src/plots/geo/index.js new file mode 100644 index 00000000000..345ada84c17 --- /dev/null +++ b/src/plots/geo/index.js @@ -0,0 +1,62 @@ +/** +* Copyright 2012-2016, 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'; + +var Plotly = require('../../plotly'); + +var Geo = require('./geo'); + +var Plots = Plotly.Plots; + + +exports.type = 'geo'; + +exports.attr = 'geo'; + +exports.idRoot = 'geo'; + +exports.attributes = require('./layout/attributes'); + +exports.layoutAttributes = require('./layout/layout_attributes'); + +exports.supplyLayoutDefaults = require('./layout/defaults'); + +exports.plot = function plotGeo(gd) { + var fullLayout = gd._fullLayout, + fullData = gd._fullData, + geoIds = Plots.getSubplotIds(fullLayout, 'geo'); + + /** + * If 'plotly-geo-assets.js' is not included, + * initialize object to keep reference to every loaded topojson + */ + if(window.PlotlyGeoAssets === undefined) { + window.PlotlyGeoAssets = { topojson : {} }; + } + + for(var i = 0; i < geoIds.length; i++) { + var geoId = geoIds[i], + fullGeoData = Plots.getSubplotData(fullData, 'geo', geoId), + geo = fullLayout[geoId]._geo; + + // If geo is not instantiated, create one! + if(geo === undefined) { + geo = new Geo({ + id: geoId, + container: fullLayout._geocontainer.node(), + topojsonURL: gd._context.topojsonURL + }, fullLayout); + + fullLayout[geoId]._geo = geo; + } + + geo.plot(fullGeoData, fullLayout, gd._promises); + } +}; diff --git a/src/plots/geo/layout/index.js b/src/plots/geo/layout/index.js deleted file mode 100644 index 88dcd9fef63..00000000000 --- a/src/plots/geo/layout/index.js +++ /dev/null @@ -1,18 +0,0 @@ -/** -* Copyright 2012-2016, 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'; - -var Plotly = require('../../../plotly'); -var attributes = require('./attributes'); - -Plotly.Plots.registerSubplot('geo', 'geo', 'geo', attributes); - -exports.layoutAttributes = require('./layout_attributes'); -exports.supplyLayoutDefaults = require('./defaults'); diff --git a/src/plots/layout_attributes.js b/src/plots/layout_attributes.js index b9d411c7659..5643f67ed69 100644 --- a/src/plots/layout_attributes.js +++ b/src/plots/layout_attributes.js @@ -196,7 +196,7 @@ module.exports = { 'xaxis': 'Axes', 'yaxis': 'Axes', 'scene': 'Gl3dLayout', - 'geo': 'GeoLayout', + 'geo': 'geo', 'legend': 'Legend', 'annotations': 'Annotations', 'shapes': 'Shapes' diff --git a/test/jasmine/tests/geolayout_test.js b/test/jasmine/tests/geolayout_test.js index 738019b0630..e4b96d7f7b8 100644 --- a/test/jasmine/tests/geolayout_test.js +++ b/test/jasmine/tests/geolayout_test.js @@ -1,9 +1,10 @@ -var Plotly = require('@src/plotly'); +var Geo = require('@src/plots/geo'); -describe('Test geolayout', function () { +describe('Test Geo layout defaults', function () { 'use strict'; - var GeoLayout = Plotly.GeoLayout; + var layoutAttributes = Geo.layoutAttributes; + var supplyLayoutDefaults = Geo.supplyLayoutDefaults; describe('supplyLayoutDefaults', function() { var layoutIn, layoutOut; @@ -30,12 +31,12 @@ describe('Test geolayout', function () { } }; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); expect(layoutOut.geo.projection.rotation).toBeUndefined(); delete layoutIn.geo.projection.type; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); expect(layoutOut.geo.projection.rotation).toBeDefined(); }); @@ -55,21 +56,21 @@ describe('Test geolayout', function () { } }; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); fields.forEach(function(field) { expect(layoutOut.geo[field]).toBeUndefined(); }); delete layoutIn.geo.projection.type; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); fields.forEach(function(field) { expect(layoutOut.geo[field]).toBeDefined(); }); }); it('should not coerce projection.parallels if type is conic', function() { - var projTypes = GeoLayout.layoutAttributes.projection.type.values; + var projTypes = layoutAttributes.projection.type.values; function testOne(projType) { layoutIn = { @@ -81,7 +82,7 @@ describe('Test geolayout', function () { } }; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); } projTypes.forEach(function(projType) { @@ -103,14 +104,14 @@ describe('Test geolayout', function () { geo: { scope: 'usa' } }; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); fields.forEach(function(field) { expect(layoutOut.geo[field]).toBeDefined(); }); delete layoutIn.geo.scope; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); fields.forEach(function(field) { expect(layoutOut.geo[field]).toBeUndefined(); }); @@ -122,7 +123,7 @@ describe('Test geolayout', function () { } }; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); fields.forEach(function(field) { expect(layoutOut.geo[field]).toBeDefined(); }); @@ -134,14 +135,14 @@ describe('Test geolayout', function () { } }; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); fields.forEach(function(field) { expect(layoutOut.geo[field]).toBeDefined(); }); delete layoutIn.geo.resolution; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); fields.forEach(function(field) { expect(layoutOut.geo[field]).toBeUndefined(); }); @@ -151,14 +152,14 @@ describe('Test geolayout', function () { var fields = [ 'showframe', 'framecolor', 'framewidth' ], - scopes = GeoLayout.layoutAttributes.scope.values; + scopes = layoutAttributes.scope.values; function testOne(scope) { layoutIn = { geo: { scope: scope } }; layoutOut = {}; - GeoLayout.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + supplyLayoutDefaults(layoutIn, layoutOut, fullData); } scopes.forEach(function(scope) { From 3c383d78180a40f43ca7fc91516ea4f31c0391e8 Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:48:18 -0500 Subject: [PATCH 04/16] add gl3d plot index + register it in plotly.js + remove Gl3dLayout --- src/plot_api/plot_api.js | 49 +++----------- src/plots/gl3d/index.js | 97 +++++++++++++++++++++++++++ src/plots/gl3d/layout/index.js | 57 ---------------- src/plots/gl3d/scene.js | 17 +++-- src/plots/gl3d/set_convert.js | 20 ++++++ src/plots/layout_attributes.js | 2 +- test/jasmine/tests/gl3dlayout_test.js | 7 +- 7 files changed, 138 insertions(+), 111 deletions(-) create mode 100644 src/plots/gl3d/index.js delete mode 100644 src/plots/gl3d/layout/index.js create mode 100644 src/plots/gl3d/set_convert.js diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 2c3476a5579..cc2bb075197 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -418,41 +418,6 @@ function setPlotContext(gd, config) { } } -function plotGl3d(gd) { - var fullLayout = gd._fullLayout, - fullData = gd._fullData, - sceneIds = plots.getSubplotIds(fullLayout, 'gl3d'); - - var i, sceneId, fullSceneData, scene, sceneOptions; - - fullLayout._paperdiv.style({ - width: fullLayout.width + 'px', - height: fullLayout.height + 'px' - }); - - gd._context.setBackground(gd, fullLayout.paper_bgcolor); - - for (i = 0; i < sceneIds.length; i++) { - sceneId = sceneIds[i]; - fullSceneData = plots.getSubplotData(fullData, 'gl3d', sceneId); - scene = fullLayout[sceneId]._scene; // ref. to corresp. Scene instance - - // If Scene is not instantiated, create one! - if(scene === undefined) { - sceneOptions = { - container: gd.querySelector('.gl-container'), - id: sceneId, - staticPlot: gd._context.staticPlot, - plotGlPixelRatio: gd._context.plotGlPixelRatio - }; - scene = new Plotly.Scene(sceneOptions, fullLayout); - fullLayout[sceneId]._scene = scene; // set ref to Scene instance - } - - scene.plot(fullSceneData, fullLayout, gd.layout); // takes care of business - } -} - function plotGeo(gd) { var fullLayout = gd._fullLayout, fullData = gd._fullData, @@ -866,8 +831,9 @@ function cleanData(data, existingData) { if(trace.yaxis) trace.yaxis = Plotly.Axes.cleanId(trace.yaxis, 'y'); // scene ids scene1 -> scene - if (trace.scene) { - trace.scene = Plotly.Gl3dLayout.cleanId(trace.scene); + var plotRegistry = plots.subplotsRegistry; + if(trace.scene && plotRegistry.gl3d) { + trace.scene = plotRegistry.gl3d.cleanId(trace.scene); } if(!plots.traceIs(trace, 'pie')) { @@ -2593,10 +2559,11 @@ function makePlotFramework(gd) { var gd3 = d3.select(gd), fullLayout = gd._fullLayout; - /* - * TODO - find a better place for 3D to initialize axes - */ - if(fullLayout._hasGL3D) Plotly.Gl3dLayout.initAxes(gd); + // TODO - find a better place for 3D to initialize axes + var plotRegistry = plots.subplotsRegistry; + if(fullLayout._hasGL3D && plotRegistry.gl3d) { + plotRegistry.gl3d.initAxes(gd); + } // Plot container fullLayout._container = gd3.selectAll('.plot-container').data([0]); diff --git a/src/plots/gl3d/index.js b/src/plots/gl3d/index.js new file mode 100644 index 00000000000..7754b4e9b7a --- /dev/null +++ b/src/plots/gl3d/index.js @@ -0,0 +1,97 @@ +/** +* Copyright 2012-2016, 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'; + +var Plotly = require('../../plotly'); + +var Scene = require('./scene'); + +var plots = Plotly.Plots; +var axesNames = ['xaxis', 'yaxis', 'zaxis']; + + +exports.type = 'gl3d'; + +exports.attr = 'scene'; + +exports.idRoot = 'scene'; + +exports.attributes = require('./layout/attributes'); + +exports.layoutAttributes = require('./layout/layout_attributes'); + +exports.supplyLayoutDefaults = require('./layout/defaults'); + +exports.plot = function plotGl3d(gd) { + var fullLayout = gd._fullLayout, + fullData = gd._fullData, + sceneIds = plots.getSubplotIds(fullLayout, 'gl3d'); + + fullLayout._paperdiv.style({ + width: fullLayout.width + 'px', + height: fullLayout.height + 'px' + }); + + gd._context.setBackground(gd, fullLayout.paper_bgcolor); + + for(var i = 0; i < sceneIds.length; i++) { + var sceneId = sceneIds[i], + fullSceneData = plots.getSubplotData(fullData, 'gl3d', sceneId), + scene = fullLayout[sceneId]._scene; // ref. to corresp. Scene instance + + // If Scene is not instantiated, create one! + if(scene === undefined) { + scene = new Scene({ + container: gd.querySelector('.gl-container'), + id: sceneId, + staticPlot: gd._context.staticPlot, + plotGlPixelRatio: gd._context.plotGlPixelRatio + }, fullLayout + ); + + fullLayout[sceneId]._scene = scene; // set ref to Scene instance + } + + scene.plot(fullSceneData, fullLayout, gd.layout); // takes care of business + } +}; + +// clean scene ids, 'scene1' -> 'scene' +exports.cleanId = function cleanId(id) { + if (!id.match(/^scene[0-9]*$/)) return; + + var sceneNum = id.substr(5); + if (sceneNum === '1') sceneNum = ''; + + return 'scene' + sceneNum; +}; + +exports.setConvert = require('./set_convert'); + +exports.initAxes = function (gd) { + var fullLayout = gd._fullLayout; + + // until they play better together + delete fullLayout.xaxis; + delete fullLayout.yaxis; + + var sceneIds = Plotly.Plots.getSubplotIds(fullLayout, 'gl3d'); + + for(var i = 0; i < sceneIds.length; ++i) { + var sceneId = sceneIds[i]; + var sceneLayout = fullLayout[sceneId]; + + for(var j = 0; j < 3; ++j) { + var axisName = axesNames[j]; + var ax = sceneLayout[axisName]; + ax._td = gd; + } + } +}; diff --git a/src/plots/gl3d/layout/index.js b/src/plots/gl3d/layout/index.js deleted file mode 100644 index fb04bc278e2..00000000000 --- a/src/plots/gl3d/layout/index.js +++ /dev/null @@ -1,57 +0,0 @@ -/** -* Copyright 2012-2016, 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'; - -var Plotly = require('../../../plotly'); -var attributes = require('./attributes'); - -var axesNames = ['xaxis', 'yaxis', 'zaxis']; -var noop = function () {}; - -Plotly.Plots.registerSubplot('gl3d', 'scene', 'scene', attributes); - -exports.layoutAttributes = require('./layout_attributes'); - -exports.supplyLayoutDefaults = require('./defaults'); - -// clean scene ids, 'scene1' -> 'scene' -exports.cleanId = function cleanId(id) { - if (!id.match(/^scene[0-9]*$/)) return; - - var sceneNum = id.substr(5); - if (sceneNum === '1') sceneNum = ''; - - return 'scene' + sceneNum; -}; - -exports.setConvert = function(containerOut) { - Plotly.Axes.setConvert(containerOut); - containerOut.setScale = noop; -}; - -exports.initAxes = function (td) { - var fullLayout = td._fullLayout; - - // until they play better together - delete fullLayout.xaxis; - delete fullLayout.yaxis; - - var sceneIds = Plotly.Plots.getSubplotIds(fullLayout, 'gl3d'); - - for (var i = 0; i < sceneIds.length; ++i) { - var sceneId = sceneIds[i]; - var sceneLayout = fullLayout[sceneId]; - for (var j = 0; j < 3; ++j) { - var axisName = axesNames[j]; - var ax = sceneLayout[axisName]; - ax._td = td; - } - } -}; diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index 9431b107e95..7cc08d4e969 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -13,19 +13,18 @@ var Plotly = require('../../plotly'); var createPlot = require('gl-plot3d'); -var createAxesOptions = require('./layout/convert'); -var createSpikeOptions = require('./layout/spikes'); -var computeTickMarks = require('./layout/tick_marks'); - var createScatterTrace = require('../../traces/scatter3d/convert'); var createSurfaceTrace = require('../../traces/surface/convert'); var createMeshTrace = require('../../traces/mesh3d/convert'); +var str2RGBAarray = require('../../lib/str2rgbarray'); +var showNoWebGlMsg = require('../../lib/show_no_webgl_msg'); var createCamera = require('./camera'); var project = require('./project'); - -var str2RGBAarray = require('../../lib/str2rgbarray'); -var showNoWebGlMsg = require('../../lib/show_no_webgl_msg'); +var setConvert = require('./set_convert'); +var createAxesOptions = require('./layout/convert'); +var createSpikeOptions = require('./layout/spikes'); +var computeTickMarks = require('./layout/tick_marks'); var STATIC_CANVAS, STATIC_CONTEXT; @@ -310,7 +309,7 @@ proto.plot = function(sceneData, fullLayout, layout) { // Update axes functions BEFORE updating traces for (i = 0; i < 3; ++i) { var axis = fullSceneLayout[axisProperties[i]]; - Plotly.Gl3dLayout.setConvert(axis); + setConvert(axis); } //Convert scene data @@ -536,7 +535,7 @@ proto.destroy = function() { // for reset camera button in mode bar proto.setCameraToDefault = function setCameraToDefault () { - // as in Gl3dLayout.layoutAttributes + // as in Gl3d.layoutAttributes this.glplot.camera.lookAt( [1.25, 1.25, 1.25], [0 , 0 , 0 ], diff --git a/src/plots/gl3d/set_convert.js b/src/plots/gl3d/set_convert.js new file mode 100644 index 00000000000..25ad8724dfb --- /dev/null +++ b/src/plots/gl3d/set_convert.js @@ -0,0 +1,20 @@ +/** +* Copyright 2012-2016, 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'; + +var Plotly = require('../../plotly'); + +var noop = function () {}; + + +module.exports = function setConvert(containerOut) { + Plotly.Axes.setConvert(containerOut); + containerOut.setScale = noop; +}; diff --git a/src/plots/layout_attributes.js b/src/plots/layout_attributes.js index 5643f67ed69..c873b48ed92 100644 --- a/src/plots/layout_attributes.js +++ b/src/plots/layout_attributes.js @@ -195,7 +195,7 @@ module.exports = { _nestedModules: { 'xaxis': 'Axes', 'yaxis': 'Axes', - 'scene': 'Gl3dLayout', + 'scene': 'gl3d', 'geo': 'geo', 'legend': 'Legend', 'annotations': 'Annotations', diff --git a/test/jasmine/tests/gl3dlayout_test.js b/test/jasmine/tests/gl3dlayout_test.js index 0013aac11f4..e4410f1523e 100644 --- a/test/jasmine/tests/gl3dlayout_test.js +++ b/test/jasmine/tests/gl3dlayout_test.js @@ -1,13 +1,14 @@ -var Plotly = require('@src/plotly'); +var Gl3d = require('@src/plots/gl3d'); -describe('Test Gl3dLayout', function () { + +describe('Test Gl3d layout defaults', function () { 'use strict'; describe('supplyLayoutDefaults', function() { var layoutIn, layoutOut; - var supplyLayoutDefaults = Plotly.Gl3dLayout.supplyLayoutDefaults; + var supplyLayoutDefaults = Gl3d.supplyLayoutDefaults; beforeEach(function() { layoutOut = { From 6640747a34a14da1f45a30ffb49b732a11370ad7 Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:48:30 -0500 Subject: [PATCH 05/16] rm plotGeo from Plotly.plot code --- src/plot_api/plot_api.js | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index cc2bb075197..d896c475a40 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -418,41 +418,6 @@ function setPlotContext(gd, config) { } } -function plotGeo(gd) { - var fullLayout = gd._fullLayout, - fullData = gd._fullData, - geoIds = plots.getSubplotIds(fullLayout, 'geo'); - - var i, geoId, fullGeoData, geo; - - // if 'plotly-geo-assets.js' is not included, - // initialize object to keep reference to every loaded topojson - if(window.PlotlyGeoAssets === undefined) { - window.PlotlyGeoAssets = { topojson : {} }; - } - - for (i = 0; i < geoIds.length; i++) { - geoId = geoIds[i]; - fullGeoData = plots.getSubplotData(fullData, 'geo', geoId); - geo = fullLayout[geoId]._geo; - - // If geo is not instantiated, create one! - if(geo === undefined) { - geo = new Plotly.Geo( - { - id: geoId, - container: fullLayout._geocontainer.node(), - topojsonURL: gd._context.topojsonURL - }, - fullLayout - ); - fullLayout[geoId]._geo = geo; - } - - geo.plot(fullGeoData, fullLayout, gd._promises); - } -} - function plotGl2d(gd) { var fullLayout = gd._fullLayout, fullData = gd._fullData, From 01ab6208e898ba84e583e8772ac2915c5227e2a4 Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:49:04 -0500 Subject: [PATCH 06/16] add gl2d plot index + register it in plotly.js --- src/plot_api/plot_api.js | 33 ----------------------- src/plotly.js | 5 +++- src/plots/gl2d/index.js | 57 +++++++++++++++++++++++++++++++++++++++ src/plots/gl2d/scene2d.js | 2 -- 4 files changed, 61 insertions(+), 36 deletions(-) create mode 100644 src/plots/gl2d/index.js diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index d896c475a40..63e3c532ca2 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -418,39 +418,6 @@ function setPlotContext(gd, config) { } } -function plotGl2d(gd) { - var fullLayout = gd._fullLayout, - fullData = gd._fullData, - subplotIds = plots.getSubplotIds(fullLayout, 'gl2d'); - - for(var i = 0; i < subplotIds.length; i++) { - var subplotId = subplotIds[i], - subplotObj = fullLayout._plots[subplotId], - fullSubplotData = plots.getSubplotData(fullData, 'gl2d', subplotId); - var scene; - - // ref. to corresp. Scene instance - scene = subplotObj._scene2d; - - // If Scene is not instantiated, create one! - if(scene === undefined) { - scene = new Plotly.Scene2D({ - container: gd.querySelector('.gl-container'), - id: subplotId, - staticPlot: gd._context.staticPlot, - plotGlPixelRatio: gd._context.plotGlPixelRatio - }, - fullLayout - ); - - // set ref to Scene instance - subplotObj._scene2d = scene; - } - - scene.plot(fullSubplotData, fullLayout, gd.layout); - } -} - function plotPolar(gd, data, layout) { // build or reuse the container skeleton var plotContainer = d3.select(gd).selectAll('.plot-container') diff --git a/src/plotly.js b/src/plotly.js index 37ba6b746f1..6fdb33ec1de 100644 --- a/src/plotly.js +++ b/src/plotly.js @@ -44,7 +44,10 @@ var Geo = require('./plots/geo'); Plots.registerSubplot(Geo); exports.Scene = require('./plots/gl3d/scene'); exports.Gl3dLayout = require('./plots/gl3d/layout'); -exports.Scene2D = require('./plots/gl2d/scene2d'); + +var Gl2d = require('./plots/gl2d'); +Plots.registerSubplot(Gl2d); + exports.micropolar = require('./plots/polar/micropolar'); // components diff --git a/src/plots/gl2d/index.js b/src/plots/gl2d/index.js new file mode 100644 index 00000000000..e163788977e --- /dev/null +++ b/src/plots/gl2d/index.js @@ -0,0 +1,57 @@ +/** +* Copyright 2012-2016, 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'; + +var Plotly = require('../../plotly'); + +var Scene2D = require('./scene2d'); + +var Plots = Plotly.Plots; + + +exports.type = 'gl2d'; + +exports.attr = ['xaxis', 'yaxis']; + +exports.idRoot = ['x', 'y']; + +exports.attributes = require('../cartesian/attributes'); + +exports.plot = function plotGl2d(gd) { + var fullLayout = gd._fullLayout, + fullData = gd._fullData, + subplotIds = Plots.getSubplotIds(fullLayout, 'gl2d'); + + for(var i = 0; i < subplotIds.length; i++) { + var subplotId = subplotIds[i], + subplotObj = fullLayout._plots[subplotId], + fullSubplotData = Plots.getSubplotData(fullData, 'gl2d', subplotId); + + // ref. to corresp. Scene instance + var scene = subplotObj._scene2d; + + // If Scene is not instantiated, create one! + if(scene === undefined) { + scene = new Scene2D({ + container: gd.querySelector('.gl-container'), + id: subplotId, + staticPlot: gd._context.staticPlot, + plotGlPixelRatio: gd._context.plotGlPixelRatio + }, + fullLayout + ); + + // set ref to Scene instance + subplotObj._scene2d = scene; + } + + scene.plot(fullSubplotData, fullLayout, gd.layout); + } +}; diff --git a/src/plots/gl2d/scene2d.js b/src/plots/gl2d/scene2d.js index e30e0f4f276..e284123d17f 100644 --- a/src/plots/gl2d/scene2d.js +++ b/src/plots/gl2d/scene2d.js @@ -25,8 +25,6 @@ var showNoWebGlMsg = require('../../lib/show_no_webgl_msg'); var AXES = ['xaxis', 'yaxis']; var STATIC_CANVAS, STATIC_CONTEXT; -Plotly.Plots.registerSubplot('gl2d', ['xaxis', 'yaxis'], ['x', 'y'], - Plotly.Axes.attributes); function Scene2D(options, fullLayout) { this.container = options.container; From c8eb2058a383bd1c3a3f4f85b08407488124deb7 Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:49:17 -0500 Subject: [PATCH 07/16] remove Scene and Gl3dLayout from internal Plotly --- src/plotly.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plotly.js b/src/plotly.js index 6fdb33ec1de..152afc0314a 100644 --- a/src/plotly.js +++ b/src/plotly.js @@ -37,13 +37,15 @@ var Plots = exports.Plots = require('./plots/plots'); var Cartesian = require('./plots/cartesian'); Plots.registerSubplot(Cartesian); + exports.Axes = require('./plots/cartesian/axes'); exports.Fx = require('./plots/cartesian/graph_interact'); var Geo = require('./plots/geo'); Plots.registerSubplot(Geo); -exports.Scene = require('./plots/gl3d/scene'); -exports.Gl3dLayout = require('./plots/gl3d/layout'); + +var Gl3d = require('./plots/gl3d'); +Plots.registerSubplot(Gl3d); var Gl2d = require('./plots/gl2d'); Plots.registerSubplot(Gl2d); From fcc00c1f7a016a244a436952d21d6048726e3798 Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:49:40 -0500 Subject: [PATCH 08/16] lint in plots.js --- src/plots/plots.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index fc12dfb1203..dbd1afa80ad 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -31,7 +31,7 @@ plots.fontWeight = 'normal'; /** * plots.register: register a module as the handler for a trace type * - * @param {object} module the module that will handle plotting this trace type + * @param {object} _module the module that will handle plotting this trace type * @param {string} thisType * @param {array of strings} categoriesIn all the categories this type is in, * tested by calls: Plotly.Plots.traceIs(trace, oneCategory) @@ -357,7 +357,7 @@ function positionPlayWithData(gd, container){ if(gd._context.sendData) { link.on('click', function() { - plots.sendDataToCloud(gd) + plots.sendDataToCloud(gd); }); } else { @@ -400,7 +400,7 @@ plots.sendDataToCloud = function(gd) { gd.emit('plotly_afterexport'); return false; -} +}; plots.supplyDefaults = function(gd) { // fill in default values: From 51fd6fc363b874ed4708258fb36fe3d53cc2276f Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:50:14 -0500 Subject: [PATCH 09/16] loop over plot modules to look for supplyLayoutDefaults, instead of hard-coding the module names --- src/plots/plots.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index dbd1afa80ad..8e6a8b52d98 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -658,17 +658,29 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) { plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) { var moduleLayoutDefaults = [ 'Axes', 'Annotations', 'Shapes', 'Fx', - 'Bar', 'Box', 'Gl3dLayout', 'GeoLayout', 'Pie', 'Legend' + 'Bar', 'Box', 'Pie', 'Legend' ]; - var i, module; + var i, _module; // don't add a check for 'function in module' as it is better to error out and // secure the module API then not apply the default function. for(i = 0; i < moduleLayoutDefaults.length; i++) { - module = moduleLayoutDefaults[i]; - if(Plotly[module]) { - Plotly[module].supplyLayoutDefaults(layoutIn, layoutOut, fullData); + _module = moduleLayoutDefaults[i]; + + if(Plotly[_module]) { + Plotly[_module].supplyLayoutDefaults(layoutIn, layoutOut, fullData); + } + } + + var plotTypes = Object.keys(subplotsRegistry); + + for(i = 0; i < plotTypes.length; i++) { + _module = subplotsRegistry[plotTypes[i]]; + + // e.g. gl2d does not have a layout-defaults step + if(_module.supplyLayoutDefaults) { + _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData); } } }; From 35470aa92d04def95eaa7d2b18ab646e34fd1008 Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:51:14 -0500 Subject: [PATCH 10/16] add special case for plot modules in plot schema nested module handler --- src/plot_api/plot_schema.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plot_api/plot_schema.js b/src/plot_api/plot_schema.js index 825b8c7eed0..0cf21ee997d 100644 --- a/src/plot_api/plot_schema.js +++ b/src/plot_api/plot_schema.js @@ -231,7 +231,12 @@ function getModule(arg) { { attributes: polarAreaAttrs } : Plotly.Plots.getModule({type: arg.type}); } - else if('module' in arg) return Plotly[arg.module]; + + var subplotsRegistry = Plotly.Plots.subplotsRegistry, + _module = arg.module; + + if(subplotsRegistry[_module]) return subplotsRegistry[_module]; + else if('module' in arg) return Plotly[_module]; } function removeUnderscoreAttrs(attributes) { From 3bea1c7e2409a3d7e98bcec715de969180ca0acf Mon Sep 17 00:00:00 2001 From: etpinard Date: Tue, 5 Jan 2016 16:52:19 -0500 Subject: [PATCH 11/16] call plot module plot method base on plot registy in Plotly.plot --- src/plot_api/plot_api.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 63e3c532ca2..3b703874adf 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -266,10 +266,12 @@ Plotly.plot = function(gd, data, layout, config) { // clean up old scenes that no longer have associated data // will this be a performance hit? - // ... until subplot of different type play better together - if(gd._fullLayout._hasGL3D) plotGl3d(gd); - if(gd._fullLayout._hasGeo) plotGeo(gd); - if(gd._fullLayout._hasGL2D) plotGl2d(gd); + var registry = plots.subplotsRegistry; + + // TODO incorporate cartesian and polar plots into this paradigm + if(fullLayout._hasGL3D && registry.gl3d) registry.gl3d.plot(gd); + if(fullLayout._hasGeo && registry.geo) registry.geo.plot(gd); + if(fullLayout._hasGL2D && registry.gl2d) registry.gl2d.plot(gd); // in case of traces that were heatmaps or contour maps // previously, remove them and their colorbars explicitly From 0b07dbd5d32a24f01199daee8a4d55ada73f44ed Mon Sep 17 00:00:00 2001 From: etpinard Date: Wed, 6 Jan 2016 16:08:46 -0500 Subject: [PATCH 12/16] rm existence check for plotRegistry[].plot : - assume that if fullLayout._has[] is set, the corresponding plot module has been registered. If not the case, this will result in an error. --- src/plot_api/plot_api.js | 18 +++++++----------- src/plots/plots.js | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/plot_api/plot_api.js b/src/plot_api/plot_api.js index 3b703874adf..aa7b2115cec 100644 --- a/src/plot_api/plot_api.js +++ b/src/plot_api/plot_api.js @@ -266,12 +266,12 @@ Plotly.plot = function(gd, data, layout, config) { // clean up old scenes that no longer have associated data // will this be a performance hit? - var registry = plots.subplotsRegistry; + var plotRegistry = plots.subplotsRegistry; // TODO incorporate cartesian and polar plots into this paradigm - if(fullLayout._hasGL3D && registry.gl3d) registry.gl3d.plot(gd); - if(fullLayout._hasGeo && registry.geo) registry.geo.plot(gd); - if(fullLayout._hasGL2D && registry.gl2d) registry.gl2d.plot(gd); + if(fullLayout._hasGL3D) plotRegistry.gl3d.plot(gd); + if(fullLayout._hasGeo) plotRegistry.geo.plot(gd); + if(fullLayout._hasGL2D) plotRegistry.gl2d.plot(gd); // in case of traces that were heatmaps or contour maps // previously, remove them and their colorbars explicitly @@ -765,9 +765,8 @@ function cleanData(data, existingData) { if(trace.yaxis) trace.yaxis = Plotly.Axes.cleanId(trace.yaxis, 'y'); // scene ids scene1 -> scene - var plotRegistry = plots.subplotsRegistry; - if(trace.scene && plotRegistry.gl3d) { - trace.scene = plotRegistry.gl3d.cleanId(trace.scene); + if(plots.traceIs(trace, 'gl3d') && trace.scene) { + trace.scene = plots.subplotsRegistry.gl3d.cleanId(trace.scene); } if(!plots.traceIs(trace, 'pie')) { @@ -2494,10 +2493,7 @@ function makePlotFramework(gd) { fullLayout = gd._fullLayout; // TODO - find a better place for 3D to initialize axes - var plotRegistry = plots.subplotsRegistry; - if(fullLayout._hasGL3D && plotRegistry.gl3d) { - plotRegistry.gl3d.initAxes(gd); - } + if(fullLayout._hasGL3D) plots.subplotsRegistry.gl3d.initAxes(gd); // Plot container fullLayout._container = gd3.selectAll('.plot-container').data([0]); diff --git a/src/plots/plots.js b/src/plots/plots.js index 8e6a8b52d98..cb428934c55 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -433,7 +433,7 @@ plots.supplyDefaults = function(gd) { fullTrace = plots.supplyDataDefaults(trace, i, newFullLayout); newFullData.push(fullTrace); - // DETECT 3D, Cartesian, and Polar + // detect plot type if(plots.traceIs(fullTrace, 'cartesian')) newFullLayout._hasCartesian = true; else if(plots.traceIs(fullTrace, 'gl3d')) newFullLayout._hasGL3D = true; else if(plots.traceIs(fullTrace, 'geo')) newFullLayout._hasGeo = true; From 1dcce201ff090756e3264b1b18c0bdd10f8b37bb Mon Sep 17 00:00:00 2001 From: etpinard Date: Wed, 6 Jan 2016 16:09:17 -0500 Subject: [PATCH 13/16] rename plot module 'type' field --> 'name' --- src/plots/cartesian/index.js | 2 +- src/plots/geo/index.js | 2 +- src/plots/gl2d/index.js | 2 +- src/plots/gl3d/index.js | 2 +- src/plots/plots.js | 2 +- test/jasmine/tests/plots_test.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plots/cartesian/index.js b/src/plots/cartesian/index.js index b37c070ea51..0d6eb38e7a6 100644 --- a/src/plots/cartesian/index.js +++ b/src/plots/cartesian/index.js @@ -12,7 +12,7 @@ var Plotly = require('../../plotly'); -exports.type = 'cartesian'; +exports.name = 'cartesian'; exports.attr = ['xaxis', 'yaxis']; diff --git a/src/plots/geo/index.js b/src/plots/geo/index.js index 345ada84c17..3effce756ce 100644 --- a/src/plots/geo/index.js +++ b/src/plots/geo/index.js @@ -16,7 +16,7 @@ var Geo = require('./geo'); var Plots = Plotly.Plots; -exports.type = 'geo'; +exports.name = 'geo'; exports.attr = 'geo'; diff --git a/src/plots/gl2d/index.js b/src/plots/gl2d/index.js index e163788977e..57c0b9e9d0c 100644 --- a/src/plots/gl2d/index.js +++ b/src/plots/gl2d/index.js @@ -16,7 +16,7 @@ var Scene2D = require('./scene2d'); var Plots = Plotly.Plots; -exports.type = 'gl2d'; +exports.name = 'gl2d'; exports.attr = ['xaxis', 'yaxis']; diff --git a/src/plots/gl3d/index.js b/src/plots/gl3d/index.js index 7754b4e9b7a..22784dd8514 100644 --- a/src/plots/gl3d/index.js +++ b/src/plots/gl3d/index.js @@ -17,7 +17,7 @@ var plots = Plotly.Plots; var axesNames = ['xaxis', 'yaxis', 'zaxis']; -exports.type = 'gl3d'; +exports.name = 'gl3d'; exports.attr = 'scene'; diff --git a/src/plots/plots.js b/src/plots/plots.js index cb428934c55..dd7d2801c3c 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -126,7 +126,7 @@ plots.traceIs = function traceIs(traceType, category) { * TODO use these in Lib.coerce */ plots.registerSubplot = function(_module) { - var plotType = _module.type; + var plotType = _module.name; if(subplotsRegistry[plotType]) { throw new Error('plot type' + plotType + ' already registered'); diff --git a/test/jasmine/tests/plots_test.js b/test/jasmine/tests/plots_test.js index 1a963e6fb0d..6c2d7ffcb53 100644 --- a/test/jasmine/tests/plots_test.js +++ b/test/jasmine/tests/plots_test.js @@ -235,7 +235,7 @@ describe('Test Plotly.Plots', function () { describe('Plotly.Plots.registerSubplot', function() { var fake = { - type: 'fake', + name: 'fake', attr: 'abc', idRoot: 'cba', attributes: { stuff: { 'more stuff': 102102 } } From 0a7222c64941682201a7f1d815999e6c409d6b9e Mon Sep 17 00:00:00 2001 From: etpinard Date: Wed, 6 Jan 2016 16:09:49 -0500 Subject: [PATCH 14/16] rm several Plotly[] calls in plot_schema.js --- src/plot_api/plot_schema.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/plot_api/plot_schema.js b/src/plot_api/plot_schema.js index 0cf21ee997d..ce73eda7ca6 100644 --- a/src/plot_api/plot_schema.js +++ b/src/plot_api/plot_schema.js @@ -10,10 +10,12 @@ 'use strict'; var Plotly = require('../plotly'); +var Plots = require('../plots/plots'); +var Lib = require('../lib'); -var extendFlat = Plotly.Lib.extendFlat; -var extendDeep = Plotly.Lib.extendDeep; -var extendDeepAll = Plotly.Lib.extendDeepAll; +var extendFlat = Lib.extendFlat; +var extendDeep = Lib.extendDeep; +var extendDeepAll = Lib.extendDeepAll; var NESTED_MODULE = '_nestedModules', COMPOSED_MODULE = '_composedModules', @@ -38,7 +40,7 @@ var PlotSchema = module.exports = {}; PlotSchema.get = function() { - Plotly.Plots.allTypes + Plots.allTypes .concat('area') // FIXME polar 'area' attributes .forEach(getTraceAttributes); @@ -56,7 +58,7 @@ PlotSchema.crawl = function(attrs, callback) { callback(attr, attrName, attrs); if(PlotSchema.isValObject(attr)) return; - if(Plotly.Lib.isPlainObject(attr)) PlotSchema.crawl(attr, callback); + if(Lib.isPlainObject(attr)) PlotSchema.crawl(attr, callback); }); }; @@ -65,7 +67,7 @@ PlotSchema.isValObject = function(obj) { }; function getTraceAttributes(type) { - var globalAttributes = Plotly.Plots.attributes, + var globalAttributes = Plots.attributes, _module = getModule({type: type}), meta = getMeta(type), subplotRegistry = getSubplotRegistry(type); @@ -111,7 +113,7 @@ function getTraceAttributes(type) { } function getLayoutAttributes() { - var globalLayoutAttributes = Plotly.Plots.layoutAttributes, + var globalLayoutAttributes = Plots.layoutAttributes, layoutAttributes = {}; // layout module attributes (+ nested + composed) @@ -136,7 +138,7 @@ function getLayoutAttributes() { function getDefs() { plotSchema.defs = { - valObjects: Plotly.Lib.valObjects, + valObjects: Lib.valObjects, metaKeys: UNDERSCORE_ATTRS.concat(['description', 'role']) }; } @@ -157,7 +159,7 @@ function coupleAttrs(attrsIn, attrsOut, whichAttrs, type) { nestedAttrs, {}, whichAttrs, type ); - Plotly.Lib.nestedProperty(attrsOut, kk) + Lib.nestedProperty(attrsOut, kk) .set(extendDeep({}, nestedReference)); }); return; @@ -180,7 +182,7 @@ function coupleAttrs(attrsIn, attrsOut, whichAttrs, type) { return; } - attrsOut[k] = Plotly.Lib.isPlainObject(attrsIn[k]) ? + attrsOut[k] = Lib.isPlainObject(attrsIn[k]) ? extendDeepAll({}, attrsIn[k]) : attrsIn[k]; }); @@ -214,7 +216,7 @@ function mergeValTypeAndRole(attrs) { attrs[attrName + 'src'] = makeSrcAttr(attrName); } } - else if(Plotly.Lib.isPlainObject(attr)) { + else if(Lib.isPlainObject(attr)) { // all attrs container objects get role 'object' attr.role = 'object'; } @@ -229,10 +231,10 @@ function getModule(arg) { if('type' in arg) { return (arg.type === 'area') ? // FIXME { attributes: polarAreaAttrs } : - Plotly.Plots.getModule({type: arg.type}); + Plots.getModule({type: arg.type}); } - var subplotsRegistry = Plotly.Plots.subplotsRegistry, + var subplotsRegistry = Plots.subplotsRegistry, _module = arg.module; if(subplotsRegistry[_module]) return subplotsRegistry[_module]; @@ -249,7 +251,7 @@ function removeUnderscoreAttrs(attributes) { function getMeta(type) { if(type === 'area') return {}; // FIXME - return Plotly.Plots.modules[type].meta || {}; + return Plots.modules[type].meta || {}; } function assignPolarLayoutAttrs(layoutAttributes) { @@ -266,9 +268,9 @@ function assignPolarLayoutAttrs(layoutAttributes) { function getSubplotRegistry(traceType) { if(traceType === 'area') return {}; // FIXME - var subplotsRegistry = Plotly.Plots.subplotsRegistry, + var subplotsRegistry = Plots.subplotsRegistry, subplotType = Object.keys(subplotsRegistry).filter(function(subplotType) { - return Plotly.Plots.traceIs({type: traceType}, subplotType); + return Plots.traceIs({type: traceType}, subplotType); })[0]; if(subplotType === undefined) return {}; @@ -277,7 +279,7 @@ function getSubplotRegistry(traceType) { } function handleSubplotObjs(layoutAttributes) { - var subplotsRegistry = Plotly.Plots.subplotsRegistry; + var subplotsRegistry = Plots.subplotsRegistry; Object.keys(layoutAttributes).forEach(function(k) { Object.keys(subplotsRegistry).forEach(function(subplotType) { From 8da8a36879b25a71746c9f3d09542ad3da06b551 Mon Sep 17 00:00:00 2001 From: etpinard Date: Wed, 6 Jan 2016 16:10:36 -0500 Subject: [PATCH 15/16] loops over trace modules to check for supplyLayoutDefaults, instead of relying an a hard-coded list. --- src/plots/plots.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/plots/plots.js b/src/plots/plots.js index dd7d2801c3c..6df2c1f1591 100644 --- a/src/plots/plots.js +++ b/src/plots/plots.js @@ -656,25 +656,13 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) { }; plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) { - var moduleLayoutDefaults = [ - 'Axes', 'Annotations', 'Shapes', 'Fx', - 'Bar', 'Box', 'Pie', 'Legend' - ]; - var i, _module; - // don't add a check for 'function in module' as it is better to error out and - // secure the module API then not apply the default function. - for(i = 0; i < moduleLayoutDefaults.length; i++) { - _module = moduleLayoutDefaults[i]; - - if(Plotly[_module]) { - Plotly[_module].supplyLayoutDefaults(layoutIn, layoutOut, fullData); - } - } + // TODO incorporate into subplotRegistry + Plotly.Axes.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + // plot module layout defaults var plotTypes = Object.keys(subplotsRegistry); - for(i = 0; i < plotTypes.length; i++) { _module = subplotsRegistry[plotTypes[i]]; @@ -683,6 +671,27 @@ plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) { _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData); } } + + // trace module layout defaults + var traceTypes = Object.keys(modules); + for(i = 0; i < traceTypes.length; i++) { + _module = modules[allTypes[i]].module; + + if(_module.supplyLayoutDefaults) { + _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData); + } + } + + // TODO register these + // Legend must come after traces (e.g. it depends on 'barmode') + var moduleLayoutDefaults = ['Fx', 'Annotations', 'Shapes', 'Legend']; + for(i = 0; i < moduleLayoutDefaults.length; i++) { + _module = moduleLayoutDefaults[i]; + + if(Plotly[_module]) { + Plotly[_module].supplyLayoutDefaults(layoutIn, layoutOut, fullData); + } + } }; plots.purge = function(gd) { From 7ccd79f6e7833c02ecf180bbde5a8f78f3fd7a0e Mon Sep 17 00:00:00 2001 From: etpinard Date: Wed, 6 Jan 2016 18:39:13 -0500 Subject: [PATCH 16/16] fix a few :cow2: --- src/plots/geo/index.js | 10 ++++++---- src/plots/gl3d/index.js | 3 ++- src/plots/gl3d/scene.js | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/plots/geo/index.js b/src/plots/geo/index.js index 3effce756ce..0769e53dafa 100644 --- a/src/plots/geo/index.js +++ b/src/plots/geo/index.js @@ -49,10 +49,12 @@ exports.plot = function plotGeo(gd) { // If geo is not instantiated, create one! if(geo === undefined) { geo = new Geo({ - id: geoId, - container: fullLayout._geocontainer.node(), - topojsonURL: gd._context.topojsonURL - }, fullLayout); + id: geoId, + container: fullLayout._geocontainer.node(), + topojsonURL: gd._context.topojsonURL + }, + fullLayout + ); fullLayout[geoId]._geo = geo; } diff --git a/src/plots/gl3d/index.js b/src/plots/gl3d/index.js index 22784dd8514..78abd7cf633 100644 --- a/src/plots/gl3d/index.js +++ b/src/plots/gl3d/index.js @@ -53,7 +53,8 @@ exports.plot = function plotGl3d(gd) { id: sceneId, staticPlot: gd._context.staticPlot, plotGlPixelRatio: gd._context.plotGlPixelRatio - }, fullLayout + }, + fullLayout ); fullLayout[sceneId]._scene = scene; // set ref to Scene instance diff --git a/src/plots/gl3d/scene.js b/src/plots/gl3d/scene.js index 7cc08d4e969..ce57e0e7f7c 100644 --- a/src/plots/gl3d/scene.js +++ b/src/plots/gl3d/scene.js @@ -22,7 +22,7 @@ var showNoWebGlMsg = require('../../lib/show_no_webgl_msg'); var createCamera = require('./camera'); var project = require('./project'); var setConvert = require('./set_convert'); -var createAxesOptions = require('./layout/convert'); +var createAxesOptions = require('./layout/convert'); var createSpikeOptions = require('./layout/spikes'); var computeTickMarks = require('./layout/tick_marks');