Skip to content

Use trace gd.data index to determine dflt trace name #1073

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 2 commits into from
Oct 26, 2016
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
10 changes: 5 additions & 5 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {

for(var i = 0; i < dataIn.length; i++) {
var trace = dataIn[i],
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout);
fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout, i);

fullTrace.index = i;
fullTrace._input = trace;
Expand All @@ -623,7 +623,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {

for(var j = 0; j < expandedTraces.length; j++) {
var expandedTrace = expandedTraces[j],
fullExpandedTrace = plots.supplyTraceDefaults(expandedTrace, cnt, fullLayout);
fullExpandedTrace = plots.supplyTraceDefaults(expandedTrace, cnt, fullLayout, i);

// mutate uid here using parent uid and expanded index
// to promote consistency between update calls
Expand Down Expand Up @@ -722,9 +722,9 @@ plots.supplyFrameDefaults = function(frameIn) {
return frameOut;
};

plots.supplyTraceDefaults = function(traceIn, traceIndex, layout) {
plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInIndex) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the odd call signature is to not break to toolpanel code:

image

var traceOut = {},
defaultColor = Color.defaults[traceIndex % Color.defaults.length];
defaultColor = Color.defaults[traceOutIndex % Color.defaults.length];

function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, plots.attributes, attr, dflt);
Expand All @@ -741,7 +741,7 @@ plots.supplyTraceDefaults = function(traceIn, traceIndex, layout) {

coerce('type');
coerce('uid');
coerce('name', 'trace ' + traceIndex);
coerce('name', 'trace ' + traceInIndex);

// coerce subplot attributes of all registered subplot types
var subplotTypes = Object.keys(subplotsRegistry);
Expand Down
29 changes: 29 additions & 0 deletions test/jasmine/tests/finance_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,35 @@ describe('finance charts defaults:', function() {
]);
});

it('trace *name* default should make reference to user data trace indices', function() {
var trace0 = Lib.extendDeep({}, mock0, {
type: 'ohlc'
});

var trace1 = { type: 'scatter' };

var trace2 = Lib.extendDeep({}, mock1, {
type: 'candlestick',
});

var trace3 = { type: 'bar' };

var out = _supply([trace0, trace1, trace2, trace3]);

var names = out._fullData.map(function(fullTrace) {
return fullTrace.name;
});

expect(names).toEqual([
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this ⏬ , this used to give

[
  'trace 0 - increasing',
  'trace 0 - decreasing',
  'trace 2',
  'trace 3 - increasing',
  'trace 3 - decreasing',
  'trace 5'
]

'trace 0 - increasing',
'trace 0 - decreasing',
'trace 1',
'trace 2 - increasing',
'trace 2 - decreasing',
'trace 3'
]);
});

it('trace-wide styling should set default for corresponding per-direction styling', function() {
function assertLine(cont, width, dash) {
expect(cont.line.width).toEqual(width);
Expand Down