//>>built define("dojox/charting/plot2d/OHLC", ["dojo/_base/lang", "dojo/_base/array", "dojo/_base/declare", "./Base", "./common", "dojox/lang/functional", "dojox/lang/functional/reversed", "dojox/lang/utils", "dojox/gfx/fx"], function(lang, arr, declare, Base, dc, df, dfr, du, fx){ /*===== var Base = dojox.charting.plot2d.Base; =====*/ var purgeGroup = dfr.lambda("item.purgeGroup()"); // Candlesticks are based on the Bars plot type; we expect the following passed // as values in a series: // { x?, open, close, high, low } // if x is not provided, the array index is used. // failing to provide the OHLC values will throw an error. return declare("dojox.charting.plot2d.OHLC", Base, { // summary: // A plot that represents typical open/high/low/close (financial reporting, primarily). // Unlike most charts, the Candlestick expects data points to be represented by // an object of the form { x?, open, close, high, low, mid? }, where both // x and mid are optional parameters. If x is not provided, the index of the // data array is used. defaultParams: { hAxis: "x", // use a horizontal axis named "x" vAxis: "y", // use a vertical axis named "y" gap: 2, // gap between columns in pixels animate: null // animate chart to place }, optionalParams: { minBarSize: 1, // minimal bar size in pixels maxBarSize: 1, // maximal bar size in pixels // theme component stroke: {}, outline: {}, shadow: {}, fill: {}, font: "", fontColor: "" }, constructor: function(chart, kwArgs){ // summary: // The constructor for a candlestick chart. // chart: dojox.charting.Chart // The chart this plot belongs to. // kwArgs: dojox.charting.plot2d.__BarCtorArgs? // An optional keyword arguments object to help define the plot. this.opt = lang.clone(this.defaultParams); du.updateWithObject(this.opt, kwArgs); du.updateWithPattern(this.opt, kwArgs, this.optionalParams); this.series = []; this.hAxis = this.opt.hAxis; this.vAxis = this.opt.vAxis; this.animate = this.opt.animate; }, collectStats: function(series){ // summary: // Collect all statistics for drawing this chart. Since the common // functionality only assumes x and y, OHLC must create it's own // stats (since data has no y value, but open/close/high/low instead). // series: dojox.charting.Series[] // The data series array to be drawn on this plot. // returns: Object // Returns an object in the form of { hmin, hmax, vmin, vmax }. // we have to roll our own, since we need to use all four passed // values to figure out our stats, and common only assumes x and y. var stats = lang.delegate(dc.defaultStats); for(var i=0; i= 0; --i){ var run = this.series[i]; if(!this.dirty && !run.dirty){ t.skip(); this._reconnectEvents(run.name); continue; } run.cleanGroup(); var theme = t.next("candlestick", [this.opt, run]), s = run.group, eventSeries = new Array(run.data.length); for(var j = 0; j < run.data.length; ++j){ var v = run.data[j]; if(v !== null){ var finalTheme = t.addMixin(theme, "candlestick", v, true); // calculate the points we need for OHLC var x = ht(v.x || (j+0.5)) + offsets.l + gap, y = dim.height - offsets.b, open = vt(v.open), close = vt(v.close), high = vt(v.high), low = vt(v.low); if(low > high){ var tmp = high; high = low; low = tmp; } if(width >= 1){ var hl = {x1: width/2, x2: width/2, y1: y - high, y2: y - low}, op = {x1: 0, x2: ((width/2) + ((finalTheme.series.stroke.width||1)/2)), y1: y-open, y2: y-open}, cl = {x1: ((width/2) - ((finalTheme.series.stroke.width||1)/2)), x2: width, y1: y-close, y2: y-close}; var shape = s.createGroup(); shape.setTransform({dx: x, dy: 0}); var inner = shape.createGroup(); inner.createLine(hl).setStroke(finalTheme.series.stroke); inner.createLine(op).setStroke(finalTheme.series.stroke); inner.createLine(cl).setStroke(finalTheme.series.stroke); // TODO: double check this. run.dyn.stroke = finalTheme.series.stroke; if(events){ var o = { element: "candlestick", index: j, run: run, shape: inner, x: x, y: y-Math.max(open, close), cx: width/2, cy: (y-Math.max(open, close)) + (Math.max(open > close ? open-close : close-open, 1)/2), width: width, height: Math.max(open > close ? open-close : close-open, 1), data: v }; this._connectEvents(o); eventSeries[j] = o; } } if(this.animate){ this._animateOHLC(shape, y - low, high - low); } } } this._eventSeries[run.name] = eventSeries; run.dirty = false; } this.dirty = false; return this; // dojox.charting.plot2d.OHLC }, _animateOHLC: function(shape, voffset, vsize){ fx.animateTransform(lang.delegate({ shape: shape, duration: 1200, transform: [ {name: "translate", start: [0, voffset - (voffset/vsize)], end: [0, 0]}, {name: "scale", start: [1, 1/vsize], end: [1, 1]}, {name: "original"} ] }, this.animate)).play(); } }); });