export function createAxis()

in src/axisHelper.ts [117:208]


export function createAxis(options: CreateAxisOptionsExtended): IAxisProperties {
    let pixelSpan: number = options.pixelSpan,
        dataDomain: number[] = options.dataDomain,
        metaDataColumn: DataViewMetadataColumn = options.metaDataColumn,
        formatString: string = options.formatString,
        outerPadding: number = options.outerPadding || DefaultOuterPadding,
        isCategoryAxis: boolean = !!options.isCategoryAxis,
        isScalar: boolean = !!options.isScalar,
        isVertical: boolean = !!options.isVertical,
        useTickIntervalForDisplayUnits: boolean = !!options.useTickIntervalForDisplayUnits,
        getValueFn: (index: number, valueType: ValueType) => any = options.getValueFn,
        categoryThickness: number = options.categoryThickness,
        axisDisplayUnits: number = options.axisDisplayUnits,
        axisPrecision: number = options.axisPrecision,
        is100Pct: boolean = !!options.is100Pct,
        tickLabelPadding: number = options.tickLabelPadding || TickLabelPadding,
        onRight: boolean = options.onRight || false;

    let dataType: ValueType = getCategoryValueType(metaDataColumn, isScalar);

    // Create the Scale
    let scaleResult: CreateScaleResult = createScale(options);
    let scale: LinearScale<any, any> = scaleResult.scale;
    let bestTickCount: number = scaleResult.bestTickCount;
    let scaleDomain: number[] = scale.domain();
    let isLogScaleAllowed: boolean = isLogScalePossible(dataDomain, dataType);

    // fix categoryThickness if scalar and the domain was adjusted when making the scale "nice"
    categoryThickness = fixCategoryThickness(categoryThickness, isScalar, dataDomain, scaleDomain);

    // Prepare Tick Values for formatting
    let tickValues: any[];
    if (isScalar && bestTickCount === 1) {
        tickValues = [dataDomain[0]];
    }
    else {
        let minTickInterval: number = isScalar
            ? getMinTickValueInterval(formatString, dataType, is100Pct)
            : undefined;

        tickValues = getRecommendedTickValues(bestTickCount, scale, dataType, isScalar, minTickInterval);
    }

    if (options.scaleType && options.scaleType === axisScale.log && isLogScaleAllowed) {
        tickValues = tickValues.filter((d: any) => {
            return powerOfTen(d);
        });
    }

    let formatter: IValueFormatter = createFormatter(
        scaleDomain,
        dataDomain,
        dataType,
        isScalar,
        formatString,
        bestTickCount,
        tickValues,
        getValueFn,
        useTickIntervalForDisplayUnits,
        axisDisplayUnits,
        axisPrecision);

    // sets default orientation only, cartesianChart will fix y2 for comboChart
    // tickSize(pixelSpan) is used to create gridLines
    let axis = (isVertical
        ? onRight ? d3.axisRight(scale) : d3.axisLeft(scale)
        : d3.axisBottom(scale)
    );

    let formattedTickValues: any[] = [];
    if (metaDataColumn) {
        formattedTickValues = formatAxisTickValues(axis, tickValues, formatter, dataType, getValueFn);
    }

    let xLabelMaxWidth: number = getXLabelMaxWidth(isScalar, categoryThickness, tickLabelPadding, tickValues, scale, pixelSpan);

    return {
        scale: scale,
        axis: axis,
        formatter: formatter,
        values: formattedTickValues,
        axisType: dataType,
        axisLabel: null,
        isCategoryAxis: isCategoryAxis,
        xLabelMaxWidth: xLabelMaxWidth,
        categoryThickness: categoryThickness,
        outerPadding: outerPadding,
        usingDefaultDomain: scaleResult.usingDefaultDomain,
        isLogScaleAllowed: isLogScaleAllowed,
        dataDomain: dataDomain,
    };
}