Skip to content

Commit 3803005

Browse files
committed
finance: add common 'line' style container
- trace-wide 'line' style sets default for increasing / decreasing line styling
1 parent d26a4b4 commit 3803005

File tree

7 files changed

+96
-31
lines changed

7 files changed

+96
-31
lines changed

src/traces/candlestick/attributes.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ var directionAttrs = {
1717
name: OHLCattrs.increasing.name,
1818
showlegend: OHLCattrs.increasing.showlegend,
1919

20-
color: Lib.extendFlat({}, boxAttrs.line.color),
21-
width: Lib.extendFlat({}, boxAttrs.line.width),
20+
line: {
21+
color: Lib.extendFlat({}, boxAttrs.line.color),
22+
width: Lib.extendFlat({}, boxAttrs.line.width)
23+
},
24+
2225
fillcolor: Lib.extendFlat({}, boxAttrs.fillcolor),
2326
};
2427

@@ -29,14 +32,25 @@ module.exports = {
2932
low: OHLCattrs.low,
3033
close: OHLCattrs.close,
3134

35+
line: {
36+
width: Lib.extendFlat({}, boxAttrs.line.width, {
37+
description: [
38+
boxAttrs.line.width.description,
39+
'Note that this style setting can also be set per',
40+
'direction via `increasing.line.width` and',
41+
'`decreasing.line.width`.'
42+
].join(' ')
43+
})
44+
},
45+
3246
increasing: Lib.extendDeep({}, directionAttrs, {
33-
color: { dflt: OHLCattrs.increasing.color.dflt }
47+
line: { color: { dflt: OHLCattrs.increasing.line.color.dflt } }
3448
}),
3549

3650
decreasing: Lib.extendDeep({}, directionAttrs, {
37-
color: { dflt: OHLCattrs.decreasing.color.dflt }
51+
line: { color: { dflt: OHLCattrs.decreasing.line.color.dflt } }
3852
}),
3953

4054
text: OHLCattrs.text,
41-
whiskerwidth: Lib.extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 }),
55+
whiskerwidth: Lib.extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 })
4256
};

src/traces/candlestick/defaults.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
2828
return;
2929
}
3030

31-
coerce('text');
32-
coerce('whiskerwidth');
31+
coerce('line.width');
3332

3433
handleDirection(traceIn, traceOut, coerce, 'increasing');
3534
handleDirection(traceIn, traceOut, coerce, 'decreasing');
35+
36+
coerce('text');
37+
coerce('whiskerwidth');
3638
};
3739

3840
function handleDirection(traceIn, traceOut, coerce, direction) {
3941
handleDirectionDefaults(traceIn, traceOut, coerce, direction);
4042

41-
coerce(direction + '.color');
42-
coerce(direction + '.width');
43+
coerce(direction + '.line.color');
44+
coerce(direction + '.line.width', traceOut.line.width);
4345
coerce(direction + '.fillcolor');
4446
}

src/traces/candlestick/transform.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,7 @@ function makeTrace(traceIn, state, direction) {
7979

8080
name: directionOpts.name,
8181
showlegend: directionOpts.showlegend,
82-
83-
line: {
84-
color: directionOpts.color,
85-
width: directionOpts.width
86-
},
87-
82+
line: directionOpts.line,
8883
fillcolor: directionOpts.fillcolor
8984
});
9085
}

src/traces/ohlc/attributes.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ var directionAttrs = {
3737
].join(' ')
3838
},
3939

40-
color: Lib.extendFlat({}, lineAttrs.color),
41-
width: Lib.extendFlat({}, lineAttrs.width),
42-
dash: Lib.extendFlat({}, lineAttrs.dash),
40+
line: {
41+
color: Lib.extendFlat({}, lineAttrs.color),
42+
width: Lib.extendFlat({}, lineAttrs.width),
43+
dash: Lib.extendFlat({}, lineAttrs.dash),
44+
}
4345
};
4446

