123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- define("dojox/charting/plot2d/Bars", ["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/array", "dojo/_base/declare", "./Base", "./common",
- "dojox/gfx/fx", "dojox/lang/utils", "dojox/lang/functional", "dojox/lang/functional/reversed"],
- function(dojo, lang, arr, declare, Base, dc, fx, du, df, dfr){
-
-
- var purgeGroup = dfr.lambda("item.purgeGroup()");
- return declare("dojox.charting.plot2d.Bars", Base, {
-
-
- defaultParams: {
- hAxis: "x",
- vAxis: "y",
- gap: 0,
- animate: null,
- enableCache: false
- },
- optionalParams: {
- minBarSize: 1,
- maxBarSize: 1,
-
- stroke: {},
- outline: {},
- shadow: {},
- fill: {},
- font: "",
- fontColor: ""
- },
- constructor: function(chart, kwArgs){
-
-
-
-
-
-
- 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;
- },
- getSeriesStats: function(){
-
-
-
-
- var stats = dc.collectSimpleStats(this.series), t;
- stats.hmin -= 0.5;
- stats.hmax += 0.5;
- t = stats.hmin, stats.hmin = stats.vmin, stats.vmin = t;
- t = stats.hmax, stats.hmax = stats.vmax, stats.vmax = t;
- return stats;
- },
-
- createRect: function(run, creator, params){
- var rect;
- if(this.opt.enableCache && run._rectFreePool.length > 0){
- rect = run._rectFreePool.pop();
- rect.setShape(params);
-
- creator.add(rect);
- }else{
- rect = creator.createRect(params);
- }
- if(this.opt.enableCache){
- run._rectUsePool.push(rect);
- }
- return rect;
- },
- render: function(dim, offsets){
-
-
-
-
-
-
-
-
- if(this.zoom && !this.isDataDirty()){
- return this.performZoom(dim, offsets);
- }
- this.dirty = this.isDirty();
- this.resetEvents();
- if(this.dirty){
- arr.forEach(this.series, purgeGroup);
- this._eventSeries = {};
- this.cleanGroup();
- var s = this.group;
- df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
- }
- var t = this.chart.theme, f, gap, height,
- ht = this._hScaler.scaler.getTransformerFromModel(this._hScaler),
- vt = this._vScaler.scaler.getTransformerFromModel(this._vScaler),
- baseline = Math.max(0, this._hScaler.bounds.lower),
- baselineWidth = ht(baseline),
- events = this.events();
- f = dc.calculateBarSize(this._vScaler.bounds.scale, this.opt);
- gap = f.gap;
- height = f.size;
- for(var i = this.series.length - 1; i >= 0; --i){
- var run = this.series[i];
- if(!this.dirty && !run.dirty){
- t.skip();
- this._reconnectEvents(run.name);
- continue;
- }
- run.cleanGroup();
- if(this.opt.enableCache){
- run._rectFreePool = (run._rectFreePool?run._rectFreePool:[]).concat(run._rectUsePool?run._rectUsePool:[]);
- run._rectUsePool = [];
- }
- var theme = t.next("bar", [this.opt, run]), s = run.group,
- eventSeries = new Array(run.data.length);
- for(var j = 0; j < run.data.length; ++j){
- var value = run.data[j];
- if(value !== null){
- var v = typeof value == "number" ? value : value.y,
- hv = ht(v),
- width = hv - baselineWidth,
- w = Math.abs(width),
- finalTheme = typeof value != "number" ?
- t.addMixin(theme, "bar", value, true) :
- t.post(theme, "bar");
- if(w >= 0 && height >= 1){
- var rect = {
- x: offsets.l + (v < baseline ? hv : baselineWidth),
- y: dim.height - offsets.b - vt(j + 1.5) + gap,
- width: w, height: height
- };
- var specialFill = this._plotFill(finalTheme.series.fill, dim, offsets);
- specialFill = this._shapeFill(specialFill, rect);
- var shape = this.createRect(run, s, rect).setFill(specialFill).setStroke(finalTheme.series.stroke);
- run.dyn.fill = shape.getFill();
- run.dyn.stroke = shape.getStroke();
- if(events){
- var o = {
- element: "bar",
- index: j,
- run: run,
- shape: shape,
- x: v,
- y: j + 1.5
- };
- this._connectEvents(o);
- eventSeries[j] = o;
- }
- if(this.animate){
- this._animateBar(shape, offsets.l + baselineWidth, -w);
- }
- }
- }
- }
- this._eventSeries[run.name] = eventSeries;
- run.dirty = false;
- }
- this.dirty = false;
- return this;
- },
- _animateBar: function(shape, hoffset, hsize){
- fx.animateTransform(lang.delegate({
- shape: shape,
- duration: 1200,
- transform: [
- {name: "translate", start: [hoffset - (hoffset/hsize), 0], end: [0, 0]},
- {name: "scale", start: [1/hsize, 1], end: [1, 1]},
- {name: "original"}
- ]
- }, this.animate)).play();
- }
- });
- });
|