8000 OHLC and Candlestick trace types by etpinard · Pull Request #1020 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

OHLC and Candlestick trace types #1020

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 32 commits into from
Oct 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e915a29
relax requirement for re-calc
etpinard Oct 7, 2016
cf5da9b
plots: pass user layout to transforms
etpinard Oct 7, 2016
7864fa8
first pass ohlc trace type
etpinard Sep 9, 2016
44f2bec
first pass candlestick trace type
etpinard Sep 9, 2016
df24552
add ohlc and candlestick to main plotly.js lib index
etpinard Sep 9, 2016
6cac3fe
[maybe?] add 'finance' partial bundle
etpinard Sep 9, 2016
0f17423
fixup user-defined transform test
etpinard Oct 7, 2016
61c72cc
finance: replace attribute 't' -> 'x'
etpinard Oct 7, 2016
a9eb7c5
candlestick: rename 'tickwidth' -> 'whiskerwidth' + make it 1 per trace
etpinard Oct 7, 2016
ede8ee2
ohlc: make 'tickwidth' 1 per trace
etpinard Oct 7, 2016
f6c33f2
finance: 2nd iteration
etpinard Oct 7, 2016
96e129a
fix groupby when `enabled: false
etpinard Oct 7, 2016
e32b60f
findArrayAttributes: include array attribute in fullInput module
etpinard Oct 7, 2016
d61afb9
test: first pass finance suite
etpinard Oct 7, 2016
dc8aaea
finace: ensure supplyDefaults is idempotent
etpinard Oct 11, 2016
5c94c05
finance: add re-calc attributes to restyle lists
etpinard Oct 11, 2016
1f574f2
finance: ensure that restyling visible works
etpinard Oct 11, 2016
7b19b74
finance: improve dflt colors
etpinard Oct 11, 2016
2b1918c
finance: improve inc / dec 'name' / 'showlegend' logic
etpinard Oct 11, 2016
fbb299b
legend: add logic for 'ohlc' and 'candlestick' in legend name edits
etpinard Oct 11, 2016
caf390b
doc: add comments about non-trivial logic in ohlc / candlestick
etpinard Oct 11, 2016
672d517
finance: pass trace 'xaxis' & 'yaxis' to generated traces
etpinard Oct 12, 2016
ea3c5a1
finance: make sure computed tickWidth is always positive
etpinard Oct 12, 2016
a892b26
olhc: add custom hover text
etpinard Oct 12, 2016
7e0a382
finance: ensure that user data isn't mutated in Plots.supplyDefaults
etpinard Oct 12, 2016
f6f072f
utils: add filterUnique helper
etpinard Oct 12, 2016
6036045
ohlc: don't force hovermode: 'closest'
etpinard Oct 12, 2016
d26a4b4
ohlc: bump tickwidth dflt to 0.1
etpinard Oct 12, 2016
3803005
finance: add common 'line' style container
etpinard Oct 12, 2016
facbf3d
test: add finance mocks
etpinard Oct 12, 2016
b98835c
ohlc: bump tickwidth dflt to 0.3
etpinard Oct 13, 2016
c9de6c8
test: add finance trace module bundle test
etpinard Oct 13, 2016
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
Prev Previous commit
Next Next commit
finance: improve inc / dec 'name' / 'showlegend' logic
- remove `increasing/decreasing.visible` attribute
- add increasing/decreasing 'name' and 'showlegend'
  • Loading branch information
etpinard committed Oct 11, 2016
commit 2b1918cfe13b01106ff58a2d466379c4b1ee776a
11 changes: 2 additions & 9 deletions src/traces/candlestick/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,8 @@ var OHLCattrs = require('../ohlc/attributes');
var boxAttrs = require('../box/attributes');

var directionAttrs = {
visible: {
valType: 'enumerated',
values: [true, false, 'legendonly'],
role: 'info',
dflt: true,
description: [

].join(' ')
},
name: OHLCattrs.increasing.name,
showlegend: OHLCattrs.increasing.showlegend,

color: Lib.extendFlat({}, boxAttrs.line.color),
width: Lib.extendFlat({}, boxAttrs.line.width),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I probably should have noticed this earlier (sorry!) but color and width seem odd for line color and width. It took me a bit to figure out that this wasn't the width of the candle, and that we don't need an attribute for that because layout.boxgap does that... This should probably be mentioned somewhere!

Also just like whiskerwidth I'd think width is a property shared by both directions. Can we call these linecolor (in directionAttrs) and linewidth (in attributes)? I guess we could argue that for consistency these should go inside a line container instead... it seems a bit funny to make a one-member container just to keep the names consistent but maybe that will actually be easier and clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we call these linecolor (in directionAttrs) and linewidth (in attributes)?

sounds good.

it seems a bit funny to make a one-member container

Agreed. I much prefer increasing.linecolor and decreasing.lincolor

Expand Down
17 changes: 8 additions & 9 deletions src/traces/candlestick/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

var Lib = require('../../lib');
var handleOHLC = require('../ohlc/ohlc_defaults');
var handleDirectionDefaults = require('../ohlc/direction_defaults');
var helpers = require('../ohlc/helpers');
var attributes = require('./attributes');

Expand All @@ -30,16 +31,14 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
coerce('text');
coerce('whiskerwidth');

handleDirection(traceOut, coerce, 'increasing');
handleDirection(traceOut, coerce, 'decreasing');
handleDirection(traceIn, traceOut, coerce, 'increasing');
handleDirection(traceIn, traceOut, coerce, 'decreasing');
};

function handleDirection(traceOut, coerce, direction) {
var dirVisible = coerce(direction + '.visible', traceOut.visible);
function handleDirection(traceIn, traceOut, coerce, direction) {
handleDirectionDefaults(traceIn, traceOut, coerce, direction);

if(dirVisible) {
coerce(direction + '.color');
coerce(direction + '.width');
coerce(direction + '.fillcolor');
}
coerce(direction + '.color');
coerce(direction + '.width');
coerce(direction + '.fillcolor');
}
37 changes: 18 additions & 19 deletions src/traces/candlestick/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

'use strict';

var Lib = require('../../lib');
var helpers = require('../ohlc/helpers');

exports.moduleType = 'transform';
Expand Down Expand Up @@ -52,17 +53,9 @@ function makeTrace(traceIn, state, direction) {
type: 'box',
boxpoints: false,

// TODO could do better
name: direction,

// TODO this doesn't restyle currently
whiskerwidth: traceIn.whiskerwidth,

text: traceIn.text,
visible: traceIn.visible,
hoverinfo: traceIn.hoverinfo,

opacity: traceIn.opacity,
showlegend: traceIn.showlegend,

transforms: helpers.makeTransform(traceIn, state, direction)
};
Expand All @@ -72,21 +65,27 @@ function makeTrace(traceIn, state, direction) {
var directionOpts = traceIn[direction];

if(directionOpts) {
Lib.extendFlat(traceOut, {

// to make autotype catch date axes soon!!
traceOut.x = traceIn.x || [0];
// to make autotype catch date axes soon!!
x: traceIn.x || [0],

// concat low and high to get correct autorange
traceOut.y = [].concat(traceIn.low).concat(traceIn.high);
// concat low and high to get correct autorange
y: [].concat(traceIn.low).concat(traceIn.high),

traceOut.visible = directionOpts.visible;
whiskerwidth: traceIn.whiskerwidth,
text: traceIn.text,

traceOut.line = {
color: directionOpts.color,
width: directionOpts.width
};
name: directionOpts.name,
showlegend: directionOpts.showlegend,

line: {
color: directionOpts.color,
width: directionOpts.width
},

traceOut.fillcolor = directionOpts.fillcolor;
fillcolor: directionOpts.fillcolor
});
}

return traceOut;
Expand Down
17 changes: 13 additions & 4 deletions src/traces/ohlc/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ var DECREASING_COLOR = '#FF4136';
var lineAttrs = scatterAttrs.line;

var directionAttrs = {
visible: {
valType: 'enumerated',
values: [true, false, 'legendonly'],
name: {
valType: 'string',
role: 'info',
dflt: true,
description: [
'Sets the segment name.',
'The segment name appear as the legend item and on hover.'
].join(' ')
},

showlegend: {
valType: 'boolean',
role: 'info',
dflt: true,
description: [
'Determines whether or not an item corresponding to this',
'segment is shown in the legend.'
].join(' ')
},

Expand Down
A3E2
17 changes: 8 additions & 9 deletions src/traces/ohlc/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

var Lib = require('../../lib');
var handleOHLC = require('./ohlc_defaults');
var handleDirectionDefaults = require('./direction_defaults');
var attributes = require('./attributes');
var helpers = require('./helpers');

Expand All @@ -30,16 +31,14 @@ module.exports = function supplyDefaults(traceIn, traceOut) {
coerce('text');
coerce('tickwidth');

handleDirection(traceOut, coerce, 'increasing');
handleDirection(traceOut, coerce, 'decreasing');
handleDirection(traceIn, traceOut, coerce, 'increasing');
handleDirection(traceIn, traceOut, coerce, 'decreasing');
};

function handleDirection(traceOut, coerce, direction) {
var dirVisible = coerce(direction + '.visible', traceOut.visible);
function handleDirection(traceIn, traceOut, coerce, direction) {
handleDirectionDefaults(traceIn, traceOut, coerce, direction);

if(dirVisible) {
coerce(direction + '.color');
coerce(direction + '.width');
coerce(direction + '.dash');
}
coerce(direction + '.color');
coerce(direction + '.width');
coerce(direction + '.dash');
}
24 changes: 24 additions & 0 deletions src/traces/ohlc/direction_defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2012-2016, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/


'use strict';


module.exports = function handleDirectionDefaults(traceIn, traceOut, coerce, direction) {
coerce(direction + '.showlegend');

// trace-wide *showlegend* overrides direction *showlegend*
if(traceIn.showlegend === false) {
traceOut[direction].showlegend = false;
}

var nameDflt = traceOut.name + ' - ' + direction;

coerce(direction + '.name', nameDflt);
};
33 changes: 17 additions & 16 deletions src/traces/ohlc/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

'use strict';

var Lib = require('../../lib');
var helpers = require('./helpers');
var axisIds = require('../../plots/cartesian/axis_ids');

Expand Down Expand Up @@ -55,14 +56,9 @@ function makeTrace(traceIn, state, direction) {
mode: 'lines',
connectgaps: false,

// TODO could do better
name: direction,

text: traceIn.text,
visible: traceIn.visible,
hoverinfo: traceIn.hoverinfo,

opacity: traceIn.opacity,
showlegend: traceIn.showlegend,

transforms: helpers.makeTransform(traceIn, state, direction)
};
Expand All @@ -72,20 +68,25 @@ function makeTrace(traceIn, state, direction) {
var directionOpts = traceIn[direction];

if(directionOpts) {
Lib.extendFlat(traceOut, {

// to make autotype catch date axes soon!!
traceOut.x = traceIn.x || [0];
// to make autotype catch date axes soon!!
x: traceIn.x || [0],

// concat low and high to get correct autorange
traceOut.y = [].concat(traceIn.low).concat(traceIn.high);
// concat low and high to get correct autorange
y: [].concat(traceIn.low).concat(traceIn.high),

traceOut.visible = directionOpts.visible;
text: traceIn.text,

traceOut.line = {
color: directionOpts.color,
width: directionOpts.width,
dash: directionOpts.dash
};
name: directionOpts.name,
showlegend: directionOpts.showlegend,

line: {
color: directionOpts.color,
width: directionOpts.width,
dash: directionOpts.dash
}
});
}

return traceOut;
Expand Down
Loading
0