-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b3e25ac
fix jsdoc for Plots.getSubplotData
etpinard 447abec
shorten parts to cartesian modules in geo.js
etpinard fe8a3f9
simplify subplot creation if-statement
etpinard 92119bb
rm (now useless) logic for ternary make plot framework
etpinard a7cca2e
move getSubplotCalcdata method into Plots
etpinard fc0af0c
add generalUpdatePerTraceModule method in Plots
etpinard bfb05d4
make ternary use getSubplotCalcData & generalUpdatePerTraceModule
etpinard 83c2722
replace unnecessary `=== undefined` check in Plots
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ plots.hasSimpleAPICommandBindings = commandModule.hasSimpleAPICommandBindings; | |
plots.findSubplotIds = function findSubplotIds(data, type) { | ||
var subplotIds = []; | ||
|
||
if(plots.subplotsRegistry[type] === undefined) return subplotIds; | ||
if(!plots.subplotsRegistry[type]) return subplotIds; | ||
|
||
var attr = plots.subplotsRegistry[type].attr; | ||
|
||
|
@@ -90,7 +90,7 @@ plots.findSubplotIds = function findSubplotIds(data, type) { | |
plots.getSubplotIds = function getSubplotIds(layout, type) { | ||
var _module = plots.subplotsRegistry[type]; | ||
|
||
if(_module === undefined) return []; | ||
if(!_module) return []; | ||
|
||
// layout must be 'fullLayout' here | ||
if(type === 'cartesian' && (!layout._has || !layout._has('cartesian'))) return []; | ||
|
@@ -124,14 +124,14 @@ 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. | ||
* | ||
*/ | ||
plots.getSubplotData = function getSubplotData(data, type, subplotId) { | ||
if(plots.subplotsRegistry[type] === undefined) return []; | ||
if(!plots.subplotsRegistry[type]) return []; | ||
|
||
var attr = plots.subplotsRegistry[type].attr, | ||
subplotData = [], | ||
|
@@ -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]) return []; | ||
|
||
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; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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. 👏