]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Types/Allow min-max as string timescale (#9985)
authorJacco van den Berg <39033624+LeeLenaleee@users.noreply.github.com>
Tue, 14 Dec 2021 16:50:37 +0000 (17:50 +0100)
committerGitHub <noreply@github.com>
Tue, 14 Dec 2021 16:50:37 +0000 (11:50 -0500)
* allow for string in time scale min max config

* add min-max type to docs

* typo

docs/axes/cartesian/time.md
types/index.esm.d.ts

index 5c609d2175da7083875d6119887c3d33306046f9..c55ee9ed9f38ba454d8becab463b576d8da5f4d8 100644 (file)
@@ -24,6 +24,8 @@ Namespace: `options.scales[scaleId]`
 
 | Name | Type | Default | Description
 | ---- | ---- | ------- | -----------
+| `min` | `string`\|`number` | | The minimum item to display. [more...](#min-max-configuration)
+| `max` | `string`\|`number` | | The maximum item to display. [more...](#min-max-configuration)
 | `adapters.date` | `object` | `{}` | Options for adapter for external date library if that adapter needs or supports options
 | `bounds` | `string` | `'data'` | Determines the scale bounds. [more...](./index.md#scale-bounds)
 | `ticks.source` | `string` | `'auto'` | How ticks are generated. [more...](#ticks-source)
@@ -124,6 +126,38 @@ If this property is defined as a string, it is interpreted as a custom format to
 
 If this is a function, it must return a type that can be handled by your date adapter's `parse` method.
 
+## Min Max Configuration
+
+For both the `min` and `max` properties, the value must be `string` that is parsable by your date adapter or a number with the amount of milliseconds that have elapsed since UNIX epoch.
+In the example below the x axis will start at 7 October 2021.
+
+```javascript
+let chart = new Chart(ctx, {
+    type: 'line',
+    data: {
+        datasets: [{
+            data: [{
+                x: '2021-11-06 23:39:30',
+                y: 50
+            }, {
+                x: '2021-11-07 01:00:28',
+                y: 60
+            }, {
+                x: '2021-11-07 09:00:28',
+                y: 20
+            }]
+        }],
+    },
+    options: {
+        scales: {
+            x: {
+                min: '2021-11-07 00:00:00',
+            }
+        }
+    }
+});
+```
+
 ## Internal data format
 
 Internally time scale uses milliseconds since epoch
index 7d7721a7d4dadce5f3e1f9aaa8e72482583feacf..92aaa58cc6bfb5a292f628e68c2d858ad4f306cb 100644 (file)
@@ -3174,6 +3174,8 @@ export const LogarithmicScale: ChartComponent & {
 };
 
 export type TimeScaleOptions = CartesianScaleOptions & {
+  min: string | number;
+  max: string | number;
   /**
    * Scale boundary strategy (bypassed by min/max time options)
    * - `data`: make sure data are fully visible, ticks outside are removed