Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4bda0bb

Browse filesBrowse files
authored
Merge pull request #1073 from plotly/transform-trace-dflt-name
Use trace gd.data index to determine dflt trace name
2 parents 000a409 + 4d10983 commit 4bda0bb
Copy full SHA for 4bda0bb

File tree

Expand file treeCollapse file tree

2 files changed

+34
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+34
-5
lines changed

‎src/plots/plots.js

Copy file name to clipboardExpand all lines: src/plots/plots.js
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
618618

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

623623
fullTrace.index = i;
624624
fullTrace._input = trace;
@@ -629,7 +629,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
629629

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

634634
// mutate uid here using parent uid and expanded index
635635
// to promote consistency between update calls
@@ -733,9 +733,9 @@ plots.supplyFrameDefaults = function(frameIn) {
733733
return frameOut;
734734
};
735735

736-
plots.supplyTraceDefaults = function(traceIn, traceIndex, layout) {
736+
plots.supplyTraceDefaults = function(traceIn, traceOutIndex, layout, traceInIndex) {
737737
var traceOut = {},
738-
defaultColor = Color.defaults[traceIndex % Color.defaults.length];
738+
defaultColor = Color.defaults[traceOutIndex % Color.defaults.length];
739739

740740
function coerce(attr, dflt) {
741741
return Lib.coerce(traceIn, traceOut, plots.attributes, attr, dflt);
@@ -752,7 +752,7 @@ plots.supplyTraceDefaults = function(traceIn, traceIndex, layout) {
752752

753753
coerce('type');
754754
coerce('uid');
755-
coerce('name', 'trace ' + traceIndex);
755+
coerce('name', 'trace ' + traceInIndex);
756756

757757
// coerce subplot attributes of all registered subplot types
758758
var subplotTypes = Object.keys(subplotsRegistry);

‎test/jasmine/tests/finance_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/finance_test.js
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,35 @@ describe('finance charts defaults:', function() {
220220
]);
221221
});
222222

223+
it('trace *name* default should make reference to user data trace indices', function() {
224+
var trace0 = Lib.extendDeep({}, mock0, {
225+
type: 'ohlc'
226+
});
227+
228+
var trace1 = { type: 'scatter' };
229+
230+
var trace2 = Lib.extendDeep({}, mock1, {
231+
type: 'candlestick',
232+
});
233+
234+
var trace3 = { type: 'bar' };
235+
236+
var out = _supply([trace0, trace1, trace2, trace3]);
237+
238+
var names = out._fullData.map(function(fullTrace) {
239+
return fullTrace.name;
240+
});
241+
242+
expect(names).toEqual([
243+
'trace 0 - increasing',
244+
'trace 0 - decreasing',
245+
'trace 1',
246+
'trace 2 - increasing',
247+
'trace 2 - decreasing',
248+
'trace 3'
249+
]);
250+
});
251+
223252
it('trace-wide styling should set default for corresponding per-direction styling', function() {
224253
function assertLine(cont, width, dash) {
225254
expect(cont.line.width).toEqual(width);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.