-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Combine geo and ternary genaral update pattern #1291
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
b3e25ac
447abec
fe8a3f9
92119bb
a7cca2e
fc0af0c
bfb05d4
83c2722
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 |
---|---|---|
|
@@ -124,8 +124,8 @@ plots.getSubplotIds = function getSubplotIds(layout, type) { | |
* Get the data trace(s) associated with a given subplot. | ||
* | ||
* @param {array} data plotly full data array. | ||
* @param {object} layout plotly full layout object. | ||
* @param {string} subplotId subplot ids to look for. | ||
* @param {string} type subplot type to look for. | ||
* @param {string} subplotId subplot id to look for. | ||
* | ||
* @return {array} list of trace objects. | ||
* | ||
|
@@ -157,6 +157,31 @@ plots.getSubplotData = function getSubplotData(data, type, subplotId) { | |
return subplotData; | ||
}; | ||
|
||
/** | ||
* Get calcdata traces(s) associated with a given subplot | ||
* | ||
* @param {array} calcData (as in gd.calcdata) | ||
* @param {string} type subplot type | ||
* @param {string} subplotId subplot id to look for | ||
* | ||
* @return {array} array of calcdata traces | ||
*/ | ||
plots.getSubplotCalcData = function(calcData, type, subplotId) { | ||
if(plots.subplotsRegistry[type] === undefined) return []; | ||
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.
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. Good call. Done in 83c2722 |
||
|
||
var attr = plots.subplotsRegistry[type].attr; | ||
var subplotCalcData = []; | ||
|
||
for(var i = 0; i < calcData.length; i++) { | ||
var calcTrace = calcData[i], | ||
trace = calcTrace[0].trace; | ||
|
||
if(trace[attr] === subplotId) subplotCalcData.push(calcTrace); | ||
} | ||
|
||
return subplotCalcData; | ||
}; | ||
|
||
// in some cases the browser doesn't seem to know how big | ||
// the text is at first, so it needs to draw it, | ||
// then wait a little, then draw it again | ||
|
@@ -2027,3 +2052,67 @@ plots.doCalcdata = function(gd, traces) { | |
calcdata[i] = cd; | ||
} | ||
}; | ||
|
||
plots.generalUpdatePerTraceModule = function(subplot, subplotCalcData, subplotLayout) { | ||
var traceHashOld = subplot.traceHash, | ||
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 always feel like the mutate-existing-data approach contributes a bit to fragility, but I understand why these things are as they are. |
||
traceHash = {}, | ||
i; | ||
|
||
function filterVisible(calcDataIn) { | ||
var calcDataOut = []; | ||
|
||
for(var i = 0; i < calcDataIn.length; i++) { | ||
var calcTrace = calcDataIn[i], | ||
trace = calcTrace[0].trace; | ||
|
||
if(trace.visible === true) calcDataOut.push(calcTrace); | ||
} | ||
|
||
return calcDataOut; | ||
} | ||
|
||
// build up moduleName -> calcData hash | ||
for(i = 0; i < subplotCalcData.length; i++) { | ||
var calcTraces = subplotCalcData[i], | ||
trace = calcTraces[0].trace; | ||
|
||
// skip over visible === false traces | ||
// as they don't have `_module` ref | ||
if(trace.visible) { | ||
traceHash[trace.type] = traceHash[trace.type] || []; | ||
traceHash[trace.type].push(calcTraces); | ||
} | ||
} | ||
|
||
var moduleNamesOld = Object.keys(traceHashOld); | ||
var moduleNames = Object.keys(traceHash); | ||
|
||
// when a trace gets deleted, make sure that its module's | ||
// plot method is called so that it is properly | ||
// removed from the DOM. | ||
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. 👏 Yes. |
||
for(i = 0; i < moduleNamesOld.length; i++) { | ||
var moduleName = moduleNamesOld[i]; | ||
|
||
if(moduleNames.indexOf(moduleName) === -1) { | ||
var fakeCalcTrace = traceHashOld[moduleName][0], | ||
fakeTrace = fakeCalcTrace[0].trace; | ||
|
||
fakeTrace.visible = false; | ||
traceHash[moduleName] = [fakeCalcTrace]; | ||
} | ||
} | ||
|
||
// update list of module names to include 'fake' traces added above | ||
moduleNames = Object.keys(traceHash); | ||
|
||
// call module plot method | ||
for(i = 0; i < moduleNames.length; i++) { | ||
var moduleCalcData = traceHash[moduleNames[i]], | ||
_module = moduleCalcData[0][0].trace._module; | ||
|
||
_module.plot(subplot, filterVisible(moduleCalcData), subplotLayout); | ||
} | ||
|
||
// update moduleName -> calcData hash | ||
subplot.traceHash = traceHash; | ||
}; |
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.
Lots of trace-specific code moved elsewhere. I like it already. 👏