Skip to content

Commit caf390b

Browse files
committed
doc: add comments about non-trivial logic in ohlc / candlestick
1 parent fbb299b commit caf390b

File tree

7 files changed

+55
-14
lines changed

7 files changed

+55
-14
lines changed

src/components/legend/draw.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ function drawTexts(g, gd) {
377377
astr;
378378

379379
// N.B. this block isn't super clean,
380+
// is unfortunately untested at the moment,
380381
// and only works for for 'ohlc' and 'candlestick',
381382
// but should be generalized for other one-to-many transforms
382383
if(['ohlc', 'candlestick'].indexOf(fullInput.type) !== -1) {

src/lib/coerce.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,12 @@ exports.findArrayAttributes = function(trace) {
457457

458458
exports.crawl(trace._module.attributes, callback);
459459

460-
// TODO add comment
460+
// Look into the fullInput module attributes for array attributes
461+
// to make sure that 'custom' array attributes are detected.
462+
//
463+
// At the moment, we need this block to make sure that
464+
// ohlc and candlestick 'open', 'high', 'low', 'close' can be
465+
// used with filter ang groupby transforms.
461466
if(trace._fullInput) {
462467
exports.crawl(trace._fullInput._module.attributes, callback);
463468

src/traces/candlestick/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ module.exports = {
1818
categories: ['cartesian', 'showLegend'],
1919
meta: {
2020
description: [
21-
// ...
21+
'The candlestick is a style of financial chart describing',
22+
'open, high, low and close for a given `x` coordinate (most likely time).',
23+
24+
'The boxes represent the spread between the `open` and `close` values and',
25+
'the lines represent the spread between the `low` and `high` values',
26+
27+
'Sample points where the close value is higher (lower) then the open',
28+
'value are called increasing (decreasing).',
29+
30+
'By default, increasing candles are drawn in green whereas',
31+
'decreasing are drawn in red.'
2232
].join(' ')
2333
},
2434

src/traces/ohlc/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = {
9393
'Sets hover text elements associated with each sample point.',
9494
'If a single string, the same string appears over',
9595
'all the data points.',
96-
'If an array of string, the items are mapped in order to the',
96+
'If an array of string, the items are mapped in order to',
9797
'this trace\'s sample points.'
9898
].join(' ')
9999
},

src/traces/ohlc/helpers.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111

1212
var Lib = require('../../lib');
1313

14-
// TODO add comment
14+
// This routine gets called during the trace supply-defaults step.
15+
//
16+
// This is a hacky way to make 'ohlc' and 'candlestick' trace types
17+
// go through the transform machinery.
18+
//
19+
// Note that, we must mutate user data (here traceIn) as opposed
20+
// to full data (here traceOut) as - at the moment - transform
21+
// defaults (which are called after trace defaults) start
22+
// from a clear transforms container.
1523
exports.pushDummyTransformOpts = function(traceIn, traceOut) {
1624
var transformOpts = {
1725

@@ -25,6 +33,8 @@ exports.pushDummyTransformOpts = function(traceIn, traceOut) {
2533
if(Array.isArray(traceIn.transforms)) {
2634
var transformsIn = traceIn.transforms;
2735

36+
// remove all ephemeral transforms,
37+
// before adding dummy transform
2838
for(var i = 0; i < transformsIn.length; i++) {
2939
if(transformsIn[i]._ephemeral) transformsIn.splice(i, 1);
3040
}
@@ -36,18 +46,28 @@ exports.pushDummyTransformOpts = function(traceIn, traceOut) {
3646
}
3747
};
3848

39-
// TODO add comment
49+
// This routine gets called during the transform supply-defaults step,
50+
// but only has an effect (because of the if-statements) during the
51+
// second round of transform defaults done on generated traces.
52+
//
53+
// This is a hacky way to pass 'ohlc' and 'candlestick' attributes
54+
// (found the transform container via exports.makeTransform)
55+
// to the traceOut container such that they can be compatible with
56+
// filter and groupby transforms.
4057
exports.copyOHLC = function(container, traceOut) {
4158
if(container.open) traceOut.open = container.open;
4259
if(container.high) traceOut.high = container.high;
4360
if(container.low) traceOut.low = container.low;
4461
if(container.close) traceOut.close = container.close;
4562
};
4663

47-
// We need to track which direction ('increasing' or 'decreasing')
64+
// This routine gets called during the applyTransform step.
65+
//
66+
// We need to track trace attributes and which direction
67+
// ('increasing' or 'decreasing')
4868
// the generated correspond to for the calcTransform step.
4969
//
50-
// To make sure that direction reaches the calcTransform,
70+
// To make sure that the attributes reach the calcTransform,
5171
// store it in the transform opts object.
5272
exports.makeTransform = function(traceIn, state, direction) {
5373
var out = Lib.extendFlat([], traceIn.transforms);
@@ -56,7 +76,7 @@ exports.makeTransform = function(traceIn, state, direction) {
5676
type: traceIn.type,
5777
direction: direction,
5878

59-
// ...
79+
// these are copied to traceOut during exports.copyOHLC
6080
open: traceIn.open,
6181
high: traceIn.high,
6282
low: traceIn.low,

src/traces/ohlc/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ module.exports = {
1818
categories: ['cartesian', 'showLegend'],
1919
meta: {
2020
description: [
21-
// ...
21+
'The ohlc (short for Open-High-Low-Close) is a style of financial chart describing',
22+
'open, high, low and close for a given `x` coordinate (most likely time).',
23+
24+
'The tip of the lines represent the `low` and `high` values and',
25+
'the horizontal segments represent the `open` and `close` values.',
26+
27+
'Sample points where the close value is higher (lower) then the open',
28+
'value are called increasing (decreasing).',
29+
30+
'By default, increasing candles are drawn in green whereas',
31+
'decreasing are drawn in red.'
2232
].join(' ')
2333
},
2434

test/jasmine/tests/finance_test.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -685,9 +685,4 @@ describe('finance charts updates:', function() {
685685
done();
686686
});
687687
});
688-
689-
it('legend *editable: true* interactions should work', function(done) {
690-
691-
done();
692-
});
693688
});

0 commit comments

Comments
 (0)