]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Move scale defaults to separate file (#8692)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sun, 21 Mar 2021 22:13:50 +0000 (00:13 +0200)
committerGitHub <noreply@github.com>
Sun, 21 Mar 2021 22:13:50 +0000 (18:13 -0400)
src/core/core.scale.defaults.js [new file with mode: 0644]
src/core/core.scale.js

diff --git a/src/core/core.scale.defaults.js b/src/core/core.scale.defaults.js
new file mode 100644 (file)
index 0000000..8aa6f09
--- /dev/null
@@ -0,0 +1,90 @@
+import defaults from './core.defaults';
+import Ticks from './core.ticks';
+
+defaults.set('scale', {
+  display: true,
+  offset: false,
+  reverse: false,
+  beginAtZero: false,
+
+  /**
+        * Scale boundary strategy (bypassed by min/max time options)
+        * - `data`: make sure data are fully visible, ticks outside are removed
+        * - `ticks`: make sure ticks are fully visible, data outside are truncated
+        * @see https://github.com/chartjs/Chart.js/pull/4556
+        * @since 3.0.0
+        */
+  bounds: 'ticks',
+
+  /**
+   * Addition grace added to max and reduced from min data value.
+   * @since 3.0.0
+   */
+  grace: 0,
+
+  // grid line settings
+  grid: {
+    display: true,
+    lineWidth: 1,
+    drawBorder: true,
+    drawOnChartArea: true,
+    drawTicks: true,
+    tickLength: 8,
+    tickWidth: (_ctx, options) => options.lineWidth,
+    tickColor: (_ctx, options) => options.color,
+    offset: false,
+    borderDash: [],
+    borderDashOffset: 0.0,
+    borderColor: (_ctx, options) => options.color,
+    borderWidth: (_ctx, options) => options.lineWidth
+  },
+
+  // scale title
+  title: {
+    // display property
+    display: false,
+
+    // actual label
+    text: '',
+
+    // top/bottom padding
+    padding: {
+      top: 4,
+      bottom: 4
+    }
+  },
+
+  // label settings
+  ticks: {
+    minRotation: 0,
+    maxRotation: 50,
+    mirror: false,
+    textStrokeWidth: 0,
+    textStrokeColor: '',
+    padding: 3,
+    display: true,
+    autoSkip: true,
+    autoSkipPadding: 3,
+    labelOffset: 0,
+    // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
+    callback: Ticks.formatters.values,
+    minor: {},
+    major: {},
+    align: 'center',
+    crossAlign: 'near',
+  }
+});
+
+defaults.route('scale.ticks', 'color', '', 'color');
+defaults.route('scale.grid', 'color', '', 'borderColor');
+defaults.route('scale.title', 'color', '', 'color');
+
+defaults.describe('scale', {
+  _fallback: false,
+  _scriptable: (name) => !name.startsWith('before') && !name.startsWith('after') && name !== 'callback' && name !== 'parser',
+  _indexable: (name) => name !== 'borderDash' && name !== 'tickBorderDash',
+});
+
+defaults.describe('scales', {
+  _fallback: 'scale',
+});
index 120937ce98080d417658720140b1bc2300d46a79..3913ad30291792607ea5c8e110c350a37251d1f9 100644 (file)
@@ -1,13 +1,16 @@
-import defaults from './core.defaults';
 import Element from './core.element';
 import {_alignPixel, _measureText, renderText, clipArea, unclipArea} from '../helpers/helpers.canvas';
 import {callback as call, each, finiteOrDefault, isArray, isFinite, isNullOrUndef, isObject} from '../helpers/helpers.core';
 import {toDegrees, toRadians, _int16Range, _limitValue, HALF_PI} from '../helpers/helpers.math';
 import {_alignStartEnd, _toLeftRightCenter} from '../helpers/helpers.extras';
 import {toFont, toPadding} from '../helpers/helpers.options';
-import Ticks from './core.ticks';
+
+import './core.scale.defaults';
+
+
 import {autoSkip} from './core.scale.autoskip';
 
+
 const reverseAlign = (align) => align === 'left' ? 'right' : align === 'right' ? 'left' : align;
 const offsetFromEdge = (scale, edge, offset) => edge === 'top' || edge === 'left' ? scale[edge] + offset : scale[edge] - offset;
 
@@ -16,94 +19,6 @@ const offsetFromEdge = (scale, edge, offset) => edge === 'top' || edge === 'left
  * @typedef {{value:number | string, label?:string, major?:boolean, $context?:any}} Tick
  */
 
-defaults.set('scale', {
-  display: true,
-  offset: false,
-  reverse: false,
-  beginAtZero: false,
-
-  /**
-        * Scale boundary strategy (bypassed by min/max time options)
-        * - `data`: make sure data are fully visible, ticks outside are removed
-        * - `ticks`: make sure ticks are fully visible, data outside are truncated
-        * @see https://github.com/chartjs/Chart.js/pull/4556
-        * @since 3.0.0
-        */
-  bounds: 'ticks',
-
-  /**
-   * Addition grace added to max and reduced from min data value.
-   * @since 3.0.0
-   */
-  grace: 0,
-
-  // grid line settings
-  grid: {
-    display: true,
-    lineWidth: 1,
-    drawBorder: true,
-    drawOnChartArea: true,
-    drawTicks: true,
-    tickLength: 8,
-    tickWidth: (_ctx, options) => options.lineWidth,
-    tickColor: (_ctx, options) => options.color,
-    offset: false,
-    borderDash: [],
-    borderDashOffset: 0.0,
-    borderColor: (_ctx, options) => options.color,
-    borderWidth: (_ctx, options) => options.lineWidth
-  },
-
-  // scale title
-  title: {
-    // display property
-    display: false,
-
-    // actual label
-    text: '',
-
-    // top/bottom padding
-    padding: {
-      top: 4,
-      bottom: 4
-    }
-  },
-
-  // label settings
-  ticks: {
-    minRotation: 0,
-    maxRotation: 50,
-    mirror: false,
-    textStrokeWidth: 0,
-    textStrokeColor: '',
-    padding: 3,
-    display: true,
-    autoSkip: true,
-    autoSkipPadding: 3,
-    labelOffset: 0,
-    // We pass through arrays to be rendered as multiline labels, we convert Others to strings here.
-    callback: Ticks.formatters.values,
-    minor: {},
-    major: {},
-    align: 'center',
-    crossAlign: 'near',
-  }
-});
-
-defaults.route('scale.ticks', 'color', '', 'color');
-defaults.route('scale.grid', 'color', '', 'borderColor');
-defaults.route('scale.title', 'color', '', 'color');
-
-defaults.describe('scale', {
-  _fallback: false,
-  _scriptable: (name) => !name.startsWith('before') && !name.startsWith('after') && name !== 'callback' && name !== 'parser',
-  _indexable: (name) => name !== 'borderDash' && name !== 'tickBorderDash',
-});
-
-defaults.describe('scales', {
-  _fallback: 'scale',
-});
-
 /**
  * Returns a new array containing numItems from arr
  * @param {any[]} arr