Skip to content

ChartCanvasNode and the need to call update. #45

Description

@pixelzoom

For #47 and phetsims/fourier-making-waves#165 ...

@jonathanolson added this REVIEW comment to Foruier's SumChartNode.js:

    const sumPlot = new CanvasLinePlot( ... );
...
    const chartCanvasNode = new ChartCanvasNode( ..., [ sumPlot ], ... );
...
    // Display the data set.
    //REVIEW: This seems to be a common pattern with Data set Properties, any way to factor it out?
    sumDataSetProperty.lazyLink( dataSet => {
      sumPlot.setDataSet( dataSet );
      chartCanvasNode.update();
    } );

This is a problem that @samreid and I wrestled with previously in bamboo. ChartCanvasNode renders 1 or more CanvasLinePlot instances. CanvasLinePlot does not know about ChartCanvasNode. So when you make changes to a CanvasLinePlot , you are currently responsible for calling ChartCanvasNode.update.

This is well-documented in CanvasLinePlot, for example:

  /**
   * Sets dataSet. You are responsible for calling update on the associated ChartCanvasNode(s).
   * @param {Vector2[]} dataSet
   * @public
   */
  setDataSet( dataSet ) {

Despite the documentation, this is still a pain point - easy to forget, and (as @jonathanolson pointed out in the REVIEW comment) a common pattern that results in duplicated code.

But I should also point out... In terms of performance, there are also benefits here. In Fourier, I have a ChartCanvasNode that is rendering 97 CanvasLinePlot instances. I can update all 97 plots, then call update. If ChartCanvasNode updated each time one of its plots was updated, then I'd have big problems in Fourier. So perhaps having to call update is OK for something like this where performance is critical.

I don't plan to address this for Fourier because of the need to move forward. But let's discuss this again, adding @jonathanolson to the discussion.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions