export var getClosestPairDiffAndRange = function (data) {
    if (data.length < 2) {
        return;
    }
    data = data.sort(function (a, b) {
        return a instanceof Date ? a.getTime() - b.getTime() : a - b;
    });
    var minDiff = Number.MAX_VALUE;
    for (var i = 1; i < data.length; i++) {
        var diff = data[i] instanceof Date
            ? data[i].getTime() - data[i - 1].getTime()
            : data[i] - data[i - 1];
        minDiff = Math.min(minDiff, diff);
    }
    var range = data[0] instanceof Date
        ? data[data.length - 1].getTime() - data[0].getTime()
        : data[data.length - 1] - data[0];
    return [minDiff, range];
};
export var calculateAppropriateBarWidth = function (data, totalWidth) {
    var result = getClosestPairDiffAndRange(data);
    if (!result || result[1] === 0) {
        return 16;
    }
    var closestPairDiff = result[0], range = result[1];
    // Refer to https://microsoft.github.io/fluentui-charting-contrib/docs/rfcs/fix-overlapping-bars-on-continuous-axes
    // for the derivation of the following formula.
    var barWidth = Math.round((totalWidth * closestPairDiff) / (2 * range + closestPairDiff));
    return barWidth;
};
//# sourceMappingURL=vbc-utils.js.map