Skip to content

Commit 3a984a2

Browse files
committed
wip
1 parent 1c2e71e commit 3a984a2

File tree

17 files changed

+113
-64
lines changed

17 files changed

+113
-64
lines changed

src/components/fx/helpers.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function quadrature(dx, dy) {
8787

8888
/** Appends values inside array attributes corresponding to given point number
8989
*
90-
* @param {object} pointData : point data object (gets mutated here
90+
* @param {object} pointData : point data object (gets mutated here)
9191
* @param {object} trace : full trace object
9292
* @param {number} ptNumber : point number
9393
*/
@@ -99,11 +99,14 @@ exports.appendArrayPointValue = function(pointData, trace, ptNumber) {
9999
var key;
100100

101101
if(astr === 'ids') key = 'id';
102-
else if(astr === 'location') key = 'location';
102+
else if(astr === 'locations') key = 'location';
103103
else key = astr;
104104

105105
if(pointData[key] === undefined) {
106-
pointData[key] = Lib.nestedProperty(trace, astr).get()[ptNumber];
106+
var val = Lib.nestedProperty(trace, astr).get();
107+
pointData[key] = Array.isArray(ptNumber) ?
108+
val[ptNumber[0]][ptNumber[1]] :
109+
val[ptNumber];
107110
}
108111
}
109112
};

src/components/fx/hover.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,17 @@ function _hover(gd, evt, subplot) {
447447
pointNumber: pt.index
448448
};
449449

450-
// could maybe :hocho: _module.eventData
451450
if(pt.trace._module.eventData) out = pt.trace._module.eventData(out, pt);
452451
else {
453452
out.x = pt.xVal;
454453
out.y = pt.yVal;
455-
456454
out.xaxis = pt.xa;
457455
out.yaxis = pt.ya;
458456

459457
if(pt.zLabelVal !== undefined) out.z = pt.zLabelVal;
460458
}
461459

462-
helpers.appendArrayPointValue(out, trace, pt.index);
460+
helpers.appendArrayPointValue(out, pt.trace, pt.index);
463461
newhoverdata.push(out);
464462
}
465463

src/plot_api/plot_schema.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ exports.findArrayAttributes = function(trace) {
157157
}
158158

159159
exports.crawl(baseAttributes, callback);
160-
exports.crawl(trace._module.attributes, callback);
160+
if(trace._module && trace._module.attributes) {
161+
exports.crawl(trace._module.attributes, callback);
162+
}
161163

