1 | define(["dojo/_base/array", "dojo/_base/declare", "./Columns", "./common", |
---|
2 | "dojox/lang/functional", "dojox/lang/functional/reversed", "dojox/lang/utils"], |
---|
3 | function(arr, declare, Columns, dc, df, dfr, du){ |
---|
4 | /*===== |
---|
5 | var Columns = dojox.charting.plot2d.Columns; |
---|
6 | =====*/ |
---|
7 | |
---|
8 | var purgeGroup = dfr.lambda("item.purgeGroup()"); |
---|
9 | |
---|
10 | return declare("dojox.charting.plot2d.ClusteredColumns", Columns, { |
---|
11 | // summary: |
---|
12 | // A plot representing grouped or clustered columns (vertical bars). |
---|
13 | render: function(dim, offsets){ |
---|
14 | // summary: |
---|
15 | // Run the calculations for any axes for this plot. |
---|
16 | // dim: Object |
---|
17 | // An object in the form of { width, height } |
---|
18 | // offsets: Object |
---|
19 | // An object of the form { l, r, t, b}. |
---|
20 | // returns: dojox.charting.plot2d.ClusteredColumns |
---|
21 | // A reference to this plot for functional chaining. |
---|
22 | if(this.zoom && !this.isDataDirty()){ |
---|
23 | return this.performZoom(dim, offsets); |
---|
24 | } |
---|
25 | this.resetEvents(); |
---|
26 | this.dirty = this.isDirty(); |
---|
27 | if(this.dirty){ |
---|
28 | arr.forEach(this.series, purgeGroup); |
---|
29 | this._eventSeries = {}; |
---|
30 | this.cleanGroup(); |
---|
31 | var s = this.group; |
---|
32 | df.forEachRev(this.series, function(item){ item.cleanGroup(s); }); |
---|
33 | } |
---|
34 | var t = this.chart.theme, f, gap, width, thickness, |
---|
35 | ht = this._hScaler.scaler.getTransformerFromModel(this._hScaler), |
---|
36 | vt = this._vScaler.scaler.getTransformerFromModel(this._vScaler), |
---|
37 | baseline = Math.max(0, this._vScaler.bounds.lower), |
---|
38 | baselineHeight = vt(baseline), |
---|
39 | events = this.events(); |
---|
40 | f = dc.calculateBarSize(this._hScaler.bounds.scale, this.opt, this.series.length); |
---|
41 | gap = f.gap; |
---|
42 | width = thickness = f.size; |
---|
43 | for(var i = 0; i < this.series.length; ++i){ |
---|
44 | var run = this.series[i], shift = thickness * i; |
---|
45 | if(!this.dirty && !run.dirty){ |
---|
46 | t.skip(); |
---|
47 | this._reconnectEvents(run.name); |
---|
48 | continue; |
---|
49 | } |
---|
50 | run.cleanGroup(); |
---|
51 | var theme = t.next("column", [this.opt, run]), s = run.group, |
---|
52 | eventSeries = new Array(run.data.length); |
---|
53 | for(var j = 0; j < run.data.length; ++j){ |
---|
54 | var value = run.data[j]; |
---|
55 | if(value !== null){ |
---|
56 | var v = typeof value == "number" ? value : value.y, |
---|
57 | vv = vt(v), |
---|
58 | height = vv - baselineHeight, |
---|
59 | h = Math.abs(height), |
---|
60 | finalTheme = typeof value != "number" ? |
---|
61 | t.addMixin(theme, "column", value, true) : |
---|
62 | t.post(theme, "column"); |
---|
63 | if(width >= 1 && h >= 0){ |
---|
64 | var rect = { |
---|
65 | x: offsets.l + ht(j + 0.5) + gap + shift, |
---|
66 | y: dim.height - offsets.b - (v > baseline ? vv : baselineHeight), |
---|
67 | width: width, height: h |
---|
68 | }; |
---|
69 | var specialFill = this._plotFill(finalTheme.series.fill, dim, offsets); |
---|
70 | specialFill = this._shapeFill(specialFill, rect); |
---|
71 | var shape = s.createRect(rect).setFill(specialFill).setStroke(finalTheme.series.stroke); |
---|
72 | run.dyn.fill = shape.getFill(); |
---|
73 | run.dyn.stroke = shape.getStroke(); |
---|
74 | if(events){ |
---|
75 | var o = { |
---|
76 | element: "column", |
---|
77 | index: j, |
---|
78 | run: run, |
---|
79 | shape: shape, |
---|
80 | x: j + 0.5, |
---|
81 | y: v |
---|
82 | }; |
---|
83 | this._connectEvents(o); |
---|
84 | eventSeries[j] = o; |
---|
85 | } |
---|
86 | if(this.animate){ |
---|
87 | this._animateColumn(shape, dim.height - offsets.b - baselineHeight, h); |
---|
88 | } |
---|
89 | } |
---|
90 | } |
---|
91 | } |
---|
92 | this._eventSeries[run.name] = eventSeries; |
---|
93 | run.dirty = false; |
---|
94 | } |
---|
95 | this.dirty = false; |
---|
96 | return this; // dojox.charting.plot2d.ClusteredColumns |
---|
97 | } |
---|
98 | }); |
---|
99 | }); |
---|