]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
isoWeekday time options on time scale as number (#7768)
authorstockiNail <stocki.nail@gmail.com>
Mon, 7 Sep 2020 20:19:45 +0000 (22:19 +0200)
committerGitHub <noreply@github.com>
Mon, 7 Sep 2020 20:19:45 +0000 (16:19 -0400)
* fixed default of tension property of line element
* Fixes isoWeekday on time scale #7749
* adds checking on isoWeekDay options in _generate function

docs/docs/axes/cartesian/time.md
src/scales/scale.time.js
types/scales/index.d.ts

index 6fb5d1a36e749181f920f8b880cac18733540f23..43438bae1d2ce7fd49ba12a5c80f9f24168e2500 100644 (file)
@@ -28,7 +28,7 @@ The following options are provided by the time scale. You may also set options p
 | `bounds` | `string` | `'data'` | Determines the scale bounds. [more...](#scale-bounds)
 | `ticks.source` | `string` | `'auto'` | How ticks are generated. [more...](#ticks-source)
 | `time.displayFormats` | `object` | | Sets how different time units are displayed. [more...](#display-formats)
-| `time.isoWeekday` | `boolean` | `false` | If true and the unit is set to 'week', then the first day of the week will be Monday. Otherwise, it will be Sunday.
+| `time.isoWeekday` | `boolean`\|`number` | `false` | If `boolean` and true and the unit is set to 'week', then the first day of the week will be Monday. Otherwise, it will be Sunday. If `number`, the index of the first day of the week (0 - Sunday, 6 - Saturday)
 | `time.parser` | `string`\|`function` | | Custom parser for dates. [more...](#parser)
 | `time.round` | `string` | `false` | If defined, dates will be rounded to the start of this unit. See [Time Units](#time-units) below for the allowed units.
 | `time.tooltipFormat` | `string` | | The format string to use for the tooltip.
index 2df0618838408be0cb3923e7bcda1b1070e59b01..f8ad236b1661df531784f5ab51b46724b2162e63 100644 (file)
@@ -1,6 +1,6 @@
 import adapters from '../core/core.adapters';
 import {isFinite, isNullOrUndef, mergeIf, valueOrDefault} from '../helpers/helpers.core';
-import {toRadians} from '../helpers/helpers.math';
+import {toRadians, isNumber} from '../helpers/helpers.math';
 import Scale from '../core/core.scale';
 import {_arrayUnique, _filterBetween, _lookup} from '../helpers/helpers.collection';
 
@@ -71,7 +71,7 @@ function parse(scale, input) {
        }
 
        if (round) {
-               value = round === 'week' && isoWeekday
+               value = round === 'week' && (isNumber(isoWeekday) || isoWeekday === true)
                        ? scale._adapter.startOf(value, 'isoWeek', isoWeekday)
                        : scale._adapter.startOf(value, round);
        }
@@ -400,17 +400,18 @@ export default class TimeScale extends Scale {
                const minor = timeOpts.unit || determineUnitForAutoTicks(timeOpts.minUnit, min, max, me._getLabelCapacity(min));
                const stepSize = valueOrDefault(timeOpts.stepSize, 1);
                const weekday = minor === 'week' ? timeOpts.isoWeekday : false;
+               const hasWeekday = isNumber(weekday) || weekday === true;
                const ticks = {};
                let first = min;
                let time;
 
                // For 'week' unit, handle the first day of week option
-               if (weekday) {
+               if (hasWeekday) {
                        first = +adapter.startOf(first, 'isoWeek', weekday);
                }
 
                // Align first ticks on unit
-               first = +adapter.startOf(first, weekday ? 'day' : minor);
+               first = +adapter.startOf(first, hasWeekday ? 'day' : minor);
 
                // Prevent browser from freezing in case user options request millions of milliseconds
                if (adapter.diff(max, min, minor) > 100000 * stepSize) {
index de939856009f07a7fb6758a8f25d3484e3ae2a5b..729aaf457f43da0fc30dcf0cbbddaee206799c0b 100644 (file)
@@ -276,10 +276,11 @@ export type ITimeScaleOptions = ICartesianScaleOptions & {
      */
     round: false | TimeUnit;
     /**
-     * If true and the unit is set to 'week', then the first day of the week will be Monday. Otherwise, it will be Sunday.
+     * If boolean and true and the unit is set to 'week', then the first day of the week will be Monday. Otherwise, it will be Sunday. 
+     * If `number`, the index of the first day of the week (0 - Sunday, 6 - Saturday).
      * @default false
      */
-    isoWeekday: false | string;
+    isoWeekday: false | number;
     /**
      * Sets how different time units are displayed.
      * @see https://www.chartjs.org/docs/next/axes/cartesian/time#display-formats