Skip to content

Commit b1c542b

Browse files
committed
Merge branch 'master' into mer-cat/fix-background-color-cartesianscale
2 parents 5ffc493 + e7b8164 commit b1c542b

25 files changed

+259
-64
lines changed

docs/axes/styling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Namespace: `options.scales[scaleId].grid`, it defines options for the grid lines
1515
| `drawTicks` | `boolean` | | | `true` | If true, draw lines beside the ticks in the axis area beside the chart.
1616
| `lineWidth` | `number` | Yes | Yes | `1` | Stroke width of grid lines.
1717
| `offset` | `boolean` | | | `false` | If true, grid lines will be shifted to be between labels. This is set to `true` for a bar chart by default.
18-
| `tickBorderDash` | `number[]` | | | | Length and spacing of the tick mark line. If not set, defaults to the grid line `borderDash` value.
18+
| `tickBorderDash` | `number[]` | Yes | Yes | `[]` | Length and spacing of the tick mark line. If not set, defaults to the grid line `borderDash` value.
1919
| `tickBorderDashOffset` | `number` | Yes | Yes | | Offset for the line dash of the tick mark. If unset, defaults to the grid line `borderDashOffset` value
2020
| `tickColor` | [`Color`](../general/colors.md) | Yes | Yes | | Color of the tick line. If unset, defaults to the grid line color.
2121
| `tickLength` | `number` | | | `8` | Length in pixels that the grid lines will draw into the axis area.

