Skip to content

Commit 4695758

Browse files
authored
Merge pull request #1349 from plotly/finance-legend-fix
Finance trace editable legend fix
2 parents 80fb6a2 + 690b9f7 commit 4695758

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/components/legend/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function drawTexts(g, gd) {
384384
var transforms = legendItem.trace.transforms,
385385
direction = transforms[transforms.length - 1].direction;
386386

387-
astr = direction + '.legenditem.name';
387+
astr = direction + '.name';
388388
}
389389
else astr = 'name';
390390

test/jasmine/tests/finance_test.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,3 +1003,87 @@ describe('finance charts updates:', function() {
10031003
});
10041004

10051005
});
1006+
1007+
describe('finance charts *special* handlers:', function() {
1008+
1009+
afterEach(destroyGraphDiv);
1010+
1011+
it('`editable: true` handlers should work', function(done) {
1012+
1013+
var gd = createGraphDiv();
1014+
1015+
function editText(itemNumber, newText) {
1016+
var textNode = d3.selectAll('text.legendtext')
1017+
.filter(function(_, i) { return i === itemNumber; }).node();
1018+
textNode.dispatchEvent(new window.MouseEvent('click'));
1019+
1020+
var editNode = d3.select('.plugin-editable.editable').node();
1021+
editNode.dispatchEvent(new window.FocusEvent('focus'));
1022+
1023+
editNode.textContent = newText;
1024+
editNode.dispatchEvent(new window.FocusEvent('focus'));
1025+
editNode.dispatchEvent(new window.FocusEvent('blur'));
1026+
}
1027+
1028+
// makeEditable in svg_text_utils clears the edit <div> in
1029+
// a 0-second transition, so push the resolve call at the back
1030+
// of the rendering queue to make sure the edit <div> is properly
1031+
// cleared after each mocked text edits.
1032+
function delayedResolve(resolve) {
1033+
setTimeout(function() { return resolve(gd); }, 0);
1034+
}
1035+
1036+
Plotly.plot(gd, [
1037+
Lib.extendDeep({}, mock0, { type: 'ohlc' }),
1038+
Lib.extendDeep({}, mock0, { type: 'candlestick' })
1039+
], {}, {
1040+
editable: true
1041+
})
1042+
.then(function(gd) {
1043+
return new Promise(function(resolve) {
1044+
gd.once('plotly_restyle', function(eventData) {
1045+
expect(eventData[0]['increasing.name']).toEqual('0');
1046+
expect(eventData[1]).toEqual([0]);
1047+
delayedResolve(resolve);
1048+
});
1049+
1050+
editText(0, '0');
1051+
});
1052+
})
1053+
.then(function(gd) {
1054+
return new Promise(function(resolve) {
1055+
gd.once('plotly_restyle', function(eventData) {
1056+
expect(eventData[0]['decreasing.name']).toEqual('1');
1057+
expect(eventData[1]).toEqual([0]);
1058+
delayedResolve(resolve);
1059+
});
1060+
1061+
editText(1, '1');
1062+
});
1063+
})
1064+
.then(function(gd) {
1065+
return new Promise(function(resolve) {
1066+
gd.once('plotly_restyle', function(eventData) {
1067+
expect(eventData[0]['decreasing.name']).toEqual('2');
1068+
expect(eventData[1]).toEqual([1]);
1069+
delayedResolve(resolve);
1070+
});
1071+
1072+
editText(3, '2');
1073+
});
1074+
})
1075+
.then(function(gd) {
1076+
return new Promise(function(resolve) {
1077+
gd.once('plotly_restyle', function(eventData) {
1078+
expect(eventData[0]['increasing.name']).toEqual('3');
1079+
expect(eventData[1]).toEqual([1]);
1080+
delayedResolve(resolve);
1081+
});
1082+
1083+
editText(2, '3');
1084+
});
1085+
})
1086+
.then(done);
1087+
});
1088+
1089+
});

0 commit comments

Comments
 (0)