Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass some chart options to DateAdapter #10528

Merged
merged 2 commits into from Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/core.adapters.js
Expand Up @@ -26,8 +26,9 @@ function abstract() {

export class DateAdapter {

constructor(options) {
constructor(options, chartOptions) {
dangreen marked this conversation as resolved.
Show resolved Hide resolved
this.options = options || {};
this.chartOptions = chartOptions || {};
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/scales/scale.time.js
Expand Up @@ -221,7 +221,10 @@ export default class TimeScale extends Scale {

init(scaleOpts, opts) {
const time = scaleOpts.time || (scaleOpts.time = {});
const adapter = this._adapter = new adapters._date(scaleOpts.adapters.date);
const adapterChartOpts = {
locale: opts.locale
};
const adapter = this._adapter = new adapters._date(scaleOpts.adapters.date, adapterChartOpts);
dangreen marked this conversation as resolved.
Show resolved Hide resolved

// Backward compatibility: before introducing adapter, `displayFormats` was
// supposed to contain *all* unit/string pairs but this can't be resolved
Expand Down
33 changes: 33 additions & 0 deletions test/specs/scale.time.tests.js
Expand Up @@ -1235,4 +1235,37 @@ describe('Time scale tests', function() {
});
});
});

it('should pass default locale to date adapter', function() {
var chart = window.acquireChart({
type: 'line',
data: {},
options: {
scales: {
x: {
type: 'time'
},
}
}
});

expect(chart.scales.x._adapter.chartOptions.locale).toBe('en-US');
dangreen marked this conversation as resolved.
Show resolved Hide resolved
});

it('should pass locale to date adapter from options', function() {
var chart = window.acquireChart({
type: 'line',
data: {},
options: {
locale: 'es',
scales: {
x: {
type: 'time'
},
}
}
});

expect(chart.scales.x._adapter.chartOptions.locale).toBe('es');
});
});
3 changes: 3 additions & 0 deletions types/adapters.d.ts
Expand Up @@ -4,6 +4,9 @@ export interface DateAdapter {
// Override one or multiple of the methods to adjust to the logic of the current date library.
override(members: Partial<DateAdapter>): void;
readonly options: unknown;
readonly chartOptions: {
locale?: string;
};

/**
* Returns a map of time formats for the supported formatting units defined
Expand Down