| 1 | import { Geometry } from "./geometry.js"; |
| 2 | |
| 3 | export class Graph{ |
| 4 | constructor( canvas, config ){ |
| 5 | this.canvas = canvas; |
| 6 | this.config = config; |
| 7 | this.context = canvas.getContext( '2d' ); |
| 8 | } |
| 9 | |
| 10 | drawBg(){ |
| 11 | let x = this.canvas.width * this.config.yAxis; |
| 12 | let y = this.canvas.height - this.canvas.height * this.config.xAxis; |
| 13 | |
| 14 | this.drawGrid( x, y ); |
| 15 | this.drawAxes( x, y ); |
| 16 | } |
| 17 | |
| 18 | drawAxes( x, y, lineWidth = 2 ){ |
| 19 | this.context.strokeStyle = "#88A"; |
| 20 | this.context.lineWidth = lineWidth; |
| 21 | |
| 22 | // yAxis |
| 23 | this.context.beginPath(); |
| 24 | this.context.moveTo( x, 0 ); |
| 25 | this.context.lineTo( x, this.canvas.height ); |
| 26 | |
| 27 | // xAxis |
| 28 | this.context.moveTo( 0, y ); |
| 29 | this.context.lineTo( this.canvas.width, y ); |
| 30 | |
| 31 | // Draw the Path |
| 32 | this.context.stroke(); |
| 33 | } |
| 34 | |
| 35 | drawLightGrid( yAxis, pos, extent ){ |
| 36 | if ( extent < 5 ) return; |
| 37 | |
| 38 | const inc = ( extent < 30 ) ? extent/2 : extent/10; |
| 39 | |
| 40 | this.context.strokeStyle = "#AAD"; |
| 41 | this.context.lineWidth = 0.5; |
| 42 | |
| 43 | this.context.beginPath(); |
| 44 | |
| 45 | if (yAxis){ |
| 46 | for( let x=pos; x<pos + extent; x+=inc){ |
| 47 | this.context.moveTo( x, 0 ); |
| 48 | this.context.lineTo( x, this.canvas.height ); |
| 49 | } |
| 50 | }else{ |
| 51 | for( let y=pos; y<pos + extent; y+=inc){ |
| 52 | this.context.moveTo( 0, y ); |
| 53 | this.context.lineTo( this.canvas.width, y ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Draw the Path |
| 58 | this.context.stroke(); |
| 59 | } |
| 60 |
nothing calls this directly
no outgoing calls
no test coverage detected