Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
e915a29cf5da9b7864fa844f2becdf245526cac3fe0f1742361c72cca9eb7c5ede8ee2f6c33f296e129ae32b60fd61afb9dc8aaea5c94c051f574f27b19b742b1918cfbb299bcaf390b672d517ea3c5a1a892b267e0a382f6f072f6036045d26a4b43803005facbf3db98835cc9de6c8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * 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 = require('../src/traces/candlestick'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * 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'; | ||
| var Plotly = require('./core'); | ||
| Plotly.register([ | ||
| require('./bar'), | ||
| require('./histogram'), | ||
| require('./pie'), | ||
| require('./ohlc'), | ||
| require('./candlestick') | ||
| ]); | ||
| module.exports = Plotly; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /** | ||
| * 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 = require('../src/traces/ohlc'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /** | ||
| * 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'; | ||
| /** | ||
| * Return news array containing only the unique items | ||
| * found in input array. | ||
| * | ||
| * IMPORTANT: Note that items are considered unique | ||
| * if `String({})` is unique. For example; | ||
| * | ||
| * Lib.filterUnique([ { a: 1 }, { b: 2 } ]) | ||
| * | ||
| * returns [{ a: 1 }] | ||
| * | ||
| * and | ||
| * | ||
| * Lib.filterUnique([ '1', 1 ]) | ||
| * | ||
| * returns ['1'] | ||
| * | ||
| * | ||
| * @param {array} array base array | ||
| * @return {array} new filtered array | ||
| */ | ||
| module.exports = function filterUnique(array) { | ||
| var seen = {}, | ||
| out = [], | ||
| j = 0; | ||
| for(var i = 0; i < array.length; i++) { | ||
| var item = array[i]; | ||
| if(seen[item] !== 1) { | ||
| seen[item] = 1; | ||
| out[j++] = item; | ||
| } | ||
| } | ||
| return out; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -369,7 +369,7 @@ plots.supplyDefaults = function(gd) { | ||
| // then do the data | ||
| newFullLayout._globalTransforms = (gd._context || {}).globalTransforms; | ||
| plots.supplyDataDefaults(newData, newFullData, newFullLayout); | ||
| plots.supplyDataDefaults(newData, newFullData, newLayout, newFullLayout); | ||
| // attach helper method to check whether a plot type is present on graph | ||
| newFullLayout._has = plots._hasPlotType.bind(newFullLayout); | ||
| @@ -530,7 +530,7 @@ function relinkPrivateKeys(toContainer, fromContainer) { | ||
| var isPlainObject = Lib.isPlainObject, | ||
| isArray = Array.isArray; | ||
| var keys = Object.keys(fromContainer); | ||
| var keys = Object.keys(fromContainer || {}); | ||
| for(var i = 0; i < keys.length; i++) { | ||
| var k = keys[i], | ||
| @@ -593,9 +593,9 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa | ||
| } | ||
| }; | ||
| plots.supplyDataDefaults = function(dataIn, dataOut, layout) { | ||
| var modules = layout._modules = [], | ||
| basePlotModules = layout._basePlotModules = [], | ||
| plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) { | ||
| var modules = fullLayout._modules = [], | ||
| basePlotModules = fullLayout._basePlotModules = [], | ||
| cnt = 0; | ||
| function pushModule(fullTrace) { | ||
| @@ -612,18 +612,18 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout) { | ||
| for(var i = 0; i < dataIn.length; i++) { | ||
| var trace = dataIn[i], | ||
| fullTrace = plots.supplyTraceDefaults(trace, cnt, layout); | ||
| fullTrace = plots.supplyTraceDefaults(trace, cnt, fullLayout); | ||
| fullTrace.index = i; | ||
| fullTrace._input = trace; | ||
| fullTrace._expandedIndex = cnt; | ||
| if(fullTrace.transforms && fullTrace.transforms.length) { | ||
| var expandedTraces = applyTransforms(fullTrace, dataOut, layout); | ||
| var expandedTraces = applyTransforms(fullTrace, dataOut, layout, fullLayout); | ||
| for(var j = 0; j < expandedTraces.length; j++) { | ||
| var expandedTrace = expandedTraces[j], | ||
| fullExpandedTrace = plots.supplyTraceDefaults(expandedTrace, cnt, layout); | ||
| fullExpandedTrace = plots.supplyTraceDefaults(expandedTrace, cnt, fullLayout); | ||
| // mutate uid here using parent uid and expanded index | ||
| // to promote consistency between update calls | ||
| @@ -805,7 +805,7 @@ function supplyTransformDefaults(traceIn, traceOut, layout) { | ||
| if(!_module) Lib.warn('Unrecognized transform type ' + type + '.'); | ||
| if(_module && _module.supplyDefaults) { | ||
| transformOut = _module.supplyDefaults(transformIn, traceOut, layout); | ||
| transformOut = _module.supplyDefaults(transformIn, traceOut, layout, traceIn); | ||
| transformOut.type = type; | ||
| } | ||
| else { | ||
| @@ -816,7 +816,7 @@ function supplyTransformDefaults(traceIn, traceOut, layout) { | ||
| } | ||
| } | ||
| function applyTransforms(fullTrace, fullData, layout) { | ||
| function applyTransforms(fullTrace, fullData, layout, fullLayout) { | ||
| var container = fullTrace.transforms, | ||
| dataOut = [fullTrace]; | ||
| @@ -830,6 +830,7 @@ function applyTransforms(fullTrace, fullData, layout) { | ||
| fullTrace: fullTrace, | ||
| fullData: fullData, | ||
| layout: layout, | ||
| fullLayout: fullLayout, | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI @bpostlethwaite Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sweet I was going to ask for this :) Now I can grab the Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact this might allow the whole Streambed Plotly.js build to stop requiring special Axes API. | ||
| transformIndex: i | ||
| }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /** | ||
| * 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'; | ||
| var Lib = require('../../lib'); | ||
| var OHLCattrs = require('../ohlc/attributes'); | ||
| var boxAttrs = require('../box/attributes'); | ||
| var directionAttrs = { | ||
| name: OHLCattrs.increasing.name, | ||
| showlegend: OHLCattrs.increasing.showlegend, | ||
| line: { | ||
| color: Lib.extendFlat({}, boxAttrs.line.color), | ||
| width: Lib.extendFlat({}, boxAttrs.line.width) | ||
| }, | ||
| fillcolor: Lib.extendFlat({}, boxAttrs.fillcolor), | ||
| }; | ||
| module.exports = { | ||
| x: OHLCattrs.x, | ||
| open: OHLCattrs.open, | ||
| high: OHLCattrs.high, | ||
| low: OHLCattrs.low, | ||
| close: OHLCattrs.close, | ||
| line: { | ||
| width: Lib.extendFlat({}, boxAttrs.line.width, { | ||
| description: [ | ||
| boxAttrs.line.width.description, | ||
| 'Note that this style setting can also be set per', | ||
| 'direction via `increasing.line.width` and', | ||
| '`decreasing.line.width`.' | ||
| ].join(' ') | ||
| }) | ||
| }, | ||
| increasing: Lib.extendDeep({}, directionAttrs, { | ||
| line: { color: { dflt: OHLCattrs.increasing.line.color.dflt } } | ||
| }), | ||
| decreasing: Lib.extendDeep({}, directionAttrs, { | ||
| line: { color: { dflt: OHLCattrs.decreasing.line.color.dflt } } | ||
| }), | ||
| text: OHLCattrs.text, | ||
| whiskerwidth: Lib.extendFlat({}, boxAttrs.whiskerwidth, { dflt: 0 }) | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * 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'; | ||
| 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'); | ||
| module.exports = function supplyDefaults(traceIn, traceOut) { | ||
| helpers.pushDummyTransformOpts(traceIn, traceOut); | ||
| function coerce(attr, dflt) { | ||
| return Lib.coerce(traceIn, traceOut, attributes, attr, dflt); | ||
| } | ||
| var len = handleOHLC(traceIn, traceOut, coerce); | ||
| if(len === 0) { | ||
| traceOut.visible = false; | ||
| return; | ||
| } | ||
| coerce('line.width'); | ||
| handleDirection(traceIn, traceOut, coerce, 'increasing'); | ||
| handleDirection(traceIn, traceOut, coerce, 'decreasing'); | ||
| coerce('text'); | ||
| coerce('whiskerwidth'); | ||
| }; | ||
| function handleDirection(traceIn, traceOut, coerce, direction) { | ||
| handleDirectionDefaults(traceIn, traceOut, coerce, direction); | ||
| coerce(direction + '.line.color'); | ||
| coerce(direction + '.line.width', traceOut.line.width); | ||
| coerce(direction + '.fillcolor'); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdtusz@rreusser thoughts on this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.