4547
module.exports = {
@@ -76,12 +78,31 @@ module.exports = {
7678
description: 'Sets the close values.'
7779
},
7880

81+
line: {
82+
width: Lib.extendFlat({}, lineAttrs.width, {
83+
description: [
84+
lineAttrs.width,
85+
'Note that this style setting can also be set per',
86+
'direction via `increasing.line.width` and',
87+
'`decreasing.line.width`.'
88+
].join(' ')
89+
}),
90+
dash: Lib.extendFlat({}, lineAttrs.dash, {
91+
description: [
92+
lineAttrs.dash,
93+
'Note that this style setting can also be set per',
94+
'direction via `increasing.line.dash` and',
95+
'`decreasing.line.dash`.'
96+
].join(' ')
97+
}),
98+
},
99+
79100
increasing: Lib.extendDeep({}, directionAttrs, {
80-
color: { dflt: INCREASING_COLOR }
101+
line: { color: { dflt: INCREASING_COLOR } }
81102
}),
82103

83104
decreasing: Lib.extendDeep({}, directionAttrs, {
84-
color: { dflt: DECREASING_COLOR }
105+
line: { color: { dflt: DECREASING_COLOR } }
85106
}),
86107

87108
text: {

src/traces/ohlc/defaults.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
2828
return;
2929
}
3030

31-
coerce('text');
32-
coerce('tickwidth');
31+
coerce('line.width');
32+
coerce('line.dash');
3333

3434
handleDirection(traceIn, traceOut, coerce, 'increasing');
3535
handleDirection(traceIn, traceOut, coerce, 'decreasing');
36+
37+
coerce('text');
38+
coerce('tickwidth');
3639
};
3740

3841
function handleDirection(traceIn, traceOut, coerce, direction) {
3942
handleDirectionDefaults(traceIn, traceOut, coerce, direction);
4043

41-
coerce(direction + '.color');
42-
coerce(direction + '.width');
43-
coerce(direction + '.dash');
44+
coerce(direction + '.line.color');
45+
coerce(direction + '.line.width', traceOut.line.width);
46+
coerce(direction + '.line.dash', traceOut.line.dash);
4447
}

src/traces/ohlc/transform.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,7 @@ function makeTrace(traceIn, state, direction) {
8181

8282
name: directionOpts.name,
8383
showlegend: directionOpts.showlegend,
84-
85-
line: {
86-
color: directionOpts.color,
87-
width: directionOpts.width,
88-
dash: directionOpts.dash
89-
}
84+
line: directionOpts.line
9085
});
9186
}
9287

test/jasmine/tests/finance_test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,41 @@ describe('finance charts defaults:', function() {
220220
]);
221221
});
222222

223+
it('trace-wide styling should set default for corresponding per-direction styling', function() {
224+
function assertLine(cont, width, dash) {
225+
expect(cont.line.width).toEqual(width);
226+
if(dash) expect(cont.line.dash).toEqual(dash);
227+
}
228+
229+
var trace0 = Lib.extendDeep({}, mock0, {
230+
type: 'ohlc',
231+
line: { width: 1, dash: 'dash' },
232+
decreasing: { line: { dash: 'dot' } }
233+
});
234+
235+
var trace1 = Lib.extendDeep({}, mock1, {
236+
type: 'candlestick',
237+
line: { width: 3 },
238+
increasing: { line: { width: 0 } }
239+
});
240+
241+
var out = _supply([trace0, trace1]);
242+
243+
244+
var fullData = out._fullData;
245+
var fullInput = fullData.map(function(fullTrace) { return fullTrace._fullInput; });
246+
247+
assertLine(fullInput[0].increasing, 1, 'dash');
248+
assertLine(fullInput[0].decreasing, 1, 'dot');
249+
assertLine(fullInput[2].increasing, 0);
250+
assertLine(fullInput[2].decreasing, 3);
251+
252+
assertLine(fullData[0], 1, 'dash');
253+
assertLine(fullData[1], 1, 'dot');
254+
assertLine(fullData[2], 0);
255+
assertLine(fullData[3], 3);
256+
});
257+
223258
it('trace-wide *visible* should be passed to generated traces', function() {
224259
var trace0 = Lib.extendDeep({}, mock0, {
225260
type: 'ohlc',

0 commit comments

Comments
 (0)