source: code/Website/open-flash-chart/ScreenCoordsRadar.as@ 7849

Last change on this file since 7849 was 7849, checked in by dennisw, 15 years ago
File size: 2.1 KB
Line 
1package {
2 import flash.geom.Point;
3
4 public class ScreenCoordsRadar extends ScreenCoordsBase
5 {
6 private var TO_RADIANS:Number = Math.PI / 180;
7 private var range:Range;
8 private var angles:Number;
9 private var angle:Number;
10 private var radius:Number;
11
12 public function ScreenCoordsRadar( top:Number, left:Number, right:Number, bottom:Number ) {
13
14 super(top, left, right, bottom);
15
16 //
17 // if the radar chart has labels this is going to
18 // get updated so they fit onto the screen
19 //
20 this.radius = ( Math.min( this.width, this.height ) / 2.0 );
21 }
22
23 // axis range, from center to outer edge
24 public function set_range( r:Range ): void {
25 this.range = r;
26 }
27
28 public function get_max():Number {
29 return this.range.max;
30 }
31
32 // how many axis/spokes
33 public function set_angles( a:Number ):void {
34 this.angles = a;
35 this.angle = 360 / a;
36 }
37
38 public function get_angles():Number {
39 return this.angles;
40 }
41
42 public function get_radius():Number {
43
44 return this.radius;
45 }
46
47 public function reduce_radius():void {
48 this.radius--;
49 }
50
51 public function get_pos( angle:Number, radius:Number ): flash.geom.Point {
52
53 // flash assumes 0 degrees is horizontal to the right
54 var a:Number = (angle - 90) * TO_RADIANS;
55 var r:Number = this.get_radius() * radius;
56
57 var p:flash.geom.Point = new flash.geom.Point(
58 r * Math.cos(a),
59 r * Math.sin(a) );
60
61 return p;
62 }
63
64 public override function get_get_x_from_pos_and_y_from_val( index:Number, y:Number, right_axis:Boolean = false ):flash.geom.Point {
65
66 // rotate
67 var p:flash.geom.Point = this.get_pos( this.angle*index, y / this.range.count() );
68
69 // translate
70 p.x += this.get_center_x();
71 p.y += this.get_center_y();
72
73 return p;
74 }
75
76 public override function get_y_from_val( y:Number, right_axis:Boolean = false ):Number {
77
78 // rotate
79 var p:flash.geom.Point = this.get_pos( 0, y / this.range.count() );
80
81 // translate
82 p.y += this.get_center_y();
83
84 return p.y;
85 }
86 }
87}
Note: See TracBrowser for help on using the repository browser.