phetsims / neuron

"Neuron" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
1 stars 3 forks source link

Chart gridlines should be done in a single Path instead of multiple Lines #51

Closed samreid closed 9 years ago

samreid commented 9 years ago

Here is the code that adds grid lines in the chart:

    //vertical grid lines
    for ( var i = 0; i < numVerticalGridLines + 1; i++ ) {
      line = new Line( i * chartDimension.width / numVerticalGridLines, 0, i * chartDimension.width / numVerticalGridLines, chartDimension.height, {stroke: 'gray', lineWidth: lineWidth} );
      line.computeShapeBounds = computeShapeBounds;
      plotGrid.addChild( line );
      plotGrid.addChild( new Text( domainMap( i ), {font: GRID_TICK_TEXT_FONT, centerX: line.centerX, top: line.bottom + 6} ) );
    }

    //horizontal grid lines
    for ( i = 0; i < numHorizontalGridLines + 1; i++ ) {
      line = new Line( 0, i * chartDimension.height / numHorizontalGridLines, chartDimension.width, i * chartDimension.height / numHorizontalGridLines, {stroke: 'gray', lineWidth: lineWidth} );
      line.computeShapeBounds = computeShapeBounds;
      plotGrid.addChild( line );
      plotGrid.addChild( new Text( rangeMap( i ), {font: GRID_TICK_TEXT_FONT, centerY: line.centerY, right: line.left - 6} ) );

    }

This adds many scenery nodes for all of the grid lines, and could be rewritten to use a single Path with several lineTo() moveTo() calls.

samreid commented 9 years ago

Oops! Duplicate of https://github.com/phetsims/neuron/issues/31. Thanks to @jbphet for pointing this out. Closing.