Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/components/fx/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ exports.appendArrayPointValue = function(pointData, trace, pointNumber) {

if(pointData[key] === undefined) {
var val = Lib.nestedProperty(trace, astr).get();
pointData[key] = Array.isArray(pointNumber) ?
val[pointNumber[0]][pointNumber[1]] :
val[pointNumber];

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];
}
}
}
};
18 changes: 15 additions & 3 deletions src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,25 @@ exports.isValObject = function(obj) {
* list of array attributes for the given trace
*/
exports.findArrayAttributes = function(trace) {
var arrayAttributes = [],
stack = [];
var arrayAttributes = [];
var stack = [];

function callback(attr, attrName, attrs, level) {
stack = stack.slice(0, level).concat([attrName]);

var splittableAttr = attr && (attr.valType === 'data_array' || attr.arrayOk === true);
var splittableAttr = (
attr &&
(attr.valType === 'data_array' || attr.arrayOk === true) &&
!(stack[level - 1] === 'colorbar' && (attrName === 'ticktext' || attrName === 'tickvals'))
);

// Manually exclude 'colorbar.tickvals' and 'colorbar.ticktext' for now
// which are declared as `valType: 'data_array'` but scale independently of
// the coordinate arrays.
//
// Down the road, we might want to add a schema field (e.g `uncorrelatedArray: true`)
// to distinguish attributes of the likes.

if(!splittableAttr) return;

var astr = toAttrString(stack);
Expand Down
80 changes: 80 additions & 0 deletions test/jasmine/tests/cartesian_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,83 @@ describe('axis zoom/pan and main plot zoom', function() {
.then(done);
});
});

describe('Event data:', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

function _hover(px, py) {
return new Promise(function(resolve, reject) {
gd.once('plotly_hover', function(d) {
delete gd._lastHoverTime;
resolve(d);
});

mouseEvent('mousemove', px, py);

setTimeout(function() {
reject('plotly_hover did not get called!');
}, 100);
});
}

it('should have correct content for *scatter* traces', function(done) {
Plotly.plot(gd, [{
y: [1, 2, 1],
marker: {
color: [20, 30, 10],
colorbar: {
tickvals: [25],
ticktext: ['one single tick']
}
}
}], {
width: 500,
height: 500
})
.then(function() { return _hover(200, 200); })
.then(function(d) {
var pt = d.points[0];

expect(pt.y).toBe(2, 'y');
expect(pt['marker.color']).toBe(30, 'marker.color');
expect('marker.colorbar.tickvals' in pt).toBe(false, 'marker.colorbar.tickvals');
expect('marker.colorbar.ticktext' in pt).toBe(false, 'marker.colorbar.ticktext');
})
.catch(fail)
.then(done);
});

it('should have correct content for *heatmap* traces', function(done) {
Plotly.plot(gd, [{
type: 'heatmap',
z: [[1, 2, 1], [2, 3, 1]],
colorbar: {
tickvals: [2],
ticktext: ['one single tick']
},
text: [['incomplete array']],
ids: [['incomplete array']]
}], {
width: 500,
height: 500
})
.then(function() { return _hover(200, 200); })
.then(function(d) {
var pt = d.points[0];

expect(pt.z).toBe(3, 'z');
expect(pt.text).toBe(undefined, 'undefined text items are included');
expect('id' in pt).toBe(false, 'undefined ids items are not included');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B. this 🔒 0d91074

expect('marker.colorbar.tickvals' in pt).toBe(false, 'marker.colorbar.tickvals');
expect('marker.colorbar.ticktext' in pt).toBe(false, 'marker.colorbar.ticktext');
})
.catch(fail)
.then(done);
});
});
14 changes: 14 additions & 0 deletions test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ describe('Test gl3d plots', function() {

expect(label.size()).toEqual(1);
expect(label.select('text').text()).toEqual('2');

return Plotly.restyle(gd, {
'colorbar.tickvals': [[25]],
'colorbar.ticktext': [['single tick!']]
});
})
.then(_hover)
.then(function() {
assertEventData(1, 2, 43, 0, [1, 2], {
'hoverinfo': 'y',
'hoverlabel.font.color': 'cyan',
'colorbar.tickvals': undefined,
'colorbar.ticktext': undefined
});
})
.then(done);
});
Expand Down