private static getXAxisValuesToDisplay()

in src/visual.ts [611:672]


    private static getXAxisValuesToDisplay(
        scale: TimeScale | LinearScale,
        rotate: boolean,
        isScalar: boolean,
        dateFormat: XAxisDateFormat,
        widthOfXAxisLabel: number): (Date | number)[] {
        let genScale = <any>scale;

        let tickWidth = rotate
            ? Visual.XAxisTickHeight * (rotate ? Math.abs(Math.sin(Visual.AxisTickRotateAngle * Math.PI / 180)) : 0)
            : widthOfXAxisLabel;
        let tickSpace = Visual.XAxisTickSpace;

        if (scale.range()[1] < tickWidth) {
            return [];
        }

        let minValue = scale.invert(scale.range()[0] + tickWidth / 2);
        let maxValue = scale.invert(scale.range()[1] - tickWidth / 2);
        let width = scale.range()[1] - scale.range()[0];

        let maxTicks: number = Math.floor((width + tickSpace) / (tickWidth + tickSpace));
        if (rotate) {
            maxTicks = Math.min(Visual.MinimumTicksToRotate, maxTicks);
        }

        let values = [];
        if (isScalar) {
            values = d3Range(<any>minValue, <any>maxValue, (<any>maxValue - <any>minValue) / (maxTicks * 100));
        } else {
            values = (dateFormat === XAxisDateFormat.TimeOnly ? timeMinute : timeDay)
                .range(<any>minValue, <any>maxValue);
        }

        if (!values.length || last(values) < maxValue) {
            values.push(maxValue);
        }

        if (!maxTicks) {
            return [];
        }

        maxTicks = Math.min(values.length, maxTicks);
        const step = (values.length - 1) / (maxTicks - 1);
        let valuesIndexses: number[] = [];

        for (let i = 0; i < values.length - 1; i = i + step) {
            valuesIndexses.push(i);
        }
        valuesIndexses.push(values.length - 1);
        values = valuesIndexses.map(x => values[Math.round(x)]);

        for (let i = 1; i < values.length; i++) {
            let prevXValue = genScale(values[i - 1]);
            let curXValue = genScale(values[i]);
            if (curXValue - prevXValue < tickWidth + tickSpace / 3) {
                values.splice(i--, 1);
            }
        }

        return values;
    }