docs/developers/plugins.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ declare module 'chart.js' {
197197
interface PluginOptionsByType<TType extends ChartType> {
198198
customCanvasBackgroundColor?: {
199199
color?: string
200-
}
200+
} | false
201201
}
202202
}
203203
```

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "chart.js",
33
"homepage": "https://www.chartjs.org",
44
"description": "Simple HTML5 charts using the canvas element.",
5-
"version": "4.3.0",
5+
"version": "4.3.1",
66
"license": "MIT",
77
"type": "module",
88
"sideEffects": [

src/controllers/controller.line.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default class LineController extends DatasetController {
5757
line._chart = this.chart;
5858
line._datasetIndex = this.index;
5959
line._decimated = !!_dataset._decimated;
60-
line.points = points;
60+
line.points = points.slice(Math.max(this._drawStart - 1, 0), this._drawStart + this._drawCount);
6161

6262
const options = this.resolveDatasetElementOptions(mode);
6363
if (!this.options.showLine) {

src/helpers/helpers.extras.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function _getStartAndCountOfVisiblePoints(meta: ChartMeta<'line' | 'scatt
9898
if (minDefined) {
9999
start = _limitValue(Math.min(
100100
// @ts-expect-error Need to type _parsed
101-
_lookupByKey(_parsed, iScale.axis, min).lo,
101+
_lookupByKey(_parsed, axis, min).lo,
102102
// @ts-expect-error Need to fix types on _lookupByKey
103103
animationsDisabled ? pointCount : _lookupByKey(points, axis, iScale.getPixelForValue(min)).lo),
104104
0, pointCount - 1);

src/plugins/plugin.legend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export class Legend extends Element {
428428
cursor.x += width + padding;
429429
} else if (typeof legendItem.text !== 'string') {
430430
const fontLineHeight = labelFont.lineHeight;
431-
cursor.y += calculateLegendItemHeight(legendItem, fontLineHeight);
431+
cursor.y += calculateLegendItemHeight(legendItem, fontLineHeight) + padding;
432432
} else {
433433
cursor.y += lineHeight;
434434
}
@@ -575,7 +575,7 @@ function calculateItemHeight(_itemHeight, legendItem, fontLineHeight) {
575575
}
576576

577577
function calculateLegendItemHeight(legendItem, fontLineHeight) {
578-
const labelHeight = legendItem.text ? legendItem.text.length + 0.5 : 0;
578+
const labelHeight = legendItem.text ? legendItem.text.length : 0;
579579
return fontLineHeight * labelHeight;
580580
}
581581

src/scales/scale.time.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export default class TimeScale extends Scale {
445445
* `minor` unit using the given scale time `options`.
446446
* Important: this method can return ticks outside the min and max range, it's the
447447
* responsibility of the calling code to clamp values if needed.
448-
* @private
448+
* @protected
449449
*/
450450
_generate() {
451451
const adapter = this._adapter;
@@ -485,7 +485,7 @@ export default class TimeScale extends Scale {
485485
}
486486

487487
// @ts-ignore
488-
return Object.keys(ticks).sort((a, b) => a - b).map(x => +x);
488+
return Object.keys(ticks).sort(sorter).map(x => +x);
489489
}
490490

491491
/**

src/scales/scale.timeseries.js

+19
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,25 @@ class TimeSeriesScale extends TimeScale {
110110
return table;
111111
}
112112

113+
/**
114+
* Generates all timestamps defined in the data.
115+
* Important: this method can return ticks outside the min and max range, it's the
116+
* responsibility of the calling code to clamp values if needed.
117+
* @protected
118+
*/
119+
_generate() {
120+
const min = this.min;
121+
const max = this.max;
122+
let timestamps = super.getDataTimestamps();
123+
if (!timestamps.includes(min) || !timestamps.length) {
124+
timestamps.splice(0, 0, min);
125+
}
126+
if (!timestamps.includes(max) || timestamps.length === 1) {
127+
timestamps.push(max);
128+
}
129+
return timestamps.sort((a, b) => a - b);
130+
}
131+
113132
/**
114133
* Returns all timestamps
115134
* @return {number[]}

src/types/index.d.ts

+86-44
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,12 @@ export interface Plugin<TType extends ChartType = ChartType, O = AnyObject>
928928
extends ExtendedPlugin<TType, O> {
929929
id: string;
930930

931+
/**
932+
* The events option defines the browser events that the plugin should listen.
933+
* @default ['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove']
934+
*/
935+
events?: (keyof HTMLElementEventMap)[]
936+
931937
/**
932938
* @desc Called when plugin is installed for this chart instance. This hook is also invoked for disabled plugins (options === false).
933939
* @param {Chart} chart - The chart instance.
@@ -2474,7 +2480,11 @@ export type DecimationOptions = LttbDecimationOptions | MinMaxDecimationOptions;
24742480

24752481
export declare const Filler: Plugin;
24762482
export interface FillerOptions {
2483+
<<<<<<< HEAD
24772484
drawTime: "beforeDatasetDraw" | "beforeDatasetsDraw";
2485+
=======
2486+
drawTime: 'beforeDraw' | 'beforeDatasetDraw' | 'beforeDatasetsDraw';
2487+
>>>>>>> master
24782488
propagate: boolean;
24792489
}
24802490

@@ -2706,6 +2716,10 @@ export interface LegendOptions<TType extends ChartType> {
27062716
* @default 10
27072717
*/
27082718
padding: number;
2719+
/**
2720+
* If usePointStyle is true, the width of the point style used for the legend.
2721+
*/
2722+
pointStyleWidth: number;
27092723
/**
27102724
* Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. See Legend Item for details.
27112725
*/
@@ -3256,13 +3270,13 @@ export interface TooltipItem<TType extends ChartType> {
32563270
}
32573271

32583272
export interface PluginOptionsByType<TType extends ChartType> {
3259-
colors: ColorsPluginOptions;
3260-
decimation: DecimationOptions;
3261-
filler: FillerOptions;
3262-
legend: LegendOptions<TType>;
3263-
subtitle: TitleOptions;
3264-
title: TitleOptions;
3265-
tooltip: TooltipOptions<TType>;
3273+
colors: ColorsPluginOptions | false;
3274+
decimation: DecimationOptions | false;
3275+
filler: FillerOptions | false;
3276+
legend: LegendOptions<TType> | false;
3277+
subtitle: TitleOptions | false;
3278+
title: TitleOptions | false;
3279+
tooltip: TooltipOptions<TType> | false;
32663280
}
32673281
export interface PluginChartOptions<TType extends ChartType> {
32683282
plugins: PluginOptionsByType<TType>;
@@ -3314,7 +3328,7 @@ export interface GridLineOptions {
33143328
/**
33153329
* @default []
33163330
*/
3317-
tickBorderDash: number[];
3331+
tickBorderDash: Scriptable<number[], ScriptableScaleContext>;
33183332
/**
33193333
* @default 0
33203334
*/
@@ -3683,7 +3697,66 @@ export declare const LogarithmicScale: ChartComponent & {
36833697
): LogarithmicScale<O>;
36843698
};
36853699

3700+
<<<<<<< HEAD
36863701
export type TimeScaleOptions = Omit<CartesianScaleOptions, "min" | "max"> & {
3702+
=======
3703+
export type TimeScaleTimeOptions = {
3704+
/**
3705+
* Custom parser for dates.
3706+
*/
3707+
parser: string | ((v: unknown) => number);
3708+
/**
3709+
* If defined, dates will be rounded to the start of this unit. See Time Units below for the allowed units.
3710+
*/
3711+
round: false | TimeUnit;
3712+
/**
3713+
* 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.
3714+
* If `number`, the index of the first day of the week (0 - Sunday, 6 - Saturday).
3715+
* @default false
3716+
*/
3717+
isoWeekday: boolean | number;
3718+
/**
3719+
* Sets how different time units are displayed.
3720+
*/
3721+
displayFormats: {
3722+
[key: string]: string;
3723+
};
3724+
/**
3725+
* The format string to use for the tooltip.
3726+
*/
3727+
tooltipFormat: string;
3728+
/**
3729+
* If defined, will force the unit to be a certain type. See Time Units section below for details.
3730+
* @default false
3731+
*/
3732+
unit: false | TimeUnit;
3733+
/**
3734+
* The minimum display format to be used for a time unit.
3735+
* @default 'millisecond'
3736+
*/
3737+
minUnit: TimeUnit;
3738+
};
3739+
3740+
export type TimeScaleTickOptions = {
3741+
/**
3742+
* Ticks generation input values:
3743+
* - 'auto': generates "optimal" ticks based on scale size and time options.
3744+
* - 'data': generates ticks from data (including labels from data `{t|x|y}` objects).
3745+
* - 'labels': generates ticks from user given `data.labels` values ONLY.
3746+
* @see https://github.com./chartjs/Chart.js/pull/4507
3747+
* @since 2.7.0
3748+
* @default 'auto'
3749+
*/
3750+
source: 'labels' | 'auto' | 'data';
3751+
/**
3752+
* The number of units between grid lines.
3753+
* @default 1
3754+
*/
3755+
stepSize: number;
3756+
};
3757+
3758+
export type TimeScaleOptions = Omit<CartesianScaleOptions, 'min' | 'max'> & {
3759+
>>>>>>> master
36873760
min: string | number;
36883761
max: string | number;
36893762
suggestedMin: string | number;
@@ -3711,43 +3784,9 @@ export type TimeScaleOptions = Omit<CartesianScaleOptions, "min" | "max"> & {
37113784
date: unknown;
37123785
};
37133786

3714-
time: {
3715-
/**
3716-
* Custom parser for dates.
3717-
*/
3718-
parser: string | ((v: unknown) => number);
3719-
/**
3720-
* If defined, dates will be rounded to the start of this unit. See Time Units below for the allowed units.
3721-
*/
3722-
round: false | TimeUnit;
3723-
/**
3724-
* 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.
3725-
* If `number`, the index of the first day of the week (0 - Sunday, 6 - Saturday).
3726-
* @default false
3727-
*/
3728-
isoWeekday: boolean | number;
3729-
/**
3730-
* Sets how different time units are displayed.
3731-
*/
3732-
displayFormats: {
3733-
[key: string]: string;
3734-
};
3735-
/**
3736-
* The format string to use for the tooltip.
3737-
*/
3738-
tooltipFormat: string;
3739-
/**
3740-
* If defined, will force the unit to be a certain type. See Time Units section below for details.
3741-
* @default false
3742-
*/
3743-
unit: false | TimeUnit;
3744-
/**
3745-
* The minimum display format to be used for a time unit.
3746-
* @default 'millisecond'
3747-
*/
3748-
minUnit: TimeUnit;
3749-
};
3787+
time: TimeScaleTimeOptions;
37503788

3789+
<<<<<<< HEAD
37513790
ticks: {
37523791
/**
37533792
* Ticks generation input values:
@@ -3765,6 +3804,9 @@ export type TimeScaleOptions = Omit<CartesianScaleOptions, "min" | "max"> & {
37653804
*/
37663805
stepSize: number;
37673806
};
3807+
=======
3808+
ticks: TimeScaleTickOptions;
3809+
>>>>>>> master
37683810
};
37693811

37703812
export interface TimeScale<O extends TimeScaleOptions = TimeScaleOptions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = {
2+
config: {
3+
type: 'line',
4+
data: {
5+
datasets: [
6+
{
7+
data: [
8+
{x: -10, y: 150},
9+
{x: 0, y: 81},
10+
{x: 10, y: 49},
11+
{x: 20, y: 32},
12+
{x: 30, y: 21},
13+
{x: 35, y: 1},
14+
{x: 40, y: 16},
15+
{x: 45, y: 13},
16+
],
17+
borderColor: '#ff0000',
18+
cubicInterpolationMode: 'monotone'
19+
}
20+
]
21+
},
22+
options: {
23+
scales: {
24+
x: {display: false, type: 'linear', min: 5, max: 37},
25+
y: {display: false}
26+
}
27+
}
28+
},
29+
options: {
30+
canvas: {
31+
height: 256,
32+
width: 512
33+
}
34+
}
35+
};
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = {
2+
config: {
3+
type: 'line',
4+
data: {
5+
datasets: [
6+
{
7+
data: [
8+
{x: -10, y: 150},
9+
{x: 0, y: 81},
10+
{x: 10, y: 49},
11+
{x: 20, y: 32},
12+
{x: 30, y: 21},
13+
{x: 35, y: 1},
14+
{x: 40, y: 16},
15+
{x: 45, y: 13},
16+
],
17+
borderColor: '#ff0000',
18+
cubicInterpolationMode: 'monotone'
19+
}
20+
]
21+
},
22+
options: {
23+
scales: {
24+
x: {display: false, type: 'linear', max: 30},
25+
y: {display: false}
26+
}
27+
}
28+
},
29+
options: {
30+
canvas: {
31+
height: 256,
32+
width: 512
33+
}
34+
}
35+
};
Loading
Loading

0 commit comments

Comments
 (0)