-
-
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 5 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 |
---|---|---|
|
@@ -100,22 +100,58 @@ 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; | ||
} | ||
} | ||
}; | ||
|
||
exports.appendArrayPointValues = 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 = { | ||
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. ✨ at some point we might want to move this to the attribute declarations. |
||
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 |
---|---|---|
|
@@ -155,7 +155,7 @@ exports.loneHover = function loneHover(hoverItem, opts) { | |
|
||
// The actual implementation is here: | ||
function _hover(gd, evt, subplot, noHoverEvent) { | ||
if((subplot === 'pie' || subplot === 'sankey') && !noHoverEvent) { | ||
if(subplot === 'sankey' && !noHoverEvent) { | ||
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 couldn't see any purpose to having pie call 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. simplified sankey -> e08e37a 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. e08e37a is very nice. 👌 |
||
gd.emit('plotly_hover', { | ||
event: evt.originalEvent, | ||
points: [evt] | ||
|
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'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright 2012-2017, 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 appendArrayPointValues = require('../../components/fx/helpers').appendArrayPointValues; | ||
|
||
|
||
// Note: like other eventData routines, this creates the data for hover/unhover/click events | ||
// but it has a different API and goes through a totally different pathway. | ||
// So to ensure it doesn't get misused, it's not attached to the Pie module. | ||
module.exports = function eventData(pt, trace) { | ||
var out = { | ||
curveNumber: trace.index, | ||
pointNumbers: pt.pts, | ||
data: trace._input, | ||
fullData: trace, | ||
label: pt.label, | ||
color: pt.color, | ||
value: pt.v, | ||
|
||
// pt.v (and pt.i below) for backward compatibility | ||
v: pt.v | ||
}; | ||
|
||
// Only include pointNumber if it's unambiguous | ||
if(pt.pts.length === 1) out.pointNumber = out.i = pt.pts[0]; | ||
|
||
// Add extra data arrays to the output | ||
// notice that this is the multi-point version ('s' on the end!) | ||
// so added data will be arrays matching the pointNumbers array. | ||
appendArrayPointValues(out, trace, pt.pts); | ||
|
||
return out; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,16 @@ exports.formatPieValue = function formatPieValue(v, separators) { | |
} | ||
return Lib.numSeparate(vRounded, separators); | ||
}; | ||
|
||
exports.getFirstFilled = function getFirstFilled(array, indices) { | ||
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 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. Picking the first non-empty item is fine 👍 |
||
if(!Array.isArray(array)) return; | ||
for(var i = 0; i < indices.length; i++) { | ||
var v = array[indices[i]]; | ||
if(v || v === 0) return v; | ||
} | ||
}; | ||
|
||
exports.castOption = function castOption(item, indices) { | ||
if(Array.isArray(item)) return exports.getFirstFilled(item, indices); | ||
else if(item) return item; | ||
}; |
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.
Maybe
appendArrayMultiPointValue
orappendArrayMultiPointValues
would more typo-proof.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.
... and please add jsDOC⤴️
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 on
appendArrayMultiPointValues
-> with docs in4ba0249