-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Pie aggregation and event cleanup #2117
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 all commits
679ed9c
ce8946c
d2756f1
ebc4d8b
5d0f3e2
e08e37a
4ba0249
ee1f8c4
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 |
---|---|---|
|
@@ -89,7 +89,8 @@ exports.quadrature = function quadrature(dx, dy) { | |
* | ||
* @param {object} pointData : point data object (gets mutated here) | ||
* @param {object} trace : full trace object | ||
* @param {number} pointNumber : point number | ||
* @param {number|Array(number)} pointNumber : point number. May be a length-2 array | ||
* [row, col] to dig into 2D arrays | ||
*/ | ||
exports.appendArrayPointValue = function(pointData, trace, pointNumber) { | ||
var arrayAttrs = trace._arrayAttrs; | ||
|
@@ -100,22 +101,68 @@ exports.appendArrayPointValue = function(pointData, trace, pointNumber) { | |
|
||
for(var i = 0; i < arrayAttrs.length; i++) { | ||
var astr = arrayAttrs[i]; | ||
var key; | ||
var key = getPointKey(astr); | ||
|
||
if(astr === 'ids') key = 'id'; | ||
else if(astr === 'locations') key = 'location'; | ||
else key = astr; | ||
if(pointData[key] === undefined) { | ||
var val = Lib.nestedProperty(trace, astr).get(); | ||
var pointVal = getPointData(val, pointNumber); | ||
|
||
if(pointVal !== undefined) pointData[key] = pointVal; | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Appends values inside array attributes corresponding to given point number array | ||
* For use when pointData references a plot entity that arose (or potentially arose) | ||
* from multiple points in the input data | ||
* | ||
* @param {object} pointData : point data object (gets mutated here) | ||
* @param {object} trace : full trace object | ||
* @param {Array(number)|Array(Array(number))} pointNumbers : Array of point numbers. | ||
* Each entry in the array may itself be a length-2 array [row, col] to dig into 2D arrays | ||
*/ | ||
exports.appendArrayMultiPointValues = function(pointData, trace, pointNumbers) { | ||
var arrayAttrs = trace._arrayAttrs; | ||
|
||
if(!arrayAttrs) { | ||
return; | ||
} | ||
|
||
for(var i = 0; i < arrayAttrs.length; i++) { | ||
var astr = arrayAttrs[i]; | ||
var key = getPointKey(astr); | ||
|
||
if(pointData[key] === undefined) { | ||
var val = Lib.nestedProperty(trace, astr).get(); | ||
var keyVal = new Array(pointNumbers.length); | ||
|
||
if(Array.isArray(pointNumber)) { | ||
if(Array.isArray(val) && Array.isArray(val[pointNumber[0]])) { | ||
pointData[key] = val[pointNumber[0]][pointNumber[1]]; | ||
} | ||
} else { | ||
pointData[key] = val[pointNumber]; | ||
for(var j = 0; j < pointNumbers.length; j++) { | ||
keyVal[j] = getPointData(val, pointNumbers[j]); | ||
} | ||
pointData[key] = keyVal; | ||
} | ||
} | ||
}; | ||
|
||
var pointKeyMap = { | ||
ids: 'id', | ||
locations: 'location', | ||
labels: 'label', | ||
values: 'value', | ||
'marker.colors': 'color' | ||
}; | ||
|
||
function getPointKey(astr) { | ||
return pointKeyMap[astr] || astr; | ||
} | ||
|
||
function getPointData(val, pointNumber) { | ||
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. This thing is very similar to 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. For the multipoint case it's nice to keep the 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. Right, it might be nice to move |
||
if(Array.isArray(pointNumber)) { | ||
if(Array.isArray(val) && Array.isArray(val[pointNumber[0]])) { | ||
return val[pointNumber[0]][pointNumber[1]]; | ||
} | ||
} else { | ||
return val[pointNumber]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,14 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout | |
var coerceFont = Lib.coerceFont; | ||
|
||
var vals = coerce('values'); | ||
if(!Array.isArray(vals) || !vals.length) { | ||
traceOut.visible = false; | ||
return; | ||
} | ||
|
||
var labels = coerce('labels'); | ||
if(!Array.isArray(labels)) { | ||
if(!Array.isArray(vals) || !vals.length) { | ||
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. Blocking: Would you mind locking this down in a jasmine test? 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. sure -> ee1f8c4 |
||
// must have at least one of vals or labels | ||
traceOut.visible = false; | ||
return; | ||
} | ||
|
||
coerce('label0'); | ||
coerce('dlabel'); | ||
} | ||
|
@@ -34,14 +35,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout | |
if(lineWidth) coerce('marker.line.color'); | ||
|
||
var colors = coerce('marker.colors'); | ||
if(!Array.isArray(colors)) traceOut.marker.colors = []; // later this will get padded with default colors | ||
if(!Array.isArray(colors)) traceOut.marker.colors = []; | ||
|
||
coerce('scalegroup'); | ||
// TODO: tilt, depth, and hole all need to be coerced to the same values within a scaleegroup | ||
// (ideally actually, depth would get set the same *after* scaling, ie the same absolute depth) | ||
// and if colors aren't specified we should match these up - potentially even if separate pies | ||
// are NOT in the same sharegroup | ||
|
||
// TODO: hole needs to be coerced to the same value within a scaleegroup | ||
|
||
var textData = coerce('text'); | ||
var textInfo = coerce('textinfo', Array.isArray(textData) ? 'text+percent' : 'percent'); | ||
|
@@ -63,14 +60,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout | |
coerce('domain.x'); | ||
coerce('domain.y'); | ||
|
||
// 3D attributes commented out until I finish them in a later PR | ||
// var tilt = coerce('tilt'); | ||
// if(tilt) { | ||
// coerce('tiltaxis'); | ||
// coerce('depth'); | ||
// coerce('shading'); | ||
// } | ||
|
||
coerce('hole'); | ||
|
||
coerce('sort'); | ||
|
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.
✨ at some point we might want to move this to the attribute declarations.