Skip to content

Finance trace editable legend fix #1349

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

Merged
merged 3 commits into from
Feb 2, 2017
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
2 changes: 1 addition & 1 deletion src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ function drawTexts(g, gd) {
var transforms = legendItem.trace.transforms,
direction = transforms[transforms.length - 1].direction;

astr = direction + '.legenditem.name';
astr = direction + '.name';
}
else astr = 'name';

Expand Down
84 changes: 84 additions & 0 deletions test/jasmine/tests/finance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,3 +963,87 @@ describe('finance charts updates:', function() {
});
});
});

describe('finance charts *special* handlers:', function() {

afterEach(destroyGraphDiv);

it('`editable: true` handlers should work', function(done) {

var gd = createGraphDiv();

function editText(itemNumber, newText) {
var textNode = d3.selectAll('text.legendtext')
.filter(function(_, i) { return i === itemNumber; }).node();
textNode.dispatchEvent(new window.MouseEvent('click'));

var editNode = d3.select('.plugin-editable.editable').node();
editNode.dispatchEvent(new window.FocusEvent('focus'));

editNode.textContent = newText;
editNode.dispatchEvent(new window.FocusEvent('focus'));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which is used to invoke the makeEditable handlers.

editNode.dispatchEvent(new window.FocusEvent('blur'));
}

// makeEditable in svg_text_utils clears the edit <div> in
// a 0-second transition, so push the resolve call at the back
// of the rendering queue to make sure the edit <div> is properly
// cleared after each mocked text edits.
function delayedResolve(resolve) {
setTimeout(function() { return resolve(gd); }, 0);
}

Plotly.plot(gd, [
Lib.extendDeep({}, mock0, { type: 'ohlc' }),
Lib.extendDeep({}, mock0, { type: 'candlestick' })
], {}, {
editable: true
})
.then(function(gd) {
return new Promise(function(resolve) {
gd.once('plotly_restyle', function(eventData) {
expect(eventData[0]['increasing.name']).toEqual('0');
expect(eventData[1]).toEqual([0]);
delayedResolve(resolve);
});

editText(0, '0');
});
})
.then(function(gd) {
return new Promise(function(resolve) {
gd.once('plotly_restyle', function(eventData) {
expect(eventData[0]['decreasing.name']).toEqual('1');
expect(eventData[1]).toEqual([0]);
delayedResolve(resolve);
});

editText(1, '1');
});
})
.then(function(gd) {
return new Promise(function(resolve) {
gd.once('plotly_restyle', function(eventData) {
expect(eventData[0]['decreasing.name']).toEqual('2');
expect(eventData[1]).toEqual([1]);
delayedResolve(resolve);
});

editText(3, '2');
});
})
.then(function(gd) {
return new Promise(function(resolve) {
gd.once('plotly_restyle', function(eventData) {
expect(eventData[0]['increasing.name']).toEqual('3');
expect(eventData[1]).toEqual([1]);
delayedResolve(resolve);
});

editText(2, '3');
});
})
.then(done);
});

});