-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Replace _has<PlotType> variables with '_has()' fullLayout method #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
88f552a
525e3c7
876ce4b
f45ffec
4e0c6da
93493a6
e63ba4a
b655cb0
f476e05
1c41c2e
313150e
392619c
3787d47
68b12c4
a41427c
a48d071
a78521c
aa2ec8b
77fb7e2
a141d78
dc297ca
e3f72f0
c59a960
9f94494
9837d8b
0c7b2f8
5e6759b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,7 +193,7 @@ plots.getSubplotIds = function getSubplotIds(layout, type) { | |
if(type === 'cartesian' && !layout._hasCartesian) return []; | ||
if(type === 'gl2d' && !layout._hasGL2D) return []; | ||
if(type === 'cartesian' || type === 'gl2d') { | ||
return Object.keys(layout._plots); | ||
return Object.keys(layout._plots || {}); | ||
} | ||
|
||
var idRegex = _module.idRegex, | ||
|
@@ -435,22 +435,29 @@ plots.sendDataToCloud = function(gd) { | |
return false; | ||
}; | ||
|
||
// Fill in default values: | ||
// | ||
// gd.data, gd.layout: | ||
// are precisely what the user specified | ||
// | ||
// gd._fullData, gd._fullLayout: | ||
// are complete descriptions of how to draw the plot | ||
// | ||
// gd._fullLayout._modules | ||
// is a list of all the trace modules required to draw the plot | ||
// | ||
plots.supplyDefaults = function(gd) { | ||
// fill in default values: | ||
// gd.data, gd.layout: | ||
// are precisely what the user specified | ||
// gd._fullData, gd._fullLayout: | ||
// are complete descriptions of how to draw the plot | ||
var oldFullLayout = gd._fullLayout || {}, | ||
newFullLayout = gd._fullLayout = {}, | ||
newLayout = gd.layout || {}, | ||
oldFullData = gd._fullData || [], | ||
newLayout = gd.layout || {}; | ||
|
||
var oldFullData = gd._fullData || [], | ||
newFullData = gd._fullData = [], | ||
newData = gd.data || [], | ||
modules = gd._modules = []; | ||
newData = gd.data || []; | ||
|
||
var i, trace, fullTrace, _module, axList, ax; | ||
var modules = newFullLayout._modules = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes more sense (and is more useful) to have |
||
|
||
var i, _module; | ||
|
||
// first fill in what we can of layout without looking at data | ||
// because fullData needs a few things from layout | ||
|
@@ -461,24 +468,28 @@ plots.supplyDefaults = function(gd) { | |
|
||
// then do the data | ||
for(i = 0; i < newData.length; i++) { | ||
trace = newData[i]; | ||
|
||
fullTrace = plots.supplyDataDefaults(trace, i, newFullLayout); | ||
var fullTrace = plots.supplyDataDefaults(newData[i], i, newFullLayout); | ||
newFullData.push(fullTrace); | ||
|
||
// 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; | ||
else if(plots.traceIs(fullTrace, 'pie')) newFullLayout._hasPie = true; | ||
else if(plots.traceIs(fullTrace, 'gl2d')) newFullLayout._hasGL2D = true; | ||
else if(plots.traceIs(fullTrace, 'ternary')) newFullLayout._hasTernary = true; | ||
else if('r' in fullTrace) newFullLayout._hasPolar = true; | ||
// detect polar | ||
if('r' in fullTrace) newFullLayout._hasPolar = true; | ||
|
||
// fill in modules list | ||
_module = fullTrace._module; | ||
if(_module && modules.indexOf(_module)===-1) modules.push(_module); | ||
if(_module && modules.indexOf(_module) === -1) modules.push(_module); | ||
} | ||
|
||
// attach helper method | ||
newFullLayout._has = hasPlotType.bind(newFullLayout); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mdtusz I know this could be more verbose, but I really like the look of e.g. |
||
|
||
// temporary block (before replace all _has??? with _hasPlotType() ? | ||
newFullLayout._hasCartesian = newFullLayout._has('cartesian'); | ||
newFullLayout._hasGeo = newFullLayout._has('geo'); | ||
newFullLayout._hasGL3D = newFullLayout._has('gl3d'); | ||
newFullLayout._hasGL2D = newFullLayout._has('gl2d'); | ||
newFullLayout._hasTernary = newFullLayout._has('ternary'); | ||
newFullLayout._hasPie = newFullLayout._has('pie'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
EDIT: No. we need keep this to preserve backward compatibility (and not break the old plot.ly workspace). |
||
|
||
// special cases that introduce interactions between traces | ||
for(i = 0; i < modules.length; i++) { | ||
_module = modules[i]; | ||
|
@@ -497,32 +508,46 @@ plots.supplyDefaults = function(gd) { | |
// clean subplots and other artifacts from previous plot calls | ||
plots.cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout); | ||
|
||
/* | ||
* Relink functions and underscore attributes to promote consistency between | ||
* plots. | ||
*/ | ||
// relink functions and _ attributes to promote consistency between plots | ||
relinkPrivateKeys(newFullLayout, oldFullLayout); | ||
|
||
plots.doAutoMargin(gd); | ||
|
||
// can't quite figure out how to get rid of this... each axis needs | ||
// a reference back to the DOM object for just a few purposes | ||
axList = Plotly.Axes.list(gd); | ||
var axList = Plotly.Axes.list(gd); | ||
for(i = 0; i < axList.length; i++) { | ||
ax = axList[i]; | ||
var ax = axList[i]; | ||
ax._gd = gd; | ||
ax.setScale(); | ||
} | ||
|
||
// update object references in calcdata | ||
if((gd.calcdata || []).length === newFullData.length) { | ||
for(i = 0; i < newFullData.length; i++) { | ||
trace = newFullData[i]; | ||
var trace = newFullData[i]; | ||
(gd.calcdata[i][0] || {}).trace = trace; | ||
} | ||
} | ||
}; | ||
|
||
// helper function to be bound to fullLayout to check | ||
// whether a certain plot type or layout categories is present on plot | ||
function hasPlotType(category) { | ||
var modules = this._modules || []; | ||
|
||
for(var i = 0; i < modules.length; i++) { | ||
var _module = modules[i]; | ||
|
||
if(_module.basePlotModule.name === category) return true; | ||
|
||
var layoutCategories = _module.layoutCategories || []; | ||
if(layoutCategories.indexOf(category) !== -1) return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayout) { | ||
var i, j; | ||
|
||
|
@@ -713,18 +738,12 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) { | |
coerce('separators'); | ||
coerce('hidesources'); | ||
coerce('smith'); | ||
coerce('_hasCartesian'); | ||
coerce('_hasGL3D'); | ||
coerce('_hasGeo'); | ||
coerce('_hasPie'); | ||
coerce('_hasGL2D'); | ||
coerce('_hasTernary'); | ||
}; | ||
|
||
plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData) { | ||
var i, _module; | ||
|
||
// TODO incorporate into subplotRegistry | ||
// TODO incorporate into subplotsRegistry | ||
Plotly.Axes.supplyLayoutDefaults(layoutIn, layoutOut, fullData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ important |
||
|
||
// plot module layout defaults | ||
|
@@ -792,7 +811,6 @@ plots.purge = function(gd) { | |
|
||
// these get recreated on Plotly.plot anyway, but just to be safe | ||
// (and to have a record of them...) | ||
delete gd._modules; | ||
delete gd._tester; | ||
delete gd._testref; | ||
delete gd._promises; | ||
|
@@ -810,7 +828,7 @@ plots.purge = function(gd) { | |
}; | ||
|
||
plots.style = function(gd) { | ||
var _modules = gd._modules; | ||
var _modules = gd._fullLayout._modules; | ||
|
||
for(var i = 0; i < _modules.length; i++) { | ||
var _module = _modules[i]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ Pie.moduleType = 'trace'; | |
Pie.name = 'pie'; | ||
Pie.basePlotModule = require('../../plots/cartesian'); | ||
Pie.categories = ['pie', 'showLegend']; | ||
Pie.layoutCategories = ['pie']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMPORTANT pie plots now have |
||
Pie.meta = { | ||
description: [ | ||
'A data visualized by the sectors of the pie is set in `values`.', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... as pie plots are now
hasCartesian
andhasPie
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is not really the same logic... what if you have both pie and cartesian for real?
I know pie is my own doing, but why does it need to have cartesian as its
basePlotModule
? Can we rip that out into its own thing? That's probably a bigger project, but as it is it's not only hacky but tough to get the logic right.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.
It should be pretty easy I think. I'll give it a shot in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy. Done in f476e05
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that's a lot easier than I was afraid it would be 💥