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

YAxisLabels.as « actionscript « open-flash-chart « libs - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 39ee3bd103a24f10804b50685f4161ac932d8c02 (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
class YAxisLabels
{
	public var labelNames:Array;
	private var steps:Number;
	
	function YAxisLabels( y_label_style:YLabelStyle, min:Number, max:Number, steps:Number, nr:Number, lv:LoadVars )
	{
		this.steps = steps;
		this.labelNames = [];
		var name:String = '';
		
		if(nr == 1)
		{
			// are the Y Labels visible?
			if( !y_label_style.show_labels )
				return;
			
			name = 'y_label_';
		}
		else if (nr = 2)
		{
			
			// are the Y Labels visible?
			if( !lv.show_y2 )
				return;
			
			name = 'y_label_2_';
		}
			
		// labels
		var every:Number = (max-min)/this.steps;
		
		for( var i:Number=min; i<=max; i+=every )
		{
			this.yAxisLabel( i, name+String(i), y_label_style, nr );
			this.labelNames.push( name+String(i) );
		}
	}

	
	
	function yAxisLabel( title:Number, name:String, y_label_style:YLabelStyle )
	{
		// does _root already have this textFiled defined?
		// this happens when we do an AJAX reload()
		// these have to be deleted by hand or else flash goes wonky.
		// In an ideal world we would put this code in the object
		// distructor method, but I don't think actionscript has these :-(
		if( _root[name] != undefined )
			_root[name].removeTextField();
											
		var tf:TextField = _root.createTextField(name, _root.getNextHighestDepth(), 0, 0, 100, 100);
		//tf.border = true;
		tf.text = _root.format(title);
		var fmt:TextFormat = new TextFormat();
		fmt.color = y_label_style.colour;
		fmt.font = "Verdana";
		fmt.size = y_label_style.size;
		fmt.align = "right";
		tf.setTextFormat(fmt);
		tf.autoSize="right";
	}

	// move y axis labels to the correct x pos
	function move( left:Number, box:Box )
	{
		var maxWidth:Number = this.width();
		
		for( var i in this.labelNames )
		{
			// right align
			_root[this.labelNames[i]]._x = left - _root[this.labelNames[i]]._width + maxWidth;
		}
		
		// now move it to the correct Y, vertical center align
		var tick:Number = box.height/this.steps;
		
		var count:Number = 0;
		for( var i in this.labelNames )
		{
			_root[this.labelNames[i]]._y = box.top + (tick*count) - (_root[this.labelNames[i]]._height/2);
			count+=1;
		}
	}


	function width()
	{
		var max:Number = 0;
		for( var x in this.labelNames )
		{
			max = Math.max( max, _root[this.labelNames[x]]._width );
		}
		return max;
	}
}