From: stockiNail Date: Wed, 7 Apr 2021 20:45:39 +0000 (+0200) Subject: Apply scale context to ticks scriptable options instead of chart context (#8839) X-Git-Tag: v3.1.0~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ae1064ab95ed16bc6ec6d5103849769268d86eb;p=thirdparty%2FChart.js.git Apply scale context to ticks scriptable options instead of chart context (#8839) * Fixes #8835 * context as argument because protected * fixes test case on formatters * reverts previous commits and sets the scale context in the scale init * changes documentation about linear ticks, adding scriptable Yes --- diff --git a/docs/axes/cartesian/linear.md b/docs/axes/cartesian/linear.md index bf82fc305..2aaf9c532 100644 --- a/docs/axes/cartesian/linear.md +++ b/docs/axes/cartesian/linear.md @@ -23,13 +23,13 @@ Namespace: `options.scales[scaleId]` Namespace: `options.scales[scaleId].ticks` -| Name | Type | Default | Description -| ---- | ---- | ------- | ----------- -| `count` | `number` | `undefined` | The number of ticks to generate. If specified, this overrides the automatic generation. -| `format` | `object` | | The [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) options used by the default label formatter -| `maxTicksLimit` | `number` | `11` | Maximum number of ticks and gridlines to show. -| `precision` | `number` | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places. -| `stepSize` | `number` | | User-defined fixed step size for the scale. [more...](#step-size) +| Name | Type | Scriptable | Default | Description +| ---- | ---- | ------- | ------- | ----------- +| `count` | `number` | Yes | `undefined` | The number of ticks to generate. If specified, this overrides the automatic generation. +| `format` | `object` | Yes | | The [`Intl.NumberFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat) options used by the default label formatter +| `maxTicksLimit` | `number` | Yes | `11` | Maximum number of ticks and gridlines to show. +| `precision` | `number` | Yes | | if defined and `stepSize` is not specified, the step size will be rounded to this many decimal places. +| `stepSize` | `number` | Yes | | User-defined fixed step size for the scale. [more...](#step-size) !!!include(axes/cartesian/_common_ticks.md)!!! diff --git a/src/core/core.scale.js b/src/core/core.scale.js index bdefea4a7..dbdbb18c3 100644 --- a/src/core/core.scale.js +++ b/src/core/core.scale.js @@ -237,7 +237,7 @@ export default class Scale extends Element { */ init(options) { const me = this; - me.options = options; + me.options = options.setContext(me.getContext()); me.axis = options.axis; diff --git a/test/specs/core.controller.tests.js b/test/specs/core.controller.tests.js index fee6832d6..9d4e7aa96 100644 --- a/test/specs/core.controller.tests.js +++ b/test/specs/core.controller.tests.js @@ -413,7 +413,7 @@ describe('Chart', function() { }); expect(chart.scales.x.type).toBe('logarithmic'); - expect(chart.scales.x.options).toBe(chart.options.scales.x); + expect(chart.scales.x.options).toEqual(chart.options.scales.x); expect(chart.scales.x.options).toEqual( jasmine.objectContaining({ _jasmineCheckA: 'a0', @@ -423,7 +423,7 @@ describe('Chart', function() { })); expect(chart.scales.y.type).toBe('time'); - expect(chart.scales.y.options).toBe(chart.options.scales.y); + expect(chart.scales.y.options).toEqual(chart.options.scales.y); expect(chart.scales.y.options).toEqual( jasmine.objectContaining({ _jasmineCheckA: 'a0',