| 1 | package charts.series.dots {
|
|---|
| 2 |
|
|---|
| 3 | import flash.display.Sprite;
|
|---|
| 4 | import charts.series.Element;
|
|---|
| 5 | import flash.display.BlendMode;
|
|---|
| 6 | import flash.events.Event;
|
|---|
| 7 | import flash.events.MouseEvent;
|
|---|
| 8 | import flash.geom.Point;
|
|---|
| 9 | import caurina.transitions.Tweener;
|
|---|
| 10 | import caurina.transitions.Equations;
|
|---|
| 11 | import string.DateUtils;
|
|---|
| 12 |
|
|---|
| 13 | public class PointDotBase extends Element {
|
|---|
| 14 |
|
|---|
| 15 | protected var radius:Number;
|
|---|
| 16 | protected var colour:Number;
|
|---|
| 17 | private var on_show_animate:Boolean;
|
|---|
| 18 | protected var on_show:Properties;
|
|---|
| 19 |
|
|---|
| 20 | public function PointDotBase( index:Number, props:Properties ) {
|
|---|
| 21 |
|
|---|
| 22 | super();
|
|---|
| 23 | this.is_tip = false;
|
|---|
| 24 | this.visible = true;
|
|---|
| 25 | this.on_show_animate = true;
|
|---|
| 26 | this.on_show = props.get('on-show');
|
|---|
| 27 |
|
|---|
| 28 | /*
|
|---|
| 29 | this.on_show = new Properties( {
|
|---|
| 30 | type: "",
|
|---|
| 31 | cascade: 3,
|
|---|
| 32 | delay: 0
|
|---|
| 33 | });
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | // line charts have a value and no X, scatter charts have
|
|---|
| 37 | // x, y (not value): radar charts have value, Y does not
|
|---|
| 38 | // make sense.
|
|---|
| 39 | if( !props.has('y') )
|
|---|
| 40 | props.set('y', props.get('value'));
|
|---|
| 41 |
|
|---|
| 42 | this._y = props.get('y');
|
|---|
| 43 |
|
|---|
| 44 | // no X passed in so calculate it from the index
|
|---|
| 45 | if( !props.has('x') )
|
|---|
| 46 | {
|
|---|
| 47 | this.index = this._x = index;
|
|---|
| 48 | }
|
|---|
| 49 | else
|
|---|
| 50 | {
|
|---|
| 51 | // tr.aces( 'x', props.get('x') );
|
|---|
| 52 | this._x = props.get('x');
|
|---|
| 53 | this.index = Number.MIN_VALUE;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | this.radius = props.get('dot-size');
|
|---|
| 57 | this.tooltip = this.replace_magic_values( props.get('tip') );
|
|---|
| 58 |
|
|---|
| 59 | if ( props.has('on-click') )
|
|---|
| 60 | this.set_on_click( props.get('on-click') );
|
|---|
| 61 |
|
|---|
| 62 | //
|
|---|
| 63 | // TODO: fix this hack
|
|---|
| 64 | //
|
|---|
| 65 | if ( props.has('axis') )
|
|---|
| 66 | if ( props.get('axis') == 'right' )
|
|---|
| 67 | this.right_axis = true;
|
|---|
| 68 |
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | public override function resize( sc:ScreenCoordsBase ): void {
|
|---|
| 72 |
|
|---|
| 73 | var x:Number;
|
|---|
| 74 | var y:Number;
|
|---|
| 75 |
|
|---|
| 76 | if ( this.index != Number.MIN_VALUE ) {
|
|---|
| 77 |
|
|---|
| 78 | var p:flash.geom.Point = sc.get_get_x_from_pos_and_y_from_val( this.index, this._y, this.right_axis );
|
|---|
| 79 | x = p.x;
|
|---|
| 80 | y = p.y;
|
|---|
| 81 | }
|
|---|
| 82 | else
|
|---|
| 83 | {
|
|---|
| 84 |
|
|---|
| 85 | //
|
|---|
| 86 | // Look: we have a real X value, so get its screen location:
|
|---|
| 87 | //
|
|---|
| 88 | x = sc.get_x_from_val( this._x );
|
|---|
| 89 | y = sc.get_y_from_val( this._y, this.right_axis );
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | // Move the mask so it is in the proper place also
|
|---|
| 93 | // this all needs to be moved into the base class
|
|---|
| 94 | if (this.line_mask != null)
|
|---|
| 95 | {
|
|---|
| 96 | this.line_mask.x = x;
|
|---|
| 97 | this.line_mask.y = y;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | if ( this.on_show_animate )
|
|---|
| 101 | this.first_show(x, y, sc);
|
|---|
| 102 | else {
|
|---|
| 103 | //
|
|---|
| 104 | // move the Sprite to the correct screen location:
|
|---|
| 105 | //
|
|---|
| 106 | this.y = y;
|
|---|
| 107 | this.x = x;
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | public function is_tweening(): Boolean {
|
|---|
| 112 | return Tweener.isTweening(this);
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | protected function first_show(x:Number, y:Number, sc:ScreenCoordsBase): void {
|
|---|
| 116 |
|
|---|
| 117 | this.on_show_animate = false;
|
|---|
| 118 | Tweener.removeTweens(this);
|
|---|
| 119 |
|
|---|
| 120 | // tr.aces('base.as', this.on_show.get('type') );
|
|---|
| 121 | var d:Number = x / this.stage.stageWidth;
|
|---|
| 122 | d *= this.on_show.get('cascade');
|
|---|
| 123 | d += this.on_show.get('delay');
|
|---|
| 124 |
|
|---|
| 125 | switch( this.on_show.get('type') ) {
|
|---|
| 126 |
|
|---|
| 127 | case 'pop-up':
|
|---|
| 128 | this.x = x;
|
|---|
| 129 | this.y = sc.get_y_bottom(this.right_axis);
|
|---|
| 130 | Tweener.addTween(this, { y:y, time:1.4, delay:d, transition:Equations.easeOutQuad } );
|
|---|
| 131 |
|
|---|
| 132 | if ( this.line_mask != null )
|
|---|
| 133 | {
|
|---|
| 134 | this.line_mask.x = x;
|
|---|
| 135 | this.line_mask.y = sc.get_y_bottom(this.right_axis);
|
|---|
| 136 | Tweener.addTween(this.line_mask, { y:y, time:1.4, delay:d, transition:Equations.easeOutQuad });
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | break;
|
|---|
| 140 |
|
|---|
| 141 | case 'explode':
|
|---|
| 142 | this.x = this.stage.stageWidth/2;
|
|---|
| 143 | this.y = this.stage.stageHeight/2;
|
|---|
| 144 | Tweener.addTween(this, { y:y, x:x, time:1.4, delay:d, transition:Equations.easeOutQuad } );
|
|---|
| 145 |
|
|---|
| 146 | if ( this.line_mask != null )
|
|---|
| 147 | {
|
|---|
| 148 | this.line_mask.x = this.stage.stageWidth/2;
|
|---|
| 149 | this.line_mask.y = this.stage.stageHeight/2;
|
|---|
| 150 | Tweener.addTween(this.line_mask, { y:y, x:x, time:1.4, delay:d, transition:Equations.easeOutQuad });
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | break;
|
|---|
| 154 |
|
|---|
| 155 | case 'mid-slide':
|
|---|
| 156 | this.x = x;
|
|---|
| 157 | this.y = this.stage.stageHeight / 2;
|
|---|
| 158 | this.alpha = 0.2;
|
|---|
| 159 | Tweener.addTween(this, { alpha:1, y:y, time:1.4, delay:d, transition:Equations.easeOutQuad });
|
|---|
| 160 |
|
|---|
| 161 | if ( this.line_mask != null )
|
|---|
| 162 | {
|
|---|
| 163 | this.line_mask.x = x;
|
|---|
| 164 | this.line_mask.y = this.stage.stageHeight / 2;
|
|---|
| 165 | Tweener.addTween(this.line_mask, { y:y, time:1.4, delay:d, transition:Equations.easeOutQuad });
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | break;
|
|---|
| 169 |
|
|---|
| 170 | /*
|
|---|
| 171 | * the tooltips go a bit funny with this one
|
|---|
| 172 | * TODO: investigate if this will work with area charts - need to move the bottom anchors
|
|---|
| 173 | case 'slide-in-up':
|
|---|
| 174 | this.x = 20; // <-- left
|
|---|
| 175 | this.y = this.stage.stageHeight / 2;
|
|---|
| 176 | Tweener.addTween(
|
|---|
| 177 | this,
|
|---|
| 178 | { x:x, time:1.4, delay:d, transition:Equations.easeOutQuad,
|
|---|
| 179 | onComplete:function():void {
|
|---|
| 180 | Tweener.addTween(this,
|
|---|
| 181 | { y:y, time:1.4, transition:Equations.easeOutQuad } ) }
|
|---|
| 182 | } );
|
|---|
| 183 | break;
|
|---|
| 184 | */
|
|---|
| 185 |
|
|---|
| 186 | case 'drop':
|
|---|
| 187 | this.x = x;
|
|---|
| 188 | this.y = -height - 10;
|
|---|
| 189 | Tweener.addTween(this, { y:y, time:1.4, delay:d, transition:Equations.easeOutBounce } );
|
|---|
| 190 |
|
|---|
| 191 | if ( this.line_mask != null )
|
|---|
| 192 | {
|
|---|
| 193 | this.line_mask.x = x;
|
|---|
| 194 | this.line_mask.y = -height - 10;
|
|---|
| 195 | Tweener.addTween(this.line_mask, { y:y, time:1.4, delay:d, transition:Equations.easeOutQuad });
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | break;
|
|---|
| 199 |
|
|---|
| 200 | case 'fade-in':
|
|---|
| 201 | this.x = x;
|
|---|
| 202 | this.y = y;
|
|---|
| 203 | this.alpha = 0;
|
|---|
| 204 | Tweener.addTween(this, { alpha:1, time:1.2, delay:d, transition:Equations.easeOutQuad } );
|
|---|
| 205 | break;
|
|---|
| 206 |
|
|---|
| 207 | case 'shrink-in':
|
|---|
| 208 | this.x = x;
|
|---|
| 209 | this.y = y;
|
|---|
| 210 | this.scaleX = this.scaleY = 5;
|
|---|
| 211 | this.alpha = 0;
|
|---|
| 212 | Tweener.addTween(
|
|---|
| 213 | this,
|
|---|
| 214 | {
|
|---|
| 215 | scaleX:1, scaleY:1, alpha:1, time:1.2,
|
|---|
| 216 | delay:d, transition:Equations.easeOutQuad,
|
|---|
| 217 | onComplete:function():void { tr.ace('Fin'); }
|
|---|
| 218 | } );
|
|---|
| 219 |
|
|---|
| 220 | break;
|
|---|
| 221 |
|
|---|
| 222 | default:
|
|---|
| 223 | this.y = y;
|
|---|
| 224 | this.x = x;
|
|---|
| 225 | }
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | public override function set_tip( b:Boolean ):void {
|
|---|
| 229 | //this.visible = b;
|
|---|
| 230 | if( b ) {
|
|---|
| 231 | this.scaleY = this.scaleX = 1.3;
|
|---|
| 232 | this.line_mask.scaleY = this.line_mask.scaleX = 1.3;
|
|---|
| 233 | }
|
|---|
| 234 | else {
|
|---|
| 235 | this.scaleY = this.scaleX = 1;
|
|---|
| 236 | this.line_mask.scaleY = this.line_mask.scaleX = 1;
|
|---|
| 237 | }
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | //
|
|---|
| 241 | // Dirty hack. Takes tooltip text, and replaces the #val# with the
|
|---|
| 242 | // tool_tip text, so noew you can do: "My Val = $#val#%", which turns into:
|
|---|
| 243 | // "My Val = $12.00%"
|
|---|
| 244 | //
|
|---|
| 245 | protected function replace_magic_values( t:String ): String {
|
|---|
| 246 |
|
|---|
| 247 | t = t.replace('#val#', NumberUtils.formatNumber( this._y ));
|
|---|
| 248 |
|
|---|
| 249 | // for scatter charts
|
|---|
| 250 | t = t.replace('#x#', NumberUtils.formatNumber(this._x));
|
|---|
| 251 | t = t.replace('#y#', NumberUtils.formatNumber(this._y));
|
|---|
| 252 |
|
|---|
| 253 | // debug the dots sizes
|
|---|
| 254 | t = t.replace('#size#', NumberUtils.formatNumber(this.radius));
|
|---|
| 255 |
|
|---|
| 256 | t = DateUtils.replace_magic_values(t, this._x);
|
|---|
| 257 | return t;
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | protected function calcXOnCircle(aRadius:Number, aDegrees:Number):Number
|
|---|
| 261 | {
|
|---|
| 262 | return aRadius * Math.cos(aDegrees / 180 * Math.PI);
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | protected function calcYOnCircle(aRadius:Number, aDegrees:Number):Number
|
|---|
| 266 | {
|
|---|
| 267 | return aRadius * Math.sin(aDegrees / 180 * Math.PI);
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | }
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|