source: code/Website/open-flash-chart/charts/BarStack.as

Last change on this file was 7849, checked in by dennisw, 15 years ago
File size: 2.8 KB
Line 
1package charts {
2 import charts.series.Element;
3 import charts.series.bars.StackCollection;
4 import string.Utils;
5 import com.serialization.json.JSON;
6 import flash.geom.Point;
7
8
9 public class BarStack extends BarBase {
10
11 public function BarStack( json:Object, num:Number, group:Number ) {
12
13 // don't let the parent do anything, we just want to
14 // use some of the more useful methods
15 super( { }, 0);
16
17 // now do all the setup
18 var root:Properties = new Properties( {
19 values: [],
20 keys: [],
21 colours: ['#FF0000','#00FF00'], // <-- ugly default colours
22 text: '', // <-- default not display a key
23 'font-size': 12,
24 tip: '#x_label# : #val#<br>Total: #total#',
25 alpha: 0.6,
26 'on-click': false,
27 'axis': 'left'
28 } );
29
30 this.props = new Properties(json, root);
31
32 this.on_show = this.get_on_show(json['on-show']);
33 //
34 // bars are grouped, so 3 bar sets on one chart
35 // will arrange them selves next to each other
36 // at each value of X, this.group tell the bar
37 // where it is in that grouping
38 //
39 this.group = group;
40
41 this.values = json.values;
42
43 this.add_values();
44 }
45
46 //
47 // return an array of key info objects:
48 //
49 public override function get_keys(): Object {
50
51 var tmp:Array = [];
52
53 for each( var o:Object in this.props.get('keys') ) {
54 if ( o.text && o['font-size'] && o.colour ) {
55 o.colour = string.Utils.get_colour( o.colour );
56 tmp.push( o );
57 }
58 }
59
60 return tmp;
61 }
62
63 //
64 // value is an array (a stack) of bar stacks
65 //
66 protected override function get_element( index:Number, value:Object ): Element {
67
68 //
69 // this is the style for a stack:
70 //
71 var default_style:Properties = new Properties({
72 colours: this.props.get('colours'),
73 tip: this.props.get('tip'),
74 alpha: this.props.get('alpha'),
75 'on-click': this.props.get('on-click'),
76 axis: this.props.get('axis'),
77 'on-show': this.on_show,
78 values: value
79 });
80
81 return new StackCollection( index, default_style, this.group );
82 }
83
84
85 //
86 // get all the Elements at this X position
87 //
88 protected override function get_all_at_this_x_pos( x:Number ):Array {
89
90 var tmp:Array = new Array();
91 var p:flash.geom.Point;
92 var e:StackCollection;
93
94 for ( var i:Number = 0; i < this.numChildren; i++ ) {
95
96 // some of the children will will mask
97 // Sprites, so filter those out:
98 //
99 if( this.getChildAt(i) is Element ) {
100
101 e = this.getChildAt(i) as StackCollection;
102
103 p = e.get_mid_point();
104 if ( p.x == x ) {
105 var children:Array = e.get_children();
106 for each( var child:Element in children )
107 tmp.push( child );
108 }
109 }
110 }
111
112 return tmp;
113 }
114 }
115}
Note: See TracBrowser for help on using the repository browser.