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 ScatterPlot extends Path {
    constructor(chartTransform, dataSet, providedOptions) {
        const options = optionize()({
            // SelfOptions
            radius: 2,
            // Path options
            fill: 'black'
        }, providedOptions);
        super(null, options);
        this.chartTransform = chartTransform;
        this.dataSet = dataSet;
        this.radius = options.radius;
        // Initialize
        this.update();
        // Update when the transform changes.
        const changedListener = () => this.update();
        chartTransform.changedEmitter.addListener(changedListener);
        this.disposeScatterPlot = () => 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();
        const length = this.dataSet.length;
        for (let i = 0; i < length; i++) {
            // NaN or Infinite components draw nothing
            const dataPoint = this.dataSet[i];
            if (dataPoint.isFinite()) {
                const viewPoint = this.chartTransform.modelToViewPosition(dataPoint);
                shape.moveTo(viewPoint.x + this.radius, viewPoint.y); // need to move to where circle actually starts
                shape.circle(viewPoint.x, viewPoint.y, this.radius);
            }
        }
        this.shape = shape.makeImmutable();
    }
    dispose() {
        this.disposeScatterPlot();
        super.dispose();
    }
}
bamboo.register('ScatterPlot', ScatterPlot);
export default ScatterPlot;
//# sourceMappingURL=ScatterPlot.js.map