source: Dev/trunk/src/client/dojox/charting/plot2d/Base.js @ 483

Last change on this file since 483 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 5.5 KB
Line 
1define(["dojo/_base/declare", "dojo/_base/array", "dojox/gfx",
2                "../Element", "./common", "../axis2d/common", "dojo/has"],
3        function(declare, arr, gfx, Element, common, ac, has){
4/*=====
5dojox.charting.plot2d.__PlotCtorArgs = {
6        // summary:
7        //              The base keyword arguments object for plot constructors.
8        //              Note that the parameters for this may change based on the
9        //              specific plot type (see the corresponding plot type for
10        //              details).
11
12        // tooltipFunc: Function?
13        //              An optional function used to compute tooltip text for this plot. It takes precedence over
14        //              the default function when available.
15        //      |               function tooltipFunc(o) { return "text"; }
16        //              `o`is the event object that triggered the tooltip.
17        tooltipFunc: null
18};
19=====*/
20        var Base = declare("dojox.charting.plot2d.Base", Element, {
21                // summary:
22                //              Base class for all plot types.
23                constructor: function(chart, kwArgs){
24                        // summary:
25                        //              Create a base plot for charting.
26                        // chart: dojox/chart/Chart
27                        //              The chart this plot belongs to.
28                        // kwArgs: dojox.charting.plot2d.__PlotCtorArgs?
29                        //              An optional arguments object to help define the plot.
30       
31                        // TODO does not work in markup
32                        if(kwArgs && kwArgs.tooltipFunc){
33                                this.tooltipFunc = kwArgs.tooltipFunc;
34                        }
35                },
36                clear: function(){
37                        // summary:
38                        //              Clear out all of the information tied to this plot.
39                        // returns: dojox.charting.plot2d.Base
40                        //              A reference to this plot for functional chaining.
41                        this.series = [];
42                        this.dirty = true;
43                        return this;    //      dojox/charting/plot2d/Base
44                },
45                setAxis: function(axis){
46                        // summary:
47                        //              Set an axis for this plot.
48                        // axis: dojox.charting.axis2d.Base
49                        //              The axis to set.
50                        // returns: dojox/charting/plot2d/Base
51                        //              A reference to this plot for functional chaining.
52                        return this;    //      dojox/charting/plot2d/Base
53                },
54                assignAxes: function(axes){
55                        // summary:
56                        //              From an array of axes pick the ones that correspond to this plot and
57                        //              assign them to the plot using setAxis method.
58                        // axes: Array
59                        //              An array of dojox/charting/axis2d/Base
60                        // tags:
61                        //              protected
62                        arr.forEach(this.axes, function(axis){
63                                if(this[axis]){
64                                        this.setAxis(axes[this[axis]]);
65                                }
66                        }, this);
67                },
68                addSeries: function(run){
69                        // summary:
70                        //              Add a data series to this plot.
71                        // run: dojox.charting.Series
72                        //              The series to be added.
73                        // returns: dojox/charting/plot2d/Base
74                        //              A reference to this plot for functional chaining.
75                        this.series.push(run);
76                        return this;    //      dojox/charting/plot2d/Base
77                },
78                getSeriesStats: function(){
79                        // summary:
80                        //              Calculate the min/max on all attached series in both directions.
81                        // returns: Object
82                        //              {hmin, hmax, vmin, vmax} min/max in both directions.
83                        return common.collectSimpleStats(this.series);
84                },
85                calculateAxes: function(dim){
86                        // summary:
87                        //              Stub function for running the axis calculations (deprecated).
88                        // dim: Object
89                        //              An object of the form { width, height }
90                        // returns: dojox/charting/plot2d/Base
91                        //              A reference to this plot for functional chaining.
92                        this.initializeScalers(dim, this.getSeriesStats());
93                        return this;    //      dojox/charting/plot2d/Base
94                },
95                initializeScalers: function(){
96                        // summary:
97                        //              Does nothing.
98                        return this;
99                },
100                isDataDirty: function(){
101                        // summary:
102                        //              Returns whether or not any of this plot's data series need to be rendered.
103                        // returns: Boolean
104                        //              Flag indicating if any of this plot's series are invalid and need rendering.
105                        return arr.some(this.series, function(item){ return item.dirty; });     //      Boolean
106                },
107                render: function(dim, offsets){
108                        // summary:
109                        //              Render the plot on the chart.
110                        // dim: Object
111                        //              An object of the form { width, height }.
112                        // offsets: Object
113                        //              An object of the form { l, r, t, b }.
114                        // returns: dojox/charting/plot2d/Base
115                        //              A reference to this plot for functional chaining.
116                        return this;    //      dojox/charting/plot2d/Base
117                },
118                renderLabel: function(group, x, y, label, theme, block, align){
119                        var elem = ac.createText[this.opt.htmlLabels && gfx.renderer != "vml" ? "html" : "gfx"]
120                                (this.chart, group, x, y, align?align:"middle", label, theme.series.font, theme.series.fontColor);
121                        // if the label is inside we need to avoid catching events on it this would prevent action on
122                        // chart elements
123                        if(block){
124                                // TODO this won't work in IE neither in VML nor in HTML
125                                // a solution would be to catch the event on the label and refire it to the element
126                                // possibly using elementFromPoint or having it already available
127                                if(this.opt.htmlLabels && gfx.renderer != "vml"){
128                                        // we have HTML labels, let's use pointEvents on the HTML node
129                                        elem.style.pointerEvents = "none";
130                                }else if(elem.rawNode){
131                                        // we have SVG labels, let's use pointerEvents on the SVG or VML node
132                                        elem.rawNode.style.pointerEvents = "none";
133                                }
134                                // else we have Canvas, we need do nothing, as Canvas text won't catch events
135                        }
136                        if(this.opt.htmlLabels && gfx.renderer != "vml"){
137                                this.htmlElements.push(elem);
138                        }
139
140                        return elem;
141                },
142                getRequiredColors: function(){
143                        // summary:
144                        //              Get how many data series we have, so we know how many colors to use.
145                        // returns: Number
146                        //              The number of colors needed.
147                        return this.series.length;      //      Number
148                },
149                _getLabel: function(number){
150                        return common.getLabel(number, this.opt.fixed, this.opt.precision);
151                }
152        });
153        if(has("dojo-bidi")){
154                Base.extend({
155                        _checkOrientation: function(group, dim, offsets){
156                                this.chart.applyMirroring(this.group, dim, offsets);
157                        }               
158                });
159        }
160        return Base;
161});
Note: See TracBrowser for help on using the repository browser.