import '../../assert/js/assert.js';
import '../../globals.js';
// Copyright 2020-2023, University of Colorado Boulder
/**
 * Shows tick marks within or next to a chart.
 *
 * @author Sam Reid (PhET Interactive Simulations)
 */
import Bounds2 from '../../dot/js/Bounds2.js';
import { Shape } from '../../kite/js/imports.js';
import Orientation from '../../phet-core/js/Orientation.js';
import { Path } from '../../scenery/js/imports.js';
import bamboo from './bamboo.js';
import optionize from '../../phet-core/js/optionize.js';
class TickMarkSet extends Path {
    /**
     * @param chartTransform
     * @param axisOrientation - the progression of the ticks.  For instance HORIZONTAL has ticks at x=0,1,2, etc.
     * @param spacing - in model coordinates
     * @param [providedOptions]
     */
    constructor(chartTransform, axisOrientation, spacing, providedOptions) {
        const options = optionize()({
            // SelfOptions
            value: 0, // appear on the axis by default
            edge: null,
            origin: 0,
            skipCoordinates: [],
            stroke: 'black',
            lineWidth: 1,
            extent: TickMarkSet.DEFAULT_EXTENT,
            clippingType: 'strict'
        }, providedOptions);
        if (options.edge) {
            assert && assert(options.value === 0, 'value and edge are mutually exclusive');
        }
        super(null, options);
        this.chartTransform = chartTransform;
        this.axisOrientation = axisOrientation;
        this.spacing = spacing;
        this.value = options.value;
        this.edge = options.edge;
        this.origin = options.origin;
        this.skipCoordinates = options.skipCoordinates;
        this.extent = options.extent;
        this.clippingType = options.clippingType;
        // Initialize
        this.update();
        // Update when the transform changes.
        const changedListener = () => this.update();
        chartTransform.changedEmitter.addListener(changedListener);
        this.disposeTickMarkSet = () => chartTransform.changedEmitter.removeListener(changedListener);
    }
    setSpacing(spacing) {
        if (spacing !== this.spacing) {
            this.spacing = spacing;
            this.update();
        }
    }
    getSpacing() {
        return this.spacing;
    }
    update() {
        const shape = new Shape();
        this.chartTransform.forEachSpacing(this.axisOrientation, this.spacing, this.origin, this.clippingType, (modelCoordinate, viewCoordinate) => {
            if (!this.skipCoordinates.includes(modelCoordinate)) {
                const tickBounds = new Bounds2(0, 0, 0, 0);
                if (this.axisOrientation === Orientation.HORIZONTAL) {
                    const viewY = this.edge === 'min' ? this.chartTransform.viewHeight :
                        this.edge === 'max' ? 0 :
                            this.chartTransform.modelToView(this.axisOrientation.opposite, this.value);
                    shape.moveTo(viewCoordinate, viewY - this.extent / 2);
                    shape.lineTo(viewCoordinate, viewY + this.extent / 2);
                    tickBounds.setMinMax(viewCoordinate, viewY - this.extent / 2, viewCoordinate, viewY + this.extent / 2);
                }
                else {
                    const viewX = this.edge === 'min' ? 0 :
                        this.edge === 'max' ? this.chartTransform.viewWidth :
                            this.chartTransform.modelToView(this.axisOrientation.opposite, this.value);
                    shape.moveTo(viewX - this.extent / 2, viewCoordinate);
                    shape.lineTo(viewX + this.extent / 2, viewCoordinate);
                    tickBounds.setMinMax(viewX - this.extent / 2, viewCoordinate, viewX + this.extent / 2, viewCoordinate);
                }
            }
        });
        this.shape = shape.makeImmutable();
    }
    dispose() {
        this.disposeTickMarkSet();
        super.dispose();
    }
    getSpacingBorders() {
        return this.chartTransform.getSpacingBorders(this.axisOrientation, this.spacing, this.origin, this.clippingType);
    }
}
TickMarkSet.DEFAULT_EXTENT = 10;
bamboo.register('TickMarkSet', TickMarkSet);
export default TickMarkSet;
//# sourceMappingURL=TickMarkSet.js.map