mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-06 16:26:52 +01:00
Optimize context object construction (#8413)
* perf: context construction * avoid setPrototypeOf
This commit is contained in:
@@ -737,14 +737,7 @@ class Chart {
|
||||
}
|
||||
|
||||
getContext() {
|
||||
return this.$context || (this.$context = Object.create(null, {
|
||||
chart: {
|
||||
value: this
|
||||
},
|
||||
type: {
|
||||
value: 'chart'
|
||||
}
|
||||
}));
|
||||
return this.$context || (this.$context = {chart: this, type: 'chart'});
|
||||
}
|
||||
|
||||
getVisibleDatasetCount() {
|
||||
|
||||
@@ -149,54 +149,27 @@ function getFirstScaleId(chart, axis) {
|
||||
}
|
||||
|
||||
function createDatasetContext(parent, index, dataset) {
|
||||
return Object.create(parent, {
|
||||
active: {
|
||||
writable: true,
|
||||
value: false
|
||||
},
|
||||
dataset: {
|
||||
value: dataset
|
||||
},
|
||||
datasetIndex: {
|
||||
value: index
|
||||
},
|
||||
index: {
|
||||
get() {
|
||||
return this.datasetIndex;
|
||||
}
|
||||
},
|
||||
type: {
|
||||
value: 'dataset'
|
||||
return Object.assign(Object.create(parent),
|
||||
{
|
||||
active: false,
|
||||
dataset,
|
||||
datasetIndex: index,
|
||||
index,
|
||||
type: 'dataset'
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
function createDataContext(parent, index, point, raw, element) {
|
||||
return Object.create(parent, {
|
||||
active: {
|
||||
writable: true,
|
||||
value: false
|
||||
},
|
||||
dataIndex: {
|
||||
value: index
|
||||
},
|
||||
parsed: {
|
||||
value: point
|
||||
},
|
||||
raw: {
|
||||
value: raw
|
||||
},
|
||||
element: {
|
||||
value: element
|
||||
},
|
||||
index: {
|
||||
get() {
|
||||
return this.dataIndex;
|
||||
}
|
||||
},
|
||||
type: {
|
||||
value: 'data',
|
||||
}
|
||||
return Object.assign(Object.create(parent), {
|
||||
active: false,
|
||||
dataIndex: index,
|
||||
parsed: point,
|
||||
raw,
|
||||
element,
|
||||
index,
|
||||
mode: 'default',
|
||||
type: 'data'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -282,27 +282,17 @@ function skip(ticks, newTicks, spacing, majorStart, majorEnd) {
|
||||
}
|
||||
|
||||
function createScaleContext(parent, scale) {
|
||||
return Object.create(parent, {
|
||||
scale: {
|
||||
value: scale
|
||||
},
|
||||
type: {
|
||||
value: 'scale'
|
||||
}
|
||||
return Object.assign(Object.create(parent), {
|
||||
scale,
|
||||
type: 'scale'
|
||||
});
|
||||
}
|
||||
|
||||
function createTickContext(parent, index, tick) {
|
||||
return Object.create(parent, {
|
||||
tick: {
|
||||
value: tick
|
||||
},
|
||||
index: {
|
||||
value: index
|
||||
},
|
||||
type: {
|
||||
value: 'tick'
|
||||
}
|
||||
return Object.assign(Object.create(parent), {
|
||||
tick,
|
||||
index,
|
||||
type: 'tick'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user