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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
| // ActionScript file
/*
L'importation du arrayCollection ne fonctionne pas :o
*/
package test{
import flash.display.*;
import flash.geom.*;
import flash.text.*;
import mx.collections.ArrayCollection;
import mx.containers.Canvas;
import mx.controls.Label;
import mx.core.UIComponent;
import mx.effects.Move;
import mx.effects.Rotate;
import mx.effects.easing.*;
public class Charts extends Canvas{
public var graphique:UIComponent;
public var spriteGraphGlobal:UIComponent;
// Variable de "design" de l'objet créé
public var tailleX:int;
public var tailleY:int;
public var coodX:int;
public var coodY:int;
public var couleurTexte;
public var couleurAbscisse:uint;
public var couleurOrdonnee:uint = 0x000000;
public var alphaAbscisse : Number = 1;
public var alphaOrdonnee : Number = 0.5;
public var couleurCourbe:uint = 0x00FF00;
public var i:int =0;
public var nbO:int = 5;
public var nbA:int = 6;
public var contour:int =40;
public var largeur:int = 50;
public var tailleYinterieur:int;
public var tailleXinterieur:int;
public var donnee2:Array;
public var donnee:ArrayCollection;
public var fondGraph:Sprite;
private var move2:Move;
//Applique l'effet de mouvement sur les barres
private function applyEffect():void {
move2.target = spriteGraphGlobal;
move2.play();
}
// A la création on affiche ca
override protected function createChildren():void {
super.createChildren();
// Recupere les valeur initials des différentes variables
this.initPos();
// Defini l'effet de mouvement
move2 = new Move();
move2.yFrom = tailleYinterieur;
move2.yTo =0;
//move2.easingFunction = Elastic.easeOut;
move2.duration = 1000;
graphique = new UIComponent();
spriteGraphGlobal = new UIComponent();
//Dessine le fond
fond();
// Dessine les données
affichageDonnee();
this.addChild(graphique);
//On applique l'effet de mouvement quand tout est créer
graphique.setStyle("creationCompleteEffect", applyEffect());
}
public function fond():void {
fondGraph = new Sprite();
var colors:Array = [0xFF0000, 0x00FF00];
var matr:Matrix = new Matrix();
matr.createGradientBox(100, 200, Math.PI / 2, 0, 0);
fondGraph.graphics.beginGradientFill(GradientType.LINEAR, colors, [1,1], [0,255], matr, SpreadMethod.PAD);
fondGraph.graphics.drawRect(contour, contour, tailleXinterieur, tailleYinterieur);
fondGraph.graphics.endFill();
// Dessine les abscisses et ordonnées
abscisse();
ordonnee();
graphique.addChild(fondGraph);
}
public function abscisse():void{
var ligneAbcisse:Sprite;
ligneAbcisse = new Sprite();
ligneAbcisse.graphics.lineStyle(1, couleurOrdonnee, 1);
for (i=0;i<nbA+1;i++)
{
ligneAbcisse.graphics.moveTo(-5+contour,tailleY-contour-(tailleYinterieur/nbA)*i);
ligneAbcisse.graphics.lineTo(tailleX-contour,tailleY-contour-(tailleYinterieur/nbA)*i);
}
graphique.addChild(ligneAbcisse);
var labelAbcisse:Array = new Array();
for (i=0; i<nbA+1; i++) {
var s:Label = new Label();
labelAbcisse.push(s);
}
for (i=0;i<nbA+1;i++)
{
labelAbcisse[i].x = -20+contour;
labelAbcisse[i].y = tailleY-contour-5-(tailleYinterieur/nbA)*i;
labelAbcisse[i].text = i;
labelAbcisse[i].width = 200;
labelAbcisse[i].height = 100;
graphique.addChild(labelAbcisse[i]);
}
}
public function ordonnee():void{
var ligneOrdonnee:Sprite;
ligneOrdonnee = new Sprite();
ligneOrdonnee.graphics.lineStyle(1, couleurAbscisse, 1);
for (i=0;i<nbO+1;i++)
{
ligneOrdonnee.graphics.moveTo(contour+(tailleXinterieur/(nbO))*i,contour);
ligneOrdonnee.graphics.lineTo(contour+(tailleXinterieur/(nbO))*i,contour+tailleYinterieur+5);
}
graphique.addChild(ligneOrdonnee);
var labelOrdonnee:Array = new Array();
for (var i:int=0; i<nbO; i++) {
var s:Label = new Label();
labelOrdonnee.push(s);
}
for (i=0;i<nbO;i++)
{
labelOrdonnee[i].x = (tailleXinterieur/(nbO))*(i);
labelOrdonnee[i].y = tailleY-contour+5;
labelOrdonnee[i].text = "aaa"+ i;
labelOrdonnee[i].setStyle("textAlign", "center");
labelOrdonnee[i].setStyle("color", couleurTexte);
labelOrdonnee[i].width = (tailleXinterieur/(nbO))+contour*2;
labelOrdonnee[i].height = 100;
graphique.addChild(labelOrdonnee[i]);
}
}
public function affichageDonnee():void{
var spriteGraph:Array = new Array();
for (var i:int=0; i<nbO; i++) {
var s:Sprite = new Sprite();
spriteGraph.push(s);
}
for (i=0;i<nbO;i++)
{
spriteGraph[i].graphics.beginFill("0x008800");
spriteGraph[i].graphics.drawRect((tailleXinterieur/(nbO))*(i)+contour+(tailleXinterieur/(nbO)-largeur)/2, tailleY-contour+tailleYinterieur, largeur, -donnee[i]*(tailleYinterieur/nbA)-tailleYinterieur);
spriteGraphGlobal.addChild(spriteGraph[i]);
}
fondGraph.mask = spriteGraphGlobal;
graphique.addChild(spriteGraphGlobal);
// this.addChild(spriteGraphGlobal);
}
public function initPos():void {
nbO = donnee.length;
//nbA= max(donnee);
nbA= 4;
this.tailleY = this.height;
this.tailleX = this.width;
this.coodX = this.x;
this.coodY = this.y;
this.tailleXinterieur = tailleX-contour*2;
this.tailleYinterieur = tailleY-contour*2;
this.couleurTexte = this.styleChanged("color");
}
public function max(array: Array):int{
var idMax :int = 0, j : int = 0;
var taille : int= array.length;
for (j=0;j<taille;j++)
{
if (array[j]>idMax){
idMax = array[j];
}
}
return idMax;
}
}
} |
Partager