Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Box.as « actionscript « open-flash-chart « libs - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b94e223fb098d3455ec4ed8dd9a510a462445dc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
class Box
{
	public var top:Number=0;
	public var left:Number=0;
	public var right:Number=0;
	public var bottom:Number=0;
	public var width:Number=0;
	public var height:Number=0;
	
	// position of the zero line
	//public var zero:Number=0;
	//public var steps:Number=0;
	
	// set by 3D axis
	public var tick_offset:Number=0;
	
	public var count:Number = 0;
	
	private var minmax:MinMax;
	
	public function Box( top:Number, left:Number, right:Number, bottom:Number,
						minmax:MinMax,
						x_left_label_width:Number, x_right_label_width:Number,
						count:Number, jiggle:Boolean, three_d:Boolean )
	{
		
		var tmp_left:Number = left;
		
		if( jiggle )
		{
			right = this.jiggle( left, right, x_right_label_width, count );
			tmp_left = this.shrink_left( left, right, x_left_label_width, count );
		}
		
		this.top = top;
		this.left = Math.max(left,tmp_left);
		
		// round this down to the nearest int:
		this.right = Math.floor( right );
		this.bottom = bottom;
		this.width = this.right-this.left;
		this.height = bottom-top;
		
		//this.steps = this.height/(minmax.y_max-minmax.y_min);
		//this.zero = bottom-(steps*(minmax.y_min*-1));
		
		this.count = count;
		this.minmax = minmax;
		
		if( three_d )
		{
			// tell the box object that the 
			// X axis labels need to be offset
			this.tick_offset = 12;
		}
	}
	
	//
	// if the last X label is wider than the chart area, the last few letters will
	// be outside the drawing area. So we make the chart width smaller so the label
	// will fit into the screen.
	//
	function jiggle( left:Number, right:Number, x_label_width:Number, count:Number )
	{
		var r:Number = 0;
		
		if( x_label_width != 0 )
		{
			var item_width:Number = (right-left) / count;
			var r:Number = right-(item_width/2);
			var new_right:Number = right;
			
			// while the right most X label is off the edge of the
			// Stage, move the box.right - 1
			while( r+(x_label_width/2) > right )
			{
				new_right -= 1;
				// changing the right also changes the item_width:
				item_width = (new_right-left) / count;
				r = new_right-(item_width/2);
			}
			right = new_right;
		}
		
		return right;
		
	}
	
	// if the left label is truncated, shrink the box until
	// it fits onto the screen
	function shrink_left( left:Number, right:Number, x_label_width:Number, count:Number )
	{
		var pos:Number = 0;

		if( x_label_width != 0 )
		{
			var item_width:Number = (right-left) / count;
			var pos:Number = left+(item_width/2);
			var new_left:Number = left;
			
			// while the left most label is hanging off the Stage
			// move the box.left in one pixel:
			while( pos-(x_label_width/2) < 0 )
			{
				new_left += 1;
				// changing the left also changes the item_width:
				item_width = (right-new_left) / count;
				pos = new_left+(item_width/2);
			}
			left = new_left;
		}
		
		return left;
		
	}
	
	//
	// the bottom point of a bar:
	//   min=-100 and max=100, use b.zero
	//   min = 10 and max = 20, use b.bottom
	//
	function getYbottom( right_axis:Boolean )
	{
		var min:Number = this.minmax.min( right_axis );
		return this.getY( Math.max(0,min), right_axis );
	}
	
	// takes a value and returns the screen Y location
	function getY( i:Number, right_axis:Boolean )
	{
		var steps:Number = this.height/(this.minmax.range( right_axis ));
		
		// find Y pos for value=zero
		var y:Number = this.bottom-(steps*(this.minmax.min( right_axis )*-1));
		
		// move up (-Y) to our point (don't forget that y_min will shift it down)
		y -= i*steps;
		return y;
	}
	
	function width_():Number
	{
		return this.right-this.left_();
	}
	
	function left_():Number
	{
		var padding_left:Number = this.tick_offset;
		return this.left+padding_left;
	}
	
	function get_x_pos( i:Number )
	{
		var item_width:Number = this.width_() / this.count;
		return this.left_()+(item_width/2)+(i*item_width);
	}
	
	function get_x_tick_pos( i:Number )
	{
		//var item_width:Number = (this.right-this.left_()) / this.count;
		
		return this.get_x_pos(i) - this.tick_offset;
	}
}