162164
if(trace.transforms) {
163165
var transforms = trace.transforms;
@@ -177,9 +179,8 @@ exports.findArrayAttributes = function(trace) {
177179
// At the moment, we need this block to make sure that
178180
// ohlc and candlestick 'open', 'high', 'low', 'close' can be
179181
// used with filter ang groupby transforms.
180-
if(trace._fullInput) {
182+
if(trace._fullInput && trace._fullInput._module && trace._fullInput._module.attributes) {
181183
exports.crawl(trace._fullInput._module.attributes, callback);
182-
183184
arrayAttributes = Lib.filterUnique(arrayAttributes);
184185
}
185186

src/plots/attributes.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ module.exports = {
6969
role: 'info',
7070
dflt: ''
7171
},
72+
ids: {
73+
valType: 'data_array',
74+
description: [
75+
'Assigns id labels to each datum.',
76+
'These ids for object constancy of data points during animation.'
77+
].join(' ')
78+
},
79+
customdata: {
80+
valType: 'data_array',
81+
description: [
82+
'Assigns extra data each datum.',
83+
'This may be useful when listening to hover, click and selection events.',
84+
'Note that, *scatter* traces also appends customdata items in the markers',
85+
'DOM elements'
86+
].join(' ')
87+
},
7288
hoverinfo: {
7389
valType: 'flaglist',
7490
role: 'info',

src/plots/cartesian/select.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
var polygon = require('../../lib/polygon');
1313
var color = require('../../components/color');
14+
var appendArrayPointValue = require('../../components/fx/helpers').appendArrayPointValue;
1415

1516
var axes = require('./axes');
1617
var constants = require('./constants');
@@ -196,3 +197,7 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
196197
}
197198
};
198199
};
200+
201+
function makePointData(selection) {
202+
// appendArrayPointValue()
203+
}

src/plots/gl3d/scene.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function render(scene) {
112112
pointNumber: ptNumber
113113
};
114114

115-
Fx.appendArrayPointValue(pointData);
115+
Fx.appendArrayPointValue(pointData, trace, ptNumber);
116116

117117
var eventData = {points: [pointData]};
118118

src/plots/plots.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ plots.supplyDefaults = function(gd) {
521521

522522
function remapTransformedArrays(cd0, newTrace) {
523523
var oldTrace = cd0.trace;
524-
var arrayAttrs = PlotSchema.findArrayAttributes(oldTrace);
524+
var arrayAttrs = oldTrace._arrayAttrs;
525525
var transformedArrayHash = {};
526526
var i, astr;
527527

@@ -676,9 +676,6 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
676676
Lib.pushUnique(modules, _module);
677677
Lib.pushUnique(basePlotModules, fullTrace._module.basePlotModule);
678678

679-
// TODO remove findArrayAttributes calls downstream
680-
fullTrace._arrayAttrs = PlotSchema.findArrayAttributes(fullTrace);
681-
682679
cnt++;
683680
}
684681

@@ -865,6 +862,9 @@ plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInInde
865862
}
866863

867864
if(visible) {
865+
coerce('customdata');
866+
coerce('ids');
867+
868868
var _module = plots.getModule(traceOut);
869869
traceOut._module = _module;
870870

@@ -2035,6 +2035,12 @@ plots.doCalcdata = function(gd, traces) {
20352035
}
20362036
}
20372037

2038+
// find array attributes in trace
2039+
for(i = 0; i < fullData.length; i++) {
2040+
trace = fullData[i];
2041+
trace._arrayAttrs = PlotSchema.findArrayAttributes(trace);
2042+
}
2043+
20382044
initCategories(axList);
20392045

20402046
var hasCalcTransform = false;

src/traces/scatter/attributes.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ module.exports = {
5757
'where `y0` is the starting coordinate and `dy` the step.'
5858
].join(' ')
5959
},
60-
customdata: {
61-
valType: 'data_array',
62-
description: 'Assigns extra data to each scatter point DOM element'
63-
},
6460
dy: {
6561
valType: 'number',
6662
dflt: 1,
@@ -70,10 +66,6 @@ module.exports = {
7066
'See `y0` for more info.'
7167
].join(' ')
7268
},
73-
ids: {
74-
valType: 'data_array',
75-
description: 'A list of keys for object constancy of data points during animation'
76-
},
7769
text: {
7870
valType: 'string',
7971
role: 'info',

src/traces/scatter/defaults.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3636
return;
3737
}
3838

39-
coerce('customdata');
4039
coerce('text');
4140
coerce('hovertext');
4241
coerce('mode', defaultMode);
43-
coerce('ids');
4442

4543
if(subTypes.hasLines(traceOut)) {
4644
handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);

src/transforms/filter.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var Lib = require('../lib');
1212
var Registry = require('../registry');
13-
var PlotSchema = require('../plot_api/plot_schema');
1413
var Axes = require('../plots/cartesian/axes');
1514

1615
var COMPARISON_OPS = ['=', '!=', '<', '>=', '>', '<='];
@@ -148,6 +147,7 @@ exports.calcTransform = function(gd, trace, opts) {
148147
var target = opts.target;
149148
var len = targetArray.length;
150149
var targetCalendar = opts.targetcalendar;
150+
var arrayAttrs = trace._arrayAttrs;
151151

152152
// even if you provide targetcalendar, if target is a string and there
153153
// is a calendar attribute matching target it will get used instead.
@@ -158,7 +158,6 @@ exports.calcTransform = function(gd, trace, opts) {
158158

159159
var d2c = Axes.getDataToCoordFunc(gd, trace, target, targetArray);
160160
var filterFunc = getFilterFunc(opts, d2c, targetCalendar);
161-
var arrayAttrs = PlotSchema.findArrayAttributes(trace);
162161
var originalArrays = {};
163162

164163
function forAllAttrs(fn, index) {

0 commit comments

Comments
 (0)