Difference between revisions of "Bar-graph.as"

From Organic Design wiki
(tweek bar values)
(revert: read code before tweeking)
Line 6: Line 6:
 
// These should be sent in create, but that's not supported yet
 
// These should be sent in create, but that's not supported yet
 
graph.barColour = 0x00ff00;
 
graph.barColour = 0x00ff00;
graph.barWidth = 3;
+
graph.barWidth = 5;
graph.barSpacing = 4;
+
graph.barSpacing = 10;
 
graph.bars = 50;
 
graph.bars = 50;
  

Revision as of 04:47, 26 March 2006

create.barGraph = function( name, layer ) {

this.createEmptyMovieClip( name, layer ); var 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 = graph.bars - 1;

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

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

// Create bars in this buffer for ( var 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.barSpacing; bar._y = _root.height; bar._width = graph.barWidth; bar._height = 0; } }

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

// Scroll both buffers // - and switch to right when it scrolls off left var size = graph.barSpacing * graph.bars; graph.buf0._x -= graph.barSpacing; if ( graph.buf0._x < -size ) graph.buf0._x += 2 * size; graph.buf1._x -= graph.barSpacing; if ( graph.buf1._x < -size ) graph.buf1._x += 2 * size;

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

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

};

return graph; };