* @private
*/
+/**
+ * @typedef { import("../../types/index.esm").ChartOptions } ChartOptions
+ */
+
/**
* @return {*}
*/
this.options = options || {};
}
+ /**
+ * Will called with chart options after adapter creation.
+ * @param {ChartOptions} chartOptions
+ */
+ // eslint-disable-next-line no-unused-vars
+ init(chartOptions) {}
+
/**
* Returns a map of time formats for the supported formatting units defined
* in Unit as well as 'datetime' representing a detailed date/time string.
const time = scaleOpts.time || (scaleOpts.time = {});
const adapter = this._adapter = new adapters._date(scaleOpts.adapters.date);
+ adapter.init(opts);
+
// Backward compatibility: before introducing adapter, `displayFormats` was
// supposed to contain *all* unit/string pairs but this can't be resolved
// when loading the scale (adapters are loaded afterward), so let's populate
});
});
});
+
+ it('should pass chart options to date adapter', function() {
+ let chartOptions;
+
+ Chart._adapters._date.override({
+ init(options) {
+ chartOptions = options;
+ }
+ });
+
+ var chart = window.acquireChart({
+ type: 'line',
+ data: {},
+ options: {
+ locale: 'es',
+ scales: {
+ x: {
+ type: 'time'
+ },
+ }
+ }
+ });
+
+ expect(chartOptions).toEqual(chart.options);
+ });
});
+import type { ChartOptions } from './index.esm';
+
export type TimeUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
export interface DateAdapter {
override(members: Partial<DateAdapter>): void;
readonly options: unknown;
+ /**
+ * Will called with chart options after adapter creation.
+ * @param {ChartOptions} chartOptions
+ */
+ init(chartOptions: ChartOptions): void;
/**
* Returns a map of time formats for the supported formatting units defined
* in Unit as well as 'datetime' representing a detailed date/time string.