Difference between revisions of "Bar-graph.as"
m |
m |
||
| Line 30: | Line 30: | ||
bar.beginFill( graph.barColour, 100 ); | bar.beginFill( graph.barColour, 100 ); | ||
bar.moveTo( 0, 0 ); | bar.moveTo( 0, 0 ); | ||
| − | bar.lineTo( 0, | + | bar.lineTo( 0, 100 ); |
| − | bar.lineTo( | + | bar.lineTo( 100, 100 ); |
| − | bar.lineTo( | + | bar.lineTo( 100, 0 ); |
bar.lineTo( 0, 0 ); | bar.lineTo( 0, 0 ); | ||
bar.endFill(); | bar.endFill(); | ||
| Line 53: | Line 53: | ||
// Update the current bar and buffer pointers | // Update the current bar and buffer pointers | ||
| − | if ( ( ++graph.curBar % graph.bars ) == 0 ) graph.curBuf = 1 | + | if ( ( ++graph.curBar % graph.bars ) == 0 ) graph.curBuf ^= 1; |
// Update the height value at the current bar | // Update the height value at the current bar | ||
Revision as of 08:22, 25 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 = 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 ( 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, 100 ); bar.lineTo( 100, 100 ); bar.lineTo( 100, 0 ); bar.lineTo( 0, 0 ); bar.endFill(); bar._x = j * graph.barSpacing; bar._y = _root.height/2; 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 = graph[ 'buf' + i ]; buf._x -= this.barSpacing; if ( buf._x < -graph._width ) buf._x += 2 * graph._width; }
// Update the current bar and buffer pointers if ( ( ++graph.curBar % graph.bars ) == 0 ) graph.curBuf ^= 1;
// Update the height value at the current bar graph[ 'buf' + graph.curBuf ][ 'bar' + graph.curBar ]._height = value;
};
return graph; };



