| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- define("dojox/charting/plot2d/Default", ["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/array",
- "./Base", "./common", "dojox/lang/functional", "dojox/lang/functional/reversed", "dojox/lang/utils", "dojox/gfx/fx"],
- function(lang, declare, arr, Base, dc, df, dfr, du, fx){
-
- var purgeGroup = dfr.lambda("item.purgeGroup()");
- var DEFAULT_ANIMATION_LENGTH = 1200;
- return declare("dojox.charting.plot2d.Default", Base, {
- defaultParams: {
- hAxis: "x",
- vAxis: "y",
- lines: true,
- areas: false,
- markers: false,
- tension: "",
- animate: false,
- enableCache: false
- },
- optionalParams: {
-
- stroke: {},
- outline: {},
- shadow: {},
- fill: {},
- font: "",
- fontColor: "",
- markerStroke: {},
- markerOutline: {},
- markerShadow: {},
- markerFill: {},
- markerFont: "",
- markerFontColor: ""
- },
- 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;
- },
- createPath: function(run, creator, params){
- var path;
- if(this.opt.enableCache && run._pathFreePool.length > 0){
- path = run._pathFreePool.pop();
- path.setShape(params);
-
- creator.add(path);
- }else{
- path = creator.createPath(params);
- }
- if(this.opt.enableCache){
- run._pathUsePool.push(path);
- }
- return path;
- },
- render: function(dim, offsets){
-
-
-
-
-
-
-
-
-
- if(this.zoom && !this.isDataDirty()){
- return this.performZoom(dim, offsets);
- }
- this.resetEvents();
- this.dirty = this.isDirty();
- if(this.dirty){
- arr.forEach(this.series, purgeGroup);
- this._eventSeries = {};
- this.cleanGroup();
- this.group.setTransform(null);
- var s = this.group;
- df.forEachRev(this.series, function(item){ item.cleanGroup(s); });
- }
- var t = this.chart.theme, stroke, outline, marker, events = this.events();
- 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._pathFreePool = (run._pathFreePool?run._pathFreePool:[]).concat(run._pathUsePool?run._pathUsePool:[]);
- run._pathUsePool = [];
- }
- if(!run.data.length){
- run.dirty = false;
- t.skip();
- continue;
- }
- var theme = t.next(this.opt.areas ? "area" : "line", [this.opt, run], true),
- s = run.group, rsegments = [], startindexes = [], rseg = null, lpoly,
- ht = this._hScaler.scaler.getTransformerFromModel(this._hScaler),
- vt = this._vScaler.scaler.getTransformerFromModel(this._vScaler),
- eventSeries = this._eventSeries[run.name] = new Array(run.data.length);
-
-
- var indexed = typeof run.data[0] == "number";
- var min = indexed?Math.max(0, Math.floor(this._hScaler.bounds.from - 1)):0,
- max = indexed?Math.min(run.data.length, Math.ceil(this._hScaler.bounds.to)):run.data.length;
-
- for(var j = min; j < max; j++){
- if(run.data[j] != null){
- if(!rseg){
- rseg = [];
- startindexes.push(j);
- rsegments.push(rseg);
- }
- rseg.push(run.data[j]);
- }else{
- rseg = null;
- }
- }
- for(var seg = 0; seg < rsegments.length; seg++){
- if(typeof rsegments[seg][0] == "number"){
- lpoly = arr.map(rsegments[seg], function(v, i){
- return {
- x: ht(i + startindexes[seg] + 1) + offsets.l,
- y: dim.height - offsets.b - vt(v)
- };
- }, this);
- }else{
- lpoly = arr.map(rsegments[seg], function(v, i){
- return {
- x: ht(v.x) + offsets.l,
- y: dim.height - offsets.b - vt(v.y)
- };
- }, this);
- }
- var lpath = this.opt.tension ? dc.curve(lpoly, this.opt.tension) : "";
- if(this.opt.areas && lpoly.length > 1){
- var fill = theme.series.fill;
- var apoly = lang.clone(lpoly);
- if(this.opt.tension){
- var apath = "L" + apoly[apoly.length-1].x + "," + (dim.height - offsets.b) +
- " L" + apoly[0].x + "," + (dim.height - offsets.b) +
- " L" + apoly[0].x + "," + apoly[0].y;
- run.dyn.fill = s.createPath(lpath + " " + apath).setFill(fill).getFill();
- } else {
- apoly.push({x: lpoly[lpoly.length - 1].x, y: dim.height - offsets.b});
- apoly.push({x: lpoly[0].x, y: dim.height - offsets.b});
- apoly.push(lpoly[0]);
- run.dyn.fill = s.createPolyline(apoly).setFill(fill).getFill();
- }
- }
- if(this.opt.lines || this.opt.markers){
-
- stroke = theme.series.stroke;
- if(theme.series.outline){
- outline = run.dyn.outline = dc.makeStroke(theme.series.outline);
- outline.width = 2 * outline.width + stroke.width;
- }
- }
- if(this.opt.markers){
- run.dyn.marker = theme.symbol;
- }
- var frontMarkers = null, outlineMarkers = null, shadowMarkers = null;
- if(stroke && theme.series.shadow && lpoly.length > 1){
- var shadow = theme.series.shadow,
- spoly = arr.map(lpoly, function(c){
- return {x: c.x + shadow.dx, y: c.y + shadow.dy};
- });
- if(this.opt.lines){
- if(this.opt.tension){
- run.dyn.shadow = s.createPath(dc.curve(spoly, this.opt.tension)).setStroke(shadow).getStroke();
- } else {
- run.dyn.shadow = s.createPolyline(spoly).setStroke(shadow).getStroke();
- }
- }
- if(this.opt.markers && theme.marker.shadow){
- shadow = theme.marker.shadow;
- shadowMarkers = arr.map(spoly, function(c){
- return this.createPath(run, s, "M" + c.x + " " + c.y + " " + theme.symbol).
- setStroke(shadow).setFill(shadow.color);
- }, this);
- }
- }
- if(this.opt.lines && lpoly.length > 1){
- if(outline){
- if(this.opt.tension){
- run.dyn.outline = s.createPath(lpath).setStroke(outline).getStroke();
- } else {
- run.dyn.outline = s.createPolyline(lpoly).setStroke(outline).getStroke();
- }
- }
- if(this.opt.tension){
- run.dyn.stroke = s.createPath(lpath).setStroke(stroke).getStroke();
- } else {
- run.dyn.stroke = s.createPolyline(lpoly).setStroke(stroke).getStroke();
- }
- }
- if(this.opt.markers){
- frontMarkers = new Array(lpoly.length);
- outlineMarkers = new Array(lpoly.length);
- outline = null;
- if(theme.marker.outline){
- outline = dc.makeStroke(theme.marker.outline);
- outline.width = 2 * outline.width + (theme.marker.stroke ? theme.marker.stroke.width : 0);
- }
- arr.forEach(lpoly, function(c, i){
- var path = "M" + c.x + " " + c.y + " " + theme.symbol;
- if(outline){
- outlineMarkers[i] = this.createPath(run, s, path).setStroke(outline);
- }
- frontMarkers[i] = this.createPath(run, s, path).setStroke(theme.marker.stroke).setFill(theme.marker.fill);
- }, this);
- run.dyn.markerFill = theme.marker.fill;
- run.dyn.markerStroke = theme.marker.stroke;
- if(events){
- arr.forEach(frontMarkers, function(s, i){
- var o = {
- element: "marker",
- index: i + startindexes[seg],
- run: run,
- shape: s,
- outline: outlineMarkers[i] || null,
- shadow: shadowMarkers && shadowMarkers[i] || null,
- cx: lpoly[i].x,
- cy: lpoly[i].y
- };
- if(typeof rsegments[seg][0] == "number"){
- o.x = i + startindexes[seg] + 1;
- o.y = rsegments[seg][i];
- }else{
- o.x = rsegments[seg][i].x;
- o.y = rsegments[seg][i].y;
- }
- this._connectEvents(o);
- eventSeries[i + startindexes[seg]] = o;
- }, this);
- }else{
- delete this._eventSeries[run.name];
- }
- }
- }
- run.dirty = false;
- }
- if(this.animate){
-
- var plotGroup = this.group;
- fx.animateTransform(lang.delegate({
- shape: plotGroup,
- duration: DEFAULT_ANIMATION_LENGTH,
- transform:[
- {name:"translate", start: [0, dim.height - offsets.b], end: [0, 0]},
- {name:"scale", start: [1, 0], end:[1, 1]},
- {name:"original"}
- ]
- }, this.animate)).play();
- }
- this.dirty = false;
- return this;
- }
- });
- });
|