Difference between revisions of "Bar-graph.as"

From Organic Design wiki
m
(Make into a proper importable symbol)
Line 1: Line 1:
this.barColour = 0x00ff00;
+
create.barGraph = function( name, layer ) {
this.barWidth = 5;
 
this.barSpacing = 10;
 
this.bars = 50;
 
  
this.curBuf = 0;
+
this.createEmptyMovieClip( name, layer );
this.curBar = 0;
+
graph = this[name];
  
// Make two bar-graph buffers of n-bars
+
// These should be sent in create, but that's not supported yet
for ( var i = 0; i < 1; i++ ) {
+
graph.barColour = 0x00ff00;
 +
graph.barWidth = 5;
 +
graph.barSpacing = 10;
 +
graph.bars = 50;
  
this.createEmptyMovieClip( 'buf' + i, i );
+
graph.curBuf = 0;
var buf = this[ 'buf' + i ];
+
graph.curBar = 0;
buf._width = this.barSpacing * this.bars;
 
buf._height = height;
 
buf._x = i * width;
 
buf._y = 0;
 
  
// Create bars in this buffer
+
// Make two bar-graph buffers of n-bars
for ( j = 0; j < this.bars; j++ ) {
+
for ( var i = 0; i < 1; i++ ) {
buf.createEmptyMovieClip( 'bar' + j, j );
+
 
var bar = buf[ 'bar' + j ];
+
graph.createEmptyMovieClip( 'buf' + i, i );
bar.lineStyle( 0, 0, 0 );
+
var buf = graph[ 'buf' + i ];
bar.beginFill( this.barColour, 100 );
+
buf._width = graph.barSpacing * graph.bars;
bar.moveTo( 0, 0 );
+
buf._height = height;
bar.lineTo( 0, 1 );
+
buf._x = i * width;
bar.lineTo( 1, 1 );
+
buf._y = 0;
bar.lineTo( 1, 0 );
+
 
bar.lineTo( 0, 0 );
+
// Create bars in this buffer
bar.endFill();
+
for ( j = 0; j < graph.bars; j++ ) {
bar._x = j * this.bar
+
buf.createEmptyMovieClip( 'bar' + j, j );
bar._y = _root.height;
+
var bar = buf[ 'bar' + j ];
bar._width = this.barWidth;
+
bar.lineStyle( 0, 0, 0 );
bar._height = _root.height / 2;
+
bar.beginFill( graph.barColour, 100 );
 +
bar.moveTo( 0, 0 );
 +
bar.lineTo( 0, 1 );
 +
bar.lineTo( 1, 1 );
 +
bar.lineTo( 1, 0 );
 +
bar.lineTo( 0, 0 );
 +
bar.endFill();
 +
bar._x = j * graph.bar
 +
bar._y = _root.height;
 +
bar._width = graph.barWidth;
 +
bar._height = _root.height / 2;
 +
}
 
}
 
}
}
 
  
// Method to scroll the graph and insert a value
+
// Method to scroll the graph and insert a value
this.rotate = function( value ) {
+
graph.rotate = function( value ) {
  
// Scroll both buffers
+
// Scroll both buffers
for ( var i = 0; i < 1; i++ ) {
+
for ( var i = 0; i < 1; i++ ) {
var buf =  this[ 'buf' + i ];
+
var buf =  this[ 'buf' + i ];
buf._x -= this.barSpacing;
+
buf._x -= this.barSpacing;
if ( buf._x < -this._width ) buf._x += 2 * this._width;
+
if ( buf._x < -this._width ) buf._x += 2 * this._width;
}
+
}
  
// Update the current bar and buffer pointers
+
// Update the current bar and buffer pointers
if ( ( ++this.curBar % this.bars ) == 0 ) this.curBuf ^= 1;
+
if ( ( ++this.curBar % this.bars ) == 0 ) this.curBuf ^= 1;
  
// Update the height value at the current bar
+
// Update the height value at the current bar
this[ 'buf' + this.curBuf ][ 'bar' + this.curBar ]._height = value;
+
this[ 'buf' + this.curBuf ][ 'bar' + this.curBar ]._height = value;
  
 +
}
 +
return graph;
 
}
 
}

Revision as of 07:45, 25 March 2006

create.barGraph = function( name, layer ) {

this.createEmptyMovieClip( name, layer ); graph = this[name];

// These should be sent in create, but that's not supported yet graph.barColour = 0x00ff00; graph.barWidth = 5; graph.barSpacing = 10; graph.bars = 50;

graph.curBuf = 0; graph.curBar = 0;

// Make two bar-graph buffers of n-bars for ( var i = 0; i < 1; i++ ) {

graph.createEmptyMovieClip( 'buf' + i, i ); var buf = graph[ 'buf' + i ]; buf._width = graph.barSpacing * graph.bars; buf._height = height; buf._x = i * width; buf._y = 0;

// Create bars in this buffer for ( j = 0; j < graph.bars; j++ ) { buf.createEmptyMovieClip( 'bar' + j, j ); var bar = buf[ 'bar' + j ]; bar.lineStyle( 0, 0, 0 ); bar.beginFill( graph.barColour, 100 ); bar.moveTo( 0, 0 ); bar.lineTo( 0, 1 ); bar.lineTo( 1, 1 ); bar.lineTo( 1, 0 ); bar.lineTo( 0, 0 ); bar.endFill(); bar._x = j * graph.bar bar._y = _root.height; bar._width = graph.barWidth; bar._height = _root.height / 2; } }

// Method to scroll the graph and insert a value graph.rotate = function( value ) {

// Scroll both buffers for ( var i = 0; i < 1; i++ ) { var buf = this[ 'buf' + i ]; buf._x -= this.barSpacing; if ( buf._x < -this._width ) buf._x += 2 * this._width; }

// Update the current bar and buffer pointers if ( ( ++this.curBar % this.bars ) == 0 ) this.curBuf ^= 1;

// Update the height value at the current bar this[ 'buf' + this.curBuf ][ 'bar' + this.curBar ]._height = value;

} return graph; }