import '../../assert/js/assert.js';
import '../../globals.js';
import { Shape } from '../../kite/js/imports.js';
import optionize from '../../phet-core/js/optionize.js';
import { Path } from '../../scenery/js/imports.js';
import bamboo from './bamboo.js';
class LinePlot extends Path {
    constructor(chartTransform, dataSet, providedOptions) {
        const options = optionize()({
            // Path options
            stroke: 'black'
        }, providedOptions);
        super(null, options);
        this.chartTransform = chartTransform;
        this.dataSet = dataSet;
        // Initialize
        this.update();
        // Update when the transform changes.
        const changedListener = () => this.update();
        chartTransform.changedEmitter.addListener(changedListener);
        this.disposeLinePlot = () => chartTransform.changedEmitter.removeListener(changedListener);
    }
    /**
     * Sets the dataSet and redraws the plot. If instead the dataSet array is mutated, it is the client's responsibility
     * to call `update` or make sure `update` is called elsewhere (say, if the chart scrolls in that frame).
     */
    setDataSet(dataSet) {
        this.dataSet = dataSet;
        this.update();
    }
    // Recomputes the rendered shape.
    update() {
        const shape = new Shape();
        let moveToNextPoint = true;
        for (let i = 0; i < this.dataSet.length; i++) {
            const dataPoint = this.dataSet[i];
            assert && assert(dataPoint === null || dataPoint.isFinite(), 'data points must be finite Vector2 or null');
            // Draw a line segment to the next non-null value. Null values result in a gap (via move) in the plot.
            if (dataPoint) {
                const viewPoint = this.chartTransform.modelToViewPosition(dataPoint);
                if (moveToNextPoint) {
                    shape.moveToPoint(viewPoint);
                    moveToNextPoint = false;
                }
                else {
                    shape.lineToPoint(viewPoint);
                }
            }
            else {
                moveToNextPoint = true;
            }
        }
        this.shape = shape.makeImmutable();
    }
    dispose() {
        this.disposeLinePlot();
        super.dispose();
    }
}
bamboo.register('LinePlot', LinePlot);
export default LinePlot;
//# sourceMappingURL=LinePlot.js.map