[7849] | 1 | package charts {
|
---|
| 2 |
|
---|
| 3 | import charts.series.Element;
|
---|
| 4 | import charts.series.dots.PointDotBase;
|
---|
| 5 | import flash.display.Graphics;
|
---|
| 6 | import flash.display.Sprite;
|
---|
| 7 | import flash.display.BlendMode;
|
---|
| 8 | import string.Utils;
|
---|
| 9 | // import charts.series.dots.PointDot;
|
---|
| 10 | import charts.series.dots.dot_factory;
|
---|
| 11 |
|
---|
| 12 |
|
---|
| 13 | public class LineBase extends Base
|
---|
| 14 | {
|
---|
| 15 | // JSON style:
|
---|
| 16 | protected var style:Object;
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | public function LineBase() {}
|
---|
| 20 |
|
---|
| 21 | //
|
---|
| 22 | // called from the BaseLine object
|
---|
| 23 | //
|
---|
| 24 | protected override function get_element( index:Number, value:Object ): Element {
|
---|
| 25 |
|
---|
| 26 | // var s:Object = this.merge_us_with_value_object( value );
|
---|
| 27 | //
|
---|
| 28 | // the width of the hollow circle is the same as the width of the line
|
---|
| 29 | //
|
---|
| 30 |
|
---|
| 31 | var tmp:Properties;
|
---|
| 32 | if( value is Number )
|
---|
| 33 | tmp = new Properties( { value:value }, this.style['--dot-style']);
|
---|
| 34 | else
|
---|
| 35 | tmp = new Properties( value, this.style['--dot-style']);
|
---|
| 36 |
|
---|
| 37 | return dot_factory.make( index, tmp );
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | // Draw lines...
|
---|
| 42 | public override function resize( sc:ScreenCoordsBase ): void {
|
---|
| 43 | this.x = this.y = 0;
|
---|
| 44 |
|
---|
| 45 | this.graphics.clear();
|
---|
| 46 | this.graphics.lineStyle( this.style.width, this.style.colour );
|
---|
| 47 |
|
---|
| 48 | if( this.style['line-style'].style != 'solid' )
|
---|
| 49 | this.dash_line(sc);
|
---|
| 50 | else
|
---|
| 51 | this.solid_line(sc);
|
---|
| 52 |
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public function solid_line( sc:ScreenCoordsBase ): void {
|
---|
| 56 |
|
---|
| 57 | var first:Boolean = true;
|
---|
| 58 | var i:Number;
|
---|
| 59 | var tmp:Sprite;
|
---|
| 60 | var x:Number;
|
---|
| 61 | var y:Number;
|
---|
| 62 |
|
---|
| 63 | for ( i=0; i < this.numChildren; i++ ) {
|
---|
| 64 |
|
---|
| 65 | tmp = this.getChildAt(i) as Sprite;
|
---|
| 66 |
|
---|
| 67 | //
|
---|
| 68 | // filter out the line masks
|
---|
| 69 | //
|
---|
| 70 | if( tmp is Element )
|
---|
| 71 | {
|
---|
| 72 | var e:Element = tmp as Element;
|
---|
| 73 |
|
---|
| 74 | // tell the point where it is on the screen
|
---|
| 75 | // we will use this info to place the tooltip
|
---|
| 76 | e.resize( sc );
|
---|
| 77 | if( first )
|
---|
| 78 | {
|
---|
| 79 | this.graphics.moveTo(e.x, e.y);
|
---|
| 80 | x = e.x;
|
---|
| 81 | y = e.y;
|
---|
| 82 | first = false;
|
---|
| 83 | }
|
---|
| 84 | else
|
---|
| 85 | this.graphics.lineTo(e.x, e.y);
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | if ( this.style.loop ) {
|
---|
| 90 | // close the line loop (radar charts)
|
---|
| 91 | this.graphics.lineTo(x, y);
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | // Dashed lines by Arseni
|
---|
| 96 | public function dash_line( sc:ScreenCoordsBase ): void {
|
---|
| 97 |
|
---|
| 98 | var first:Boolean = true;
|
---|
| 99 |
|
---|
| 100 | var prev_x:int = 0;
|
---|
| 101 | var prev_y:int = 0;
|
---|
| 102 | var on_len_left:Number = 0;
|
---|
| 103 | var off_len_left:Number = 0;
|
---|
| 104 | var on_len:Number = this.style['line-style'].on; //Stroke Length
|
---|
| 105 | var off_len:Number = this.style['line-style'].off; //Space Length
|
---|
| 106 | var now_on:Boolean = true;
|
---|
| 107 |
|
---|
| 108 | for ( var i:Number = 0; i < this.numChildren; i++ ) {
|
---|
| 109 | var tmp:Sprite = this.getChildAt(i) as Sprite;
|
---|
| 110 | //
|
---|
| 111 | // filter out the line masks
|
---|
| 112 | //
|
---|
| 113 | if( tmp is Element )
|
---|
| 114 | {
|
---|
| 115 | var e:Element = tmp as Element;
|
---|
| 116 |
|
---|
| 117 | // tell the point where it is on the screen
|
---|
| 118 | // we will use this info to place the tooltip
|
---|
| 119 | e.resize( sc );
|
---|
| 120 | if( first )
|
---|
| 121 | {
|
---|
| 122 | this.graphics.moveTo(e.x, e.y);
|
---|
| 123 | on_len_left = on_len;
|
---|
| 124 | off_len_left = off_len;
|
---|
| 125 | now_on = true;
|
---|
| 126 | first = false;
|
---|
| 127 | prev_x = e.x;
|
---|
| 128 | prev_y = e.y;
|
---|
| 129 | var x_tmp_1:Number = prev_x;
|
---|
| 130 | var x_tmp_2:Number;
|
---|
| 131 | var y_tmp_1:Number = prev_y;
|
---|
| 132 | var y_tmp_2:Number;
|
---|
| 133 | }
|
---|
| 134 | else {
|
---|
| 135 | var part_len:Number = Math.sqrt((e.x - prev_x) * (e.x - prev_x) + (e.y - prev_y) * (e.y - prev_y) );
|
---|
| 136 | var sinus:Number = ((e.y - prev_y) / part_len);
|
---|
| 137 | var cosinus:Number = ((e.x - prev_x) / part_len);
|
---|
| 138 | var part_len_left:Number = part_len;
|
---|
| 139 | var inside_part:Boolean = true;
|
---|
| 140 |
|
---|
| 141 | while (inside_part) {
|
---|
| 142 | //Draw Lines And spaces one by one in loop
|
---|
| 143 | if ( now_on ) {
|
---|
| 144 | //Draw line
|
---|
| 145 | //If whole stroke fits
|
---|
| 146 | if ( on_len_left < part_len_left ) {
|
---|
| 147 | //Fits - draw whole stroke
|
---|
| 148 | x_tmp_2 = x_tmp_1 + on_len_left * cosinus;
|
---|
| 149 | y_tmp_2 = y_tmp_1 + on_len_left * sinus;
|
---|
| 150 | x_tmp_1 = x_tmp_2;
|
---|
| 151 | y_tmp_1 = y_tmp_2;
|
---|
| 152 | part_len_left = part_len_left - on_len_left;
|
---|
| 153 | now_on = false;
|
---|
| 154 | off_len_left = off_len;
|
---|
| 155 | } else {
|
---|
| 156 | //Does not fit - draw part of the stroke
|
---|
| 157 | x_tmp_2 = e.x;
|
---|
| 158 | y_tmp_2 = e.y;
|
---|
| 159 | x_tmp_1 = x_tmp_2;
|
---|
| 160 | y_tmp_1 = y_tmp_2;
|
---|
| 161 | on_len_left = on_len_left - part_len_left;
|
---|
| 162 | inside_part = false;
|
---|
| 163 | }
|
---|
| 164 | this.graphics.lineTo(x_tmp_2, y_tmp_2);
|
---|
| 165 | } else {
|
---|
| 166 | //Draw space
|
---|
| 167 | //If whole space fits
|
---|
| 168 | if ( off_len_left < part_len_left ) {
|
---|
| 169 | //Fits - draw whole space
|
---|
| 170 | x_tmp_2 = x_tmp_1 + off_len_left * cosinus;
|
---|
| 171 | y_tmp_2 = y_tmp_1 + off_len_left * sinus;
|
---|
| 172 | x_tmp_1 = x_tmp_2;
|
---|
| 173 | y_tmp_1 = y_tmp_2;
|
---|
| 174 | part_len_left = part_len_left - off_len_left;
|
---|
| 175 | now_on = true;
|
---|
| 176 | on_len_left = on_len;
|
---|
| 177 | } else {
|
---|
| 178 | //Does not fit - draw part of the space
|
---|
| 179 | x_tmp_2 = e.x;
|
---|
| 180 | y_tmp_2 = e.y;
|
---|
| 181 | x_tmp_1 = x_tmp_2;
|
---|
| 182 | y_tmp_1 = y_tmp_2;
|
---|
| 183 | off_len_left = off_len_left - part_len_left;
|
---|
| 184 | inside_part = false;
|
---|
| 185 | }
|
---|
| 186 | this.graphics.moveTo(x_tmp_2, y_tmp_2);
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 | prev_x = e.x;
|
---|
| 191 | prev_y = e.y;
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | protected function merge_us_with_value_object( value:Object ): Object {
|
---|
| 197 |
|
---|
| 198 | var default_style:Object = {
|
---|
| 199 | 'dot-size': this.style['dot-size'],
|
---|
| 200 | colour: this.style.colour,
|
---|
| 201 | 'halo-size': this.style['halo-size'],
|
---|
| 202 | tip: this.style.tip,
|
---|
| 203 | 'on-click': this.style['on-click'],
|
---|
| 204 | 'axis': this.style.axis
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | if( value is Number )
|
---|
| 208 | default_style.value = value;
|
---|
| 209 | else
|
---|
| 210 | object_helper.merge_2( value, default_style );
|
---|
| 211 |
|
---|
| 212 | // our parent colour is a number, but
|
---|
| 213 | // we may have our own colour:
|
---|
| 214 | if( default_style.colour is String )
|
---|
| 215 | default_style.colour = Utils.get_colour( default_style.colour );
|
---|
| 216 |
|
---|
| 217 | // Minor hack, replace all #key# with this LINEs key text:
|
---|
| 218 | default_style.tip = default_style.tip.replace('#key#', this.style.text);
|
---|
| 219 |
|
---|
| 220 | return default_style;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | public override function get_colour(): Number {
|
---|
| 224 | return this.style.colour;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | }
|
---|