1 | package charts {
|
---|
2 |
|
---|
3 | import flash.events.Event;
|
---|
4 | import flash.events.MouseEvent;
|
---|
5 | import charts.series.Element;
|
---|
6 | import charts.series.dots.scat;
|
---|
7 | import string.Utils;
|
---|
8 | import flash.geom.Point;
|
---|
9 | import flash.display.Sprite;
|
---|
10 | import flash.display.BlendMode;
|
---|
11 | import charts.series.dots.DefaultDotProperties;
|
---|
12 |
|
---|
13 |
|
---|
14 | public class ScatterLine extends ScatterBase
|
---|
15 | {
|
---|
16 | public var stepgraph:Number = 0;
|
---|
17 | public static const STEP_HORIZONTAL:Number = 1;
|
---|
18 | public static const STEP_VERTICAL:Number = 2;
|
---|
19 |
|
---|
20 | public function ScatterLine( json:Object )
|
---|
21 | {
|
---|
22 | super(json);
|
---|
23 | //
|
---|
24 | // so the mask child can punch a hole through the line
|
---|
25 | //
|
---|
26 | this.blendMode = BlendMode.LAYER;
|
---|
27 | //
|
---|
28 |
|
---|
29 | this.style = {
|
---|
30 | values: [],
|
---|
31 | width: 2,
|
---|
32 | colour: '#3030d0',
|
---|
33 | text: '', // <-- default not display a key
|
---|
34 | 'font-size': 12,
|
---|
35 | stepgraph: 0,
|
---|
36 | axis: 'left'
|
---|
37 | };
|
---|
38 |
|
---|
39 | // hack: keep this incase the merge kills it, we'll
|
---|
40 | // remove the merge later (and this hack)
|
---|
41 | var tmp:Object = json['dot-style'];
|
---|
42 |
|
---|
43 | object_helper.merge_2( json, style );
|
---|
44 |
|
---|
45 | this.default_style = new DefaultDotProperties(
|
---|
46 | json['dot-style'], this.style.colour, this.style.axis);
|
---|
47 |
|
---|
48 | this.style.colour = string.Utils.get_colour( style.colour );
|
---|
49 |
|
---|
50 | this.line_width = style.width;
|
---|
51 | this.colour = this.style.colour;
|
---|
52 | this.key = style.text;
|
---|
53 | this.font_size = style['font-size'];
|
---|
54 | //this.circle_size = style['dot-size'];
|
---|
55 |
|
---|
56 | switch (style['stepgraph']) {
|
---|
57 | case 'horizontal':
|
---|
58 | stepgraph = STEP_HORIZONTAL;
|
---|
59 | break;
|
---|
60 | case 'vertical':
|
---|
61 | stepgraph = STEP_VERTICAL;
|
---|
62 | break;
|
---|
63 | }
|
---|
64 |
|
---|
65 | this.values = style.values;
|
---|
66 | this.add_values();
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|
71 | // Draw points...
|
---|
72 | public override function resize( sc:ScreenCoordsBase ): void {
|
---|
73 |
|
---|
74 | // move the dots:
|
---|
75 | super.resize( sc );
|
---|
76 |
|
---|
77 | this.graphics.clear();
|
---|
78 | this.graphics.lineStyle( this.style.width, this.style.colour );
|
---|
79 |
|
---|
80 | //if( this.style['line-style'].style != 'solid' )
|
---|
81 | // this.dash_line(sc);
|
---|
82 | //else
|
---|
83 | this.solid_line(sc);
|
---|
84 |
|
---|
85 | }
|
---|
86 |
|
---|
87 | //
|
---|
88 | // This is cut and paste from LineBase
|
---|
89 | //
|
---|
90 | public function solid_line( sc:ScreenCoordsBase ): void {
|
---|
91 |
|
---|
92 | var first:Boolean = true;
|
---|
93 | var last_x:Number = 0;
|
---|
94 | var last_y:Number = 0;
|
---|
95 |
|
---|
96 | var areaClosed:Boolean = true;
|
---|
97 | var isArea:Boolean = false;
|
---|
98 | var areaBaseX:Number = NaN;
|
---|
99 | var areaBaseY:Number = NaN;
|
---|
100 | var areaColour:Number = this.colour;
|
---|
101 | var areaAlpha:Number = 0.4;
|
---|
102 | var areaStyle:Object = this.style['area-style'];
|
---|
103 | if (areaStyle != null)
|
---|
104 | {
|
---|
105 | isArea = true;
|
---|
106 | if (areaStyle.x != null)
|
---|
107 | {
|
---|
108 | areaBaseX = areaStyle.x;
|
---|
109 | }
|
---|
110 | if (areaStyle.y != null)
|
---|
111 | {
|
---|
112 | areaBaseY = areaStyle.y;
|
---|
113 | }
|
---|
114 | if (areaStyle.colour != null)
|
---|
115 | {
|
---|
116 | areaColour = string.Utils.get_colour( areaStyle.colour );
|
---|
117 | }
|
---|
118 | if (areaStyle.alpha != null)
|
---|
119 | {
|
---|
120 | areaAlpha = areaStyle.alpha;
|
---|
121 | }
|
---|
122 | if (!isNaN(areaBaseX))
|
---|
123 | {
|
---|
124 | // Convert X Value to screen position
|
---|
125 | areaBaseX = sc.get_x_from_val(areaBaseX);
|
---|
126 | }
|
---|
127 | if (!isNaN(areaBaseY))
|
---|
128 | {
|
---|
129 | // Convert Y Value to screen position
|
---|
130 | areaBaseY = sc.get_y_from_val(areaBaseY); // TODO: Allow for right Y-Axis??
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | for ( var i:Number = 0; i < this.numChildren; i++ ) {
|
---|
135 |
|
---|
136 | var tmp:Sprite = this.getChildAt(i) as Sprite;
|
---|
137 |
|
---|
138 | //
|
---|
139 | // filter out the line masks
|
---|
140 | //
|
---|
141 | if( tmp is Element )
|
---|
142 | {
|
---|
143 | var e:Element = tmp as Element;
|
---|
144 |
|
---|
145 | // tell the point where it is on the screen
|
---|
146 | // we will use this info to place the tooltip
|
---|
147 | e.resize( sc );
|
---|
148 | if (!e.visible)
|
---|
149 | {
|
---|
150 | // Creates a gap in the plot and closes out the current area if defined
|
---|
151 | if ((isArea) && (i > 0))
|
---|
152 | {
|
---|
153 | // draw an invisible line back to the base and close the fill
|
---|
154 | areaX = isNaN(areaBaseX) ? last_x : areaBaseX;
|
---|
155 | areaY = isNaN(areaBaseY) ? last_y : areaBaseY;
|
---|
156 | this.graphics.lineStyle( 0, areaColour, 0 );
|
---|
157 | this.graphics.lineTo(areaX, areaY);
|
---|
158 | this.graphics.endFill();
|
---|
159 | areaClosed = true;
|
---|
160 | }
|
---|
161 | first = true;
|
---|
162 | }
|
---|
163 | else if( first )
|
---|
164 | {
|
---|
165 | if (isArea)
|
---|
166 | {
|
---|
167 | // draw an invisible line from the base to the point
|
---|
168 | var areaX:Number = isNaN(areaBaseX) ? e.x : areaBaseX;
|
---|
169 | var areaY:Number = isNaN(areaBaseY) ? e.y : areaBaseY;
|
---|
170 | // Begin the fill for the area
|
---|
171 | this.graphics.beginFill(areaColour, areaAlpha);
|
---|
172 | this.graphics.lineStyle( 0, areaColour, 0 );
|
---|
173 | this.graphics.moveTo(areaX, areaY);
|
---|
174 | this.graphics.lineTo(e.x, e.y);
|
---|
175 | areaClosed = false;
|
---|
176 | // change the line style back to normal
|
---|
177 | this.graphics.lineStyle( this.style.width, this.style.colour, 1.0 );
|
---|
178 | }
|
---|
179 | else
|
---|
180 | {
|
---|
181 | // just move to the point
|
---|
182 | this.graphics.moveTo(e.x, e.y);
|
---|
183 | }
|
---|
184 | first = false;
|
---|
185 | }
|
---|
186 | else
|
---|
187 | {
|
---|
188 | if (this.stepgraph == STEP_HORIZONTAL)
|
---|
189 | this.graphics.lineTo(e.x, last_y);
|
---|
190 | else if (this.stepgraph == STEP_VERTICAL)
|
---|
191 | this.graphics.lineTo(last_x, e.y);
|
---|
192 |
|
---|
193 | this.graphics.lineTo(e.x, e.y);
|
---|
194 | }
|
---|
195 | last_x = e.x;
|
---|
196 | last_y = e.y;
|
---|
197 | }
|
---|
198 | }
|
---|
199 |
|
---|
200 | // Close out the area if defined
|
---|
201 | if (isArea && !areaClosed)
|
---|
202 | {
|
---|
203 | // draw an invisible line back to the base and close the fill
|
---|
204 | areaX = isNaN(areaBaseX) ? last_x : areaBaseX;
|
---|
205 | areaY = isNaN(areaBaseY) ? last_y : areaBaseY;
|
---|
206 | this.graphics.lineStyle( 0, areaColour, 0 );
|
---|
207 | this.graphics.lineTo(areaX, areaY);
|
---|
208 | this.graphics.endFill();
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | }
|
---|
213 | }
|
---|