The logarithmic scale is used to chart numerical data. It can be placed on either the x or y-axis. As the name suggests, logarithmic interpolation is used to determine where a value lies on the axis.
+## Configuration Options
+
+These options extend the [common configuration for all cartesian axes](index.md#configuration-options).
+
+| Name | Type | Description
+| ---- | ---- | -----------
+| `suggestedMax` | `number` | Adjustment used when calculating the maximum data value. [more...](#axis-range-settings)
+| `suggestedMin` | `number` | Adjustment used when calculating the minimum data value. [more...](#axis-range-settings)
+
## Tick Configuration Options
The following options are provided by the logarithmic scale. They are all located in the `ticks` sub-options. These options extend the [common tick configuration](index.md#tick-configuration).
-import {isFinite} from '../helpers/helpers.core';
+import {isFinite, isNullOrUndef} from '../helpers/helpers.core';
import {_setMinAndMaxByKey, log10} from '../helpers/helpers.math';
import Scale from '../core/core.scale';
import LinearScaleBase from './scale.linearbase';
handleTickRangeOptions() {
const me = this;
+ const {suggestedMax, suggestedMin} = me.options;
const DEFAULT_MIN = 1;
const DEFAULT_MAX = 10;
let min = me.min;
let max = me.max;
+ if (!isNullOrUndef(suggestedMin)) {
+ min = Math.min(min, suggestedMin);
+ }
+ if (!isNullOrUndef(suggestedMax)) {
+ max = Math.max(max, suggestedMax);
+ }
+
if (min === max) {
if (min <= 0) { // includes null
min = DEFAULT_MIN;
});
});
+ it('Should correctly determine the max & min when no values provided and suggested minimum and maximum are set', function() {
+ var chart = window.acquireChart({
+ type: 'bar',
+ data: {
+ datasets: [{
+ yAxisID: 'y',
+ data: []
+ }],
+ labels: ['a', 'b', 'c', 'd', 'e', 'f']
+ },
+ options: {
+ scales: {
+ y: {
+ type: 'logarithmic',
+ suggestedMin: 10,
+ suggestedMax: 100
+ }
+ }
+ }
+ });
+
+ expect(chart.scales.y).not.toEqual(undefined); // must construct
+ expect(chart.scales.y.min).toBe(10);
+ expect(chart.scales.y.max).toBe(100);
+ });
});
export type ILogarithmicScaleOptions = ICartesianScaleOptions & {
stacked?: boolean;
+ /**
+ * Adjustment used when calculating the maximum data value.
+ * @see https://www.chartjs.org/docs/next/axes/cartesian/linear#axis-range-settings
+ */
+ suggestedMin?: number;
+ /**
+ * Adjustment used when calculating the minimum data value.
+ * @see https://www.chartjs.org/docs/next/axes/cartesian/linear#axis-range-settings
+ */
+ suggestedMax?: number;
+
ticks: {
/**
* The Intl.NumberFormat options used by the default label formatter