Skip to content

Commit ab30f93

Browse files
committed
Merge branch 'master' into scattergl-lasso
2 parents 27811d6 + ffb3791 commit ab30f93

File tree

24 files changed

+232
-92
lines changed

24 files changed

+232
-92
lines changed

src/components/annotations/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
237237
// at the end, even if their position changes
238238
annText.selectAll('tspan.line').attr({y: 0, x: 0});
239239

240-
var mathjaxGroup = annTextGroupInner.select('.annotation-math-group');
240+
var mathjaxGroup = annTextGroupInner.select('.annotation-text-math-group');
241241
var hasMathjax = !mathjaxGroup.empty();
242242
var anntextBB = Drawing.bBox(
243243
(hasMathjax ? mathjaxGroup : annText).node());

src/components/fx/helpers.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
'use strict';
1010

11+
var Lib = require('../../lib');
1112
var constants = require('./constants');
1213

1314
// look for either subplot or xaxis and yaxis attributes
@@ -83,3 +84,29 @@ function quadrature(dx, dy) {
8384
return Math.sqrt(x * x + y * y);
8485
};
8586
}
87+
88+
/** Appends values inside array attributes corresponding to given point number
89+
*
90+
* @param {object} pointData : point data object (gets mutated here)
91+
* @param {object} trace : full trace object
92+
* @param {number} pointNumber : point number
93+
*/
94+
exports.appendArrayPointValue = function(pointData, trace, pointNumber) {
95+
var arrayAttrs = trace._arrayAttrs;
96+
97+
for(var i = 0; i < arrayAttrs.length; i++) {
98+
var astr = arrayAttrs[i];
99+
var key;
100+
101+
if(astr === 'ids') key = 'id';
102+
else if(astr === 'locations') key = 'location';
103+
else key = astr;
104+
105+
if(pointData[key] === undefined) {
106+
var val = Lib.nestedProperty(trace, astr).get();
107+
pointData[key] = Array.isArray(pointNumber) ?
108+
val[pointNumber[0]][pointNumber[1]] :
109+
val[pointNumber];
110+
}
111+
}
112+
};

src/components/fx/hover.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ function _hover(gd, evt, subplot) {
457457
if(pt.zLabelVal !== undefined) out.z = pt.zLabelVal;
458458
}
459459

460+
helpers.appendArrayPointValue(out, pt.trace, pt.index);
460461
newhoverdata.push(out);
461462
}
462463

src/components/fx/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
getDistanceFunction: helpers.getDistanceFunction,
3636
getClosest: helpers.getClosest,
3737
inbox: helpers.inbox,
38+
appendArrayPointValue: helpers.appendArrayPointValue,
3839

3940
castHoverOption: castHoverOption,
4041
castHoverinfo: castHoverinfo,

src/lib/svg_text_utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ exports.convertToTspans = function(_context, gd, _callback) {
3030

3131
// Until we get tex integrated more fully (so it can be used along with non-tex)
3232
// allow some elements to prohibit it by attaching 'data-notex' to the original
33-
var tex = (!_context.attr('data-notex')) && str.match(FIND_TEX);
33+
var tex = (!_context.attr('data-notex')) &&
34+
(typeof MathJax !== 'undefined') &&
35+
str.match(FIND_TEX);
36+
3437
var parent = d3.select(_context.node().parentNode);
3538
if(parent.empty()) return;
3639
var svgClass = (_context.attr('class')) ? _context.attr('class').split(' ')[0] : 'text';

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/dragbox.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var setCursor = require('../../lib/setcursor');
2222
var dragElement = require('../../components/dragelement');
2323
var FROM_TL = require('../../constants/alignment').FROM_TL;
2424

25+
var Plots = require('../plots');
26+
2527
var doTicks = require('./axes').doTicks;
2628
var getFromId = require('./axis_ids').getFromId;
2729
var prepSelect = require('./select');
@@ -655,7 +657,13 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
655657
// be repositioning the data in the relayout. But DON'T call
656658
// ticksAndAnnotations again - it's unnecessary and would overwrite `updates`
657659
updateSubplots([0, 0, pw, ph]);
658-
Plotly.relayout(gd, updates);
660+
661+
// since we may have been redrawing some things during the drag, we may have
662+
// accumulated MathJax promises - wait for them before we relayout.
663+
Lib.syncOrAsync([
664+
Plots.previousPromises,
665+
function() { Plotly.relayout(gd, updates); }
666+
], gd);
659667
}
660668

661669
// updateSubplots - find all plot viewboxes that should be

src/plots/cartesian/select.js

Lines changed: 21 additions & 1 deletion
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');
@@ -151,7 +152,9 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
151152
selection = [];
152153
for(i = 0; i < searchTraces.length; i++) {
153154
searchInfo = searchTraces[i];
154-
[].push.apply(selection, searchInfo.selectPoints(searchInfo, poly));
155+
[].push.apply(selection, fillSelectionItem(
156+
searchInfo.selectPoints(searchInfo, poly), searchInfo
157+
));
155158
}
156159

157160
eventData = {points: selection};
@@ -196,3 +199,20 @@ module.exports = function prepSelect(e, startX, startY, dragOptions, mode) {
196199
}
197200
};
198201
};
202+
203+
function fillSelectionItem(selection, searchInfo) {
204+
if(Array.isArray(selection)) {
205+
var trace = searchInfo.cd[0].trace;
206+
207+
for(var i = 0; i < selection.length; i++) {
208+
var sel = selection[i];
209+
210+
sel.curveNumber = trace.index;
211+
sel.data = trace._input;
212+
sel.fullData = trace;
213+
appendArrayPointValue(sel, trace, sel.pointNumber);
214+
}
215+
}
216+
217+
return selection;
218+
}

src/plots/gl2d/scene2d.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ proto.updateFx = function(dragmode) {
534534

535535
proto.emitPointAction = function(nextSelection, eventType) {
536536
var uid = nextSelection.trace.uid;
537+
var ptNumber = nextSelection.pointIndex;
537538
var trace;
538539

539540
for(var i = 0; i < this.fullData.length; i++) {
@@ -542,18 +543,20 @@ proto.emitPointAction = function(nextSelection, eventType) {
542543
}
543544
}
544545

545-
this.graphDiv.emit(eventType, {
546-
points: [{
547-
x: nextSelection.traceCoord[0],
548-
y: nextSelection.traceCoord[1],
549-
curveNumber: trace.index,
550-
pointNumber: nextSelection.pointIndex,
551-
data: trace._input,
552-
fullData: this.fullData,
553-
xaxis: this.xaxis,
554-
yaxis: this.yaxis
555-
}]
556-
});
546+
var pointData = {
547+
x: nextSelection.traceCoord[0],
548+
y: nextSelection.traceCoord[1],
549+
curveNumber: trace.index,
550+
pointNumber: ptNumber,
551+
data: trace._input,
552+
fullData: this.fullData,
553+
xaxis: this.xaxis,
554+
yaxis: this.yaxis
555+
};
556+
557+
Fx.appendArrayPointValue(pointData, trace, ptNumber);
558+
559+
this.graphDiv.emit(eventType, {points: [pointData]});
557560
};
558561

559562
proto.draw = function() {

0 commit comments

Comments
 (0)