source: extensions/GrumPluginClasses/js/CanvasDraw.GraphClasses.js @ 19961

Last change on this file since 19961 was 17735, checked in by grum, 12 years ago

version 3.5.4 - fix minor bug & add new functions to framework

File size: 28.5 KB
Line 
1/** ----------------------------------------------------------------------------
2 * file         : CanvasDraw.GraphClasses.js
3 * file version : 1.0
4 * date         : 2011-10-22
5 * -----------------------------------------------------------------------------
6 * author: grum at grum.fr
7 * << May the Little SpaceFrog be with you >>
8 *
9 * This program is free software and is published under the terms of the GNU GPL
10 * Please read CanvasDraw.ReadMe.txt file for more information
11 *
12 * -----------------------------------------------------------------------------
13 *
14 * dependencies : none
15 *
16 * -----------------------------------------------------------------------------
17 *
18 *  - CDMargins()
19 *      . top
20 *      . bottom
21 *      . left
22 *      . right
23 *
24 *  - CDAxis()
25 *      . set()
26 *      . setValues()
27 *      . get()
28 *      . getXYHPos()
29 *      . getVPos()
30 *      . getXYVStepPos()
31 *      . getXYAxisValues()
32 *      . getXYAxisValues()
33 *
34 *  - CDSerie()
35 *      .
36 *
37 * -----------------------------------------------------------------------------
38 */
39
40
41/**
42 * margins
43 */
44function CDMargins(values)
45{
46  var _this=this,
47      margins={
48        left:0,
49        right:0,
50        bottom:0,
51        top:0
52  },
53
54  init = function (values)
55    {
56      _this.set(values);
57    };
58
59  this.setLeft = function(value)
60    {
61      if(value>=0) margins.left=value;
62      return(margins.left);
63    };
64
65  this.setRight = function(value)
66    {
67      if(value>=0) margins.right=value;
68      return(margins.right);
69    };
70
71  this.setTop = function(value)
72    {
73      if(value>=0) margins.top=value;
74      return(margins.top);
75    };
76
77  this.setBottom = function(value)
78    {
79      if(value>=0) margins.bottom=value;
80      return(margins.bottom);
81    };
82
83  this.get = function ()
84    {
85      return(margins);
86    };
87
88  this.set = function (value)
89    {
90      if(value instanceof CDMargins)
91      {
92        tmp=value.get();
93        margins.left=tmp.left;
94        margins.top=tmp.top;
95        margins.bottom=tmp.bottom;
96        margins.right=tmp.right;
97        return(margins);
98      }
99      if($.isPlainObject(value))
100      {
101        if(value.left && value.left>0) margins.left=value.left;
102        if(value.right && value.right>0) margins.right=value.right;
103        if(value.top && value.top>0) margins.top=value.top;
104        if(value.bottom && value.bottom>0) margins.bottom=value.bottom;
105      }
106      return(margins);
107    };
108
109  this.equals = function (value)
110    {
111      if(value instanceof CDMargins)
112      {
113        tmp=value.get();
114        if(margins.left==tmp.left &&
115           margins.top==tmp.top &&
116           margins.bottom==tmp.bottom &&
117           margins.right==tmp.right) return(true);
118        return(false);
119      }
120      if(value.left && value.right && value.top && value.bottom)
121      {
122        if(value.left!=margins.left ||
123           value.right!=margins.right ||
124           value.top!=margins.top ||
125           value.bottom!=margins.bottom) return(false);
126        return(true);
127      }
128      return(false);
129    };
130
131  init(values);
132}
133
134/**
135 * axis properties
136 */
137function CDAxis(options, values)
138{
139  var _this=this,
140      properties={
141        mode:'XY',  // 'XY', 'pie'
142        series:[],
143        size:{
144          width:0,
145          height:0
146        },
147        display:{
148          color:'rgba(128,128,128,1)',
149          visible:
150            {
151              XY:{
152                H:true,
153                V:true,
154                cursorH:true,
155                cursorV:true
156              },
157              pie:true
158            }
159        },
160        XY:{
161          ticks:{
162            H:{
163              size:{
164                small:0,
165                big:3
166              },
167              visible:{
168                small:false,
169                big:true
170              },
171              minSpaceLast:5,
172              frequency:{
173                small:0,
174                big:1
175              },
176              value:{
177                rotate:90,
178                visible:true,
179                fontName:'arial',
180                fontSize:8
181              },
182              offset0:false
183            },
184            V:{
185              unit:'',
186              size:{
187                small:1,
188                big:3
189              },
190              visible:{
191                small:true,
192                big:true
193              },
194              minSpaceLast:5,
195              steps:100,
196              frequency:{
197                small:5,
198                big:10
199              },
200              value:{
201                rotate:0,
202                visible:true,
203                fontName:'arial',
204                fontSize:8
205              }
206            }
207          },
208          values:{
209            H:[],
210            minV:0,
211            maxV:100
212          }
213        },
214        pie:{
215          unit:'',
216          innerRadius:0.6,  // between 0 and 1
217          outerRadius:1.5,  // greater than 1
218          fontName:'arial',
219          fontSize:8
220        }
221
222      },
223      data={
224        XY:{
225            H:{
226              space:0,
227              size:0,
228              center:0
229            },
230            V:{
231              space:0,
232              factor:1,
233              size:0,
234              center:0
235            }
236          },
237        pie:{
238            H:{center:0},
239            V:{center:0}
240          }
241      },
242
243    // functions
244      init = function (options)
245        {
246          if($.isPlainObject(options)) _this.set(options);
247        },
248
249      computeData = function ()
250        {
251          data.XY.H.size=properties.size.width-properties.XY.ticks.H.minSpaceLast;
252          data.XY.H.center=Math.round(properties.size.width/2);
253          data.XY.V.size=properties.size.height-properties.XY.ticks.V.minSpaceLast;
254          data.XY.V.center=Math.round(properties.size.height/2);
255
256          if(properties.XY.values.H.length>0)
257          {
258            data.XY.H.space=Math.round((data.XY.H.size-properties.XY.values.H.length)/properties.XY.values.H.length)+1;
259          }
260          else
261          {
262            data.XY.H.space=0;
263          }
264
265
266          data.XY.V.space=Math.floor(10000*data.XY.V.size/properties.XY.ticks.V.steps)/10000;
267          data.XY.V.factor=Math.abs(data.XY.V.size)/properties.XY.ticks.V.steps;
268
269          data.pie.H.center=Math.round(properties.size.width/2);
270          data.pie.V.center=Math.round(properties.size.height/2);
271        },
272
273      serieFind = function (name)
274        {
275          for(var i=0;i<properties.series.length;i++)
276          {
277            if(properties.series[i].get().name==name) return(i);
278          }
279          return(-1);
280        },
281
282      serieSort = function ()
283        {
284          properties.series.sort(serieCompareOrder);
285
286          // calculate cumulative values
287          for(var i=properties.series.length-1;i>=0;i--)
288          {
289            var current=properties.series[i].get().options.get();
290            if(current.mode!=null && current.mode=='cumulative')
291            {
292              properties.series[i].get().options.cumulativeInit(properties.series[i].get().values);
293              for(var j=i-1;j>=0;j--)
294              {
295                var next=properties.series[j].get().options.get();
296                if(next.mode!=null && next.mode=='cumulative')
297                {
298                  properties.series[i].get().options.cumulativeAdd(properties.series[j].get().values);
299                }
300              }
301            }
302          }
303        },
304
305      serieCompareOrder = function (a, b)
306        {
307          aO=a.get().order;
308          bO=b.get().order;
309          if(aO==bO) return(0);
310          return((aO<bO)?-1:1);
311        };
312
313  this.set = function (value)
314    {
315      if(value.mode!=null &&
316         (value.mode=='XY' || value.mode=='pie')
317        ) properties.mode=value.mode;
318
319      if(value.size!=null)
320      {
321        if(value.size.width!=null) properties.size.width=value.size.width;
322        if(value.size.height!=null) properties.size.height=value.size.height;
323      }
324
325      if(value.display!=null)
326      {
327        if(value.display.color!=null) properties.display.color=value.display.color;
328        if(value.display.visible!=null)
329        {
330          if(value.display.visible.XY!=null)
331          {
332            if(value.display.visible.XY.H==true || value.display.visible.XY.H==false) properties.display.visible.XY.H=value.display.visible.XY.H;
333            if(value.display.visible.XY.V==true || value.display.visible.XY.V==false) properties.display.visible.XY.V=value.display.visible.XY.V;
334            if(value.display.visible.XY.cursorH==true || value.display.visible.XY.cursorH==false) properties.display.visible.XY.cursorH=value.display.visible.XY.cursorH;
335            if(value.display.visible.XY.cursorV==true || value.display.visible.XY.cursorV==false) properties.display.visible.XY.cursorV=value.display.visible.XY.cursorV;
336          }
337          if(value.display.visible.pie!=null)
338          {
339            if(value.display.visible.pie==true || value.display.visible.pie==false) properties.display.visible.pie=value.display.visible.pie;
340          }
341
342        }
343      }
344
345      if(value.XY!=null)
346      {
347        if(value.XY.ticks!=null)
348        {
349          if(value.XY.ticks.H!=null)
350          {
351            if(value.XY.ticks.H.size!=null && !$.isPlainObject(value.XY.ticks.H.size))
352            {
353              properties.XY.ticks.H.size.small=value.XY.ticks.H.size;
354              properties.XY.ticks.H.size.big=value.XY.ticks.H.size;
355            }
356            else if(value.XY.ticks.H.size!=null && $.isPlainObject(value.XY.ticks.H.size))
357            {
358              if(value.XY.ticks.H.size.small) properties.XY.ticks.H.size.small=value.XY.ticks.H.size.small;
359              if(value.XY.ticks.H.size.big) properties.XY.ticks.H.size.big=value.XY.ticks.H.size.big;
360            }
361
362            if(value.XY.ticks.H.visible==true || value.XY.ticks.H.visible==false)
363            {
364              properties.XY.ticks.H.visible.small=value.XY.ticks.H.visible;
365              properties.XY.ticks.H.visible.big=value.XY.ticks.H.visible;
366            }
367            else if(value.XY.ticks.H.visible && $.isPlainObject(value.XY.ticks.H.visible))
368            {
369              if(value.XY.ticks.H.visible.small==true || value.XY.ticks.H.visible.small==false) properties.XY.ticks.H.visible.small=value.XY.ticks.H.visible.small;
370              if(value.XY.ticks.H.visible.big==true || value.XY.ticks.H.visible.big==false) properties.XY.ticks.H.visible.big=value.XY.ticks.H.visible.big;
371            }
372
373            if(value.XY.ticks.H.frequency!=null)
374            {
375              if(value.XY.ticks.H.frequency.small!=null) properties.XY.ticks.H.frequency.small=value.XY.ticks.H.frequency.small;
376              if(value.XY.ticks.H.frequency.big!=null) properties.XY.ticks.H.frequency.big=value.XY.ticks.H.frequency.big;
377            }
378
379            if(value.XY.ticks.H.value!=null)
380            {
381              if(value.XY.ticks.H.value.rotate!=null) properties.XY.ticks.H.value.rotate=value.XY.ticks.H.value.rotate%180;
382              if(value.XY.ticks.H.value.visible==true || value.XY.ticks.H.value.visible==false) properties.XY.ticks.H.value.visible=value.XY.ticks.H.value.visible;
383              if(value.XY.ticks.H.value.fontName!=null) properties.XY.ticks.H.value.fontName=value.XY.ticks.H.value.fontName;
384              if(value.XY.ticks.H.value.fontSize!=null) properties.XY.ticks.H.value.fontSize=value.XY.ticks.H.value.fontSize;
385            }
386
387            if(value.XY.ticks.H.minSpaceLast!=null && value.XY.ticks.minSpaceLast>=0) properties.XY.ticks.H.minSpaceLast=value.XY.ticks.H.minSpaceLast;
388            if(value.XY.ticks.H.offset0==true || value.XY.ticks.H.offset0==false) properties.XY.ticks.H.offset0=value.XY.ticks.H.offset0;
389          }
390
391          if(value.XY.ticks.V!=null)
392          {
393            if(value.XY.ticks.V.size!=null && !$.isPlainObject(value.XY.ticks.V.size))
394            {
395              properties.XY.ticks.V.size.small=value.XY.ticks.V.size;
396              properties.XY.ticks.V.size.big=value.XY.ticks.V.size;
397            }
398            else if(value.XY.ticks.V.size!=null)
399            {
400              if(value.XY.ticks.V.size.small!=null) properties.XY.ticks.V.size.small=value.XY.ticks.V.size.small;
401              if(value.XY.ticks.V.size.big!=null) properties.XY.ticks.V.size.big=value.XY.ticks.V.size.big;
402            }
403
404            if(value.XY.ticks.V.visible==true || value.XY.ticks.V.visible==false)
405            {
406              properties.XY.ticks.V.visible.small=value.XY.ticks.V.visible;
407              properties.XY.ticks.V.visible.big=value.XY.ticks.V.visible;
408            }
409            else if(value.XY.ticks.V.visible!=null && $.isPlainObject(value.XY.ticks.V.visible))
410            {
411              if(value.XY.ticks.V.visible.small==true || value.XY.ticks.V.visible.small==false) properties.XY.ticks.V.visible.small=value.XY.ticks.V.visible.small;
412              if(value.XY.ticks.V.visible.big==true || value.XY.ticks.V.visible.big==false) properties.XY.ticks.V.visible.big=value.XY.ticks.V.visible.big;
413            }
414
415            if(value.XY.ticks.V.frequency!=null)
416            {
417              if(value.XY.ticks.V.frequency.small!=null) properties.XY.ticks.V.frequency.small=value.XY.ticks.V.frequency.small;
418              if(value.XY.ticks.V.frequency.big!=null) properties.XY.ticks.V.frequency.big=value.XY.ticks.V.frequency.big;
419            }
420
421            if(value.XY.ticks.V.value!=null)
422            {
423              if(value.XY.ticks.V.value.rotate!=null) properties.XY.ticks.V.value.rotate=value.XY.ticks.V.value.rotate%180;
424              if(value.XY.ticks.V.value.visible==true || value.XY.ticks.V.value.visible==false) properties.XY.ticks.V.value.visible=value.XY.ticks.V.value.visible;
425              if(value.XY.ticks.V.value.fontName!=null) properties.XY.ticks.V.value.fontName=value.XY.ticks.V.value.fontName;
426              if(value.XY.ticks.V.value.fontSize!=null) properties.XY.ticks.V.value.fontSize=value.XY.ticks.V.value.fontSize;
427            }
428
429            if(value.XY.ticks.V.minSpaceLast!=null && value.XY.ticks.V.minSpaceLast>=0) properties.XY.ticks.V.minSpaceLast=value.XY.ticks.V.minSpaceLast;
430            if(value.XY.ticks.V.steps!=null && value.XY.ticks.V.steps>=0) properties.XY.ticks.V.steps=value.XY.ticks.V.steps;
431            if(value.XY.ticks.V.unit!=null) properties.XY.ticks.V.unit=value.XY.ticks.V.unit;
432          }
433        }
434
435        if(value.XY.values) this.setValues(value.XY.values);
436      }
437
438      if(value.pie!=null)
439      {
440        if(value.pie.unit!=null) properties.pie.unit=value.pie.unit;
441
442        if(value.pie.innerRadius!=null && value.pie.innerRadius>=0 && value.pie.innerRadius<=1) properties.pie.innerRadius=value.pie.innerRadius;
443        if(value.pie.outerRadius!=null && value.pie.outerRadius>=1) properties.pie.outerRadius=value.pie.outerRadius;
444
445        if(value.pie.fontName!=null) properties.pie.fontName=value.pie.fontName;
446        if(value.pie.fontSize!=null) properties.pie.fontSize=value.pie.fontSize;
447      }
448
449      if(value.series!=null && $.isArray(value.series))
450        for(var i=0;i<value.series.length;i++)
451        {
452          this.serieAdd(value.series[i]);
453        }
454
455      computeData();
456    };
457
458  this.setValues = function (value)
459    {
460      if(value.H && $.isArray(value.H)) properties.XY.values.H=value.H;
461      value.minV?tmpMin=value.minV:tmpMin=properties.XY.values.minV;
462      value.maxV?tmpMax=value.maxV:tmpMax=properties.XY.values.maxV;
463
464      if(tmpMin>0 && tmpMin<tmpMax) properties.XY.values.minV=tmpMin;
465      if(tmpMax>0 && tmpMin<tmpMax) properties.XY.values.maxV=tmpMax;
466
467      computeData();
468    };
469
470  this.get = function ()
471    {
472      return({properties:properties, data:data});
473    };
474
475  this.getXYHPos = function (index, applyOffset)
476    {
477      var offset=0;
478
479      if(applyOffset==null) applyOffset=true;
480
481      if(applyOffset==true && properties.XY.ticks.H.offset0) offset=0.5;
482      return(Math.round(data.XY.H.space*(index+offset)));
483    };
484
485  this.getXYVPos = function (value)
486    {
487      return(data.XY.V.factor*value);
488    };
489
490  this.getXYVStepPos = function (value)
491    {
492      return(Math.round(data.XY.V.space*value));
493    };
494
495  this.getXYAxisValues = function (x, y)
496    {
497      var H=0,
498          V=0;
499
500      //if(properties.XY.ticks.H.offset0) x+=data.XY.H.space/2;
501      H=(data.XY.H.space==0)?0:Math.floor(x/data.XY.H.space);
502      V=(data.XY.V.space==0)?0:y/data.XY.V.space;
503
504      return({H:H, V:V});
505    };
506
507  /**
508   * Add a serie to the axis; the serie type must be compatible with the axis mode
509   * Note: the serie name is unique for an axis; if the serie name already exist,
510   * she won't be added
511   *
512   * @param CDSerie serie: the serie to Add
513   * @return boolean: true if serie was added otherwise false
514   */
515  this.serieAdd = function (serie)
516    {
517      var index=-1,
518          serieType='';
519
520      if(serie instanceof CDSerie)
521      {
522        serieType=serie.get().options.get().type;
523
524        if(
525           (properties.mode=='XY' &&
526             (serieType=='bar' ||
527              serieType=='area' ||
528              serieType=='line')
529           ) ||
530           (properties.mode=='pie' && serieType=='pie')
531          )
532        {
533          index=serieFind(serie.get().name);
534          if(index==-1)
535          {
536            properties.series.push(serie);
537            serieSort();
538            return(true);
539          }
540        }
541      }
542      return(false);
543    };
544
545  this.serieGet = function (serieName)
546    {
547      var index=-1;
548
549      if(serieName instanceof CDSerie)
550      {
551        serieName=serieName.get().name;
552      }
553      if(serieName!=null)
554      {
555        index=serieFind(serieName);
556        if(index>=0) return(properties.series[index]);
557      }
558      return(properties.series);
559    };
560
561  this.serieDelete = function (serie)
562    {
563      var index=-1;
564
565      if(serieName instanceof CDSerie)
566      {
567        serieName=serieName.get().name;
568      }
569      if(serieName!=null)
570      {
571        index=serieFind(serieName);
572        if(index>=0)
573        {
574          properties.series.splice(index, 1);
575          serieSort();
576          return(true);
577        }
578      }
579      return(false);
580    };
581
582  init(options, values);
583}
584
585
586function CDSerie(initProperties)
587{
588  var _this=this,
589      properties={
590        name:'',
591        order:0,
592        values:[],
593        valuesLabels:[],
594        options:{ }
595      },
596
597    init = function (values)
598      {
599        _this.set(values);
600      };
601
602
603  this.set = function (values)
604    {
605      if(!$.isPlainObject(values)) return(false);
606
607      if(values.name!=null) properties.name=values.name;
608      if(values.order!=null && values.order>=0) properties.order=values.order;
609
610      if(values.values!=null && $.isArray(values.values)) properties.values=values.values;
611
612      if(values.valuesLabels!=null && $.isArray(values.valuesLabels))
613      {
614        properties.valuesLabels=values.valuesLabels;
615      }
616
617      if(properties.valuesLabels.length>properties.values.length)
618      {
619        properties.valuesLabels.splice(properties.values.length);
620      }
621      else if(properties.valuesLabels.length<properties.values.length)
622      {
623        var nb=properties.values.length-properties.valuesLabels.length;
624
625        for(var i=0;i<nb;i++)
626        {
627          properties.valuesLabels.push('');
628        }
629      }
630
631      if(values.options!=null &&
632         (values.options instanceof CDSerieOptionsBar ||
633          values.options instanceof CDSerieOptionsArea ||
634          values.options instanceof CDSerieOptionsLine ||
635          values.options instanceof CDSerieOptionsPie)
636        )
637      {
638        delete properties.options;
639        properties.options=values.options;
640      }
641
642      return(true);
643    };
644
645  this.get = function ()
646    {
647      return(properties);
648    }
649
650  init(initProperties);
651}
652
653function CDSerieOptionsBar(initProperties)
654{
655  var _this=this,
656      properties={
657        type:'bar',
658        mode:'normal',        // normal, cumulative
659        backgroundColor:'#ccccff',
660        borderColor:'#ffffff',
661        borderWidth:1,
662        width:1,          // bar width in percentage; 1=100%
663        offset:0,         // x offset applied to display the bar
664        cumulativesValues:[]
665      },
666
667    init = function (values)
668      {
669        _this.set(values);
670      };
671
672  this.set = function (values)
673    {
674      if(!$.isPlainObject(values)) return(false);
675
676      if(values.mode=='normal' || values.mode=='cumulative') properties.mode=values.mode;
677      if(values.backgroundColor!=null) properties.backgroundColor=values.backgroundColor;
678      if(values.borderColor!=null) properties.borderColor=values.borderColor;
679      if(values.borderWidth!=null && values.borderWidth>=0) properties.borderWidth=values.borderWidth;
680
681      if(values.width) properties.width=values.width;
682      if(values.offset) properties.offset=values.offset;
683
684      return(true);
685    };
686
687  this.cumulativeInit = function (values)
688    {
689      if(!$.isArray(values)) return(properties.cumulativesValues);
690      properties.cumulativesValues=[];
691      for(var i=0;i<values.length;i++)
692      {
693        properties.cumulativesValues.push(values[i]);
694      }
695      return(properties.cumulativesValues);
696    };
697  this.cumulativeAdd = function (values)
698    {
699      if(values.length!=properties.cumulativesValues.length) return(properties.cumulativesValues);
700      for(var i=0;i<properties.cumulativesValues.length;i++)
701      {
702        properties.cumulativesValues[i]+=values[i];
703      }
704      return(properties.cumulativesValues);
705    };
706  this.cumulativeGet = function ()
707    {
708      return(properties.cumulativesValues);
709    };
710
711  this.get = function ()
712    {
713      return(properties);
714    };
715
716  init(initProperties);
717}
718
719function CDSerieOptionsArea(initProperties)
720{
721  var _this=this,
722      properties={
723        type:'area',
724        mode:'normal',        // normal, cumulative
725        backgroundColor:'#ccccff',
726        borderColor:'#ffffff',
727        borderWidth:1,
728        cumulativesValues:[]
729      },
730
731    init = function (values)
732      {
733        _this.set(values);
734      };
735
736  this.set = function (values)
737    {
738      if(!$.isPlainObject(values)) return(false);
739
740      if(values.mode=='normal' || values.mode=='cumulative') properties.mode=values.mode;
741      if(values.backgroundColor!=null) properties.backgroundColor=values.backgroundColor;
742      if(values.borderColor!=null) properties.borderColor=values.borderColor;
743      if(values.borderWidth!=null && values.borderWidth>=0) properties.borderWidth=values.borderWidth;
744
745      return(true);
746    };
747
748  this.cumulativeInit = function (values)
749    {
750      if(!$.isArray(values)) return(properties.cumulativesValues);
751      properties.cumulativesValues=values;
752      return(properties.cumulativesValues);
753    };
754  this.cumulativeAdd = function (values)
755    {
756      if(values.length!=properties.cumulativesValues.length) return(properties.cumulativesValues);
757      for(var i=0;i<properties.cumulativesValues.length;i++)
758      {
759        properties.cumulativesValues[i]+=values[i];
760      }
761      return(properties.cumulativesValues);
762    };
763  this.cumulativeGet = function ()
764    {
765      return(properties.cumulativesValues);
766    };
767
768  this.get = function ()
769    {
770      return(properties);
771    };
772
773  init(initProperties);
774}
775
776function CDSerieOptionsLine(initProperties)
777{
778  var _this=this,
779      properties={
780        type:'line',
781        color:'#ffff00',
782        width:1,
783        dot:'none',   // none, circle, square, diamong
784        dotSize:3
785      },
786
787    init = function (values)
788      {
789        _this.set(values);
790      };
791
792  this.set = function (values)
793    {
794      if(!$.isPlainObject(values)) return(false);
795
796      if(values.mode=='normal' || values.mode=='cumulative') properties.mode=values.mode;
797      if(values.color!=null) properties.color=values.color;
798      if(values.width!=null) properties.width=values.width;
799      if(values.dot=='none' ||
800         values.dot=='square' ||
801         values.dot=='circle' ||
802         values.dot=='diamond'
803        ) properties.dot=values.dot;
804
805      if(values.dotSize!=null && values.dotSize>1) properties.dotSize=values.dotSize;
806
807      return(true);
808    }
809
810  this.get = function ()
811    {
812      return(properties);
813    }
814
815  init(initProperties);
816}
817
818function CDSerieOptionsPie(initProperties)
819{
820  var _this=this,
821      properties={
822        type:'pie',
823        backgroundColors:
824          ['#FF96A1',
825           '#A796FF',
826           '#96FF97',
827           '#FFFE96',
828           '#FF96DA',
829           '#96C8FF',
830           '#AEFF96',
831           '#FF9896',
832           '#C096FF',
833           '#96FFFD',
834           '#D4FF96'],
835        borderColor:'#ffffff',
836        borderWidth:2,
837        outerRadius:50,
838        innerRadius:0,
839        offset:0        // exploded pie or not..
840      },
841
842    init = function (values)
843      {
844        _this.set(values);
845      };
846
847  this.set = function (values)
848    {
849      var tmpIRadius=0,
850          tmpORadius=0;
851
852      if(!$.isPlainObject(values)) return(false);
853
854      if(values.backgroundColors!=null && $.isArray(values.backgroundColors)) properties.backgroundColors=values.backgroundColors;
855      if(values.borderColor!=null) properties.borderColor=values.borderColor;
856      if(values.borderWidth!=null && values.borderWidth>=0) properties.borderWidth=values.borderWidth;
857
858      tmpORadius=(values.outerRadius!=null)?values.outerRadius:properties.outerRadius;
859      tmpIRadius=(values.innerRadius!=null)?values.innerRadius:properties.innerRadius;
860
861      if(tmpORadius>0 && tmpORadius>tmpIRadius) properties.outerRadius=tmpORadius;
862      if(tmpIRadius>=0 && tmpIRadius<tmpORadius) properties.innerRadius=tmpIRadius;
863      if(values.offset!=null && values.offset>0) properties.offset=values.offset;
864
865      return(true);
866    }
867
868  this.get = function ()
869    {
870      return(properties);
871    }
872
873  init(initProperties);
874}
875
876
877
878
879/**
880 * legend
881 */
882function CDLegend(values)
883{
884  var _this=this,
885      properties={
886        width:0,
887        visible:true,
888        position:'right',  // left or right
889        backgroundColor:'#101010',
890        borderColor:'#ffffff',
891        borderWidth:1,
892        fontName:'arial',
893        fontSize:8
894      },
895      data={
896        realWidth:0
897      };
898
899  init = function (values)
900    {
901      _this.set(values);
902    };
903
904  this.get = function ()
905    {
906      return(properties);
907    };
908
909  this.set = function (value)
910    {
911      if(value instanceof CDLegend)
912      {
913        tmp=value.get();
914        properties.fontName=tmp.fontName;
915        properties.fontSize=tmp.fontSize;
916        properties.width=tmp.width;
917        properties.visible=tmp.visible;
918        properties.position=tmp.position;
919        properties.backgroundColor=tmp.backgroundColor;
920        properties.borderColor=tmp.borderColor;
921        properties.borderWidth=tmp.borderWidth;
922
923        data.realWidth=value.width;
924        return(properties);
925      }
926      if($.isPlainObject(value))
927      {
928        if(value.fontName!=null && value.fontName!='') properties.fontName=value.fontName;
929        if(value.fontSize!=null && value.fontSize>0) properties.fontSize=value.fontSize;
930        if(value.width!=null && value.width>0)
931        {
932          properties.width=value.width;
933          data.realWidth=value.width;
934        }
935        if(value.visible!=null) properties.visible=value.visible;
936        if(value.position!=null && (value.position=='left' || value.position=='right')) properties.position=value.position;
937        if(value.backgroundColor!=null) properties.backgroundColor=value.backgroundColor;
938        if(value.borderColor!=null) properties.borderColor=value.borderColor;
939        if(value.borderWidth!=null && value.borderWidth>=0) properties.borderWidth=value.borderWidth;
940      }
941      return(properties);
942    };
943
944  this.equals = function (value)
945    {
946      if(value instanceof CDLegend)
947      {
948        tmp=value.get();
949        if(properties.fontName==tmp.fontName &&
950           properties.fontSize==tmp.fontSize &&
951           properties.width==tmp.width &&
952           properties.visible==tmp.visible &&
953           properties.position==tmp.position &&
954           properties.backgroundColor==tmp.backgroundColor &&
955           properties.borderColor==tmp.borderColor &&
956           properties.borderWidth==tmp.borderWidth) return(true);
957        return(false);
958      }
959      if(value.fontName!=null &&
960         value.fontSize!=null &&
961         value.width!=null &&
962         value.visible!=null &&
963         value.position!=null &&
964         value.backgroundColor!=null &&
965         value.borderColor!=null &&
966         value.borderWidth!=null &&
967
968         value.fontName==properties.fontName &&
969         value.fontSize==properties.fontSize &&
970         value.width==properties.width &&
971         value.visible==properties.visible &&
972         value.position==properties.position &&
973         value.backgroundColor==properties.backgroundColor &&
974         value.borderColor==properties.borderColor &&
975         value.borderWidth==properties.borderWidth
976        )
977        return(true);
978      return(false);
979    };
980
981  this.getRealWidth = function ()
982    {
983      return(data.realWidth);
984    };
985
986  this.setRealWidth = function (value)
987    {
988      if(properties.width==0 && value>=0) data.realWidth=value;
989      return(data.realWidth);
990    };
991
992
993  init(values);
994}
995
Note: See TracBrowser for help on using the repository browser.