Add null guards for querySelector results and division by zero in AttributesFilter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 17:10:11 +08:00
parent 008339a23d
commit 4c2a79a514

View File

@@ -650,6 +650,7 @@ function getPercentLabel(val) {
* @param {object} chart - The Chart.js instance data. * @param {object} chart - The Chart.js instance data.
*/ */
function resizeMask(chart) { function resizeMask(chart) {
if (selectRange.value === 0) return;
const from = (selectArea.value[0] * 0.01) / (selectRange.value * 0.01); const from = (selectArea.value[0] * 0.01) / (selectRange.value * 0.01);
const to = (selectArea.value[1] * 0.01) / (selectRange.value * 0.01); const to = (selectArea.value[1] * 0.01) / (selectRange.value * 0.01);
resizeLeftMask(chart, from); resizeLeftMask(chart, from);
@@ -663,6 +664,7 @@ function resizeMask(chart) {
function resizeLeftMask(chart, from) { function resizeLeftMask(chart, from) {
const canvas = document.querySelector("#chartCanvasId canvas"); const canvas = document.querySelector("#chartCanvasId canvas");
const mask = document.getElementById("chart-mask-left"); const mask = document.getElementById("chart-mask-left");
if (!canvas || !mask) return;
mask.style.left = `${canvas.offsetLeft + chart.chartArea.left}px`; mask.style.left = `${canvas.offsetLeft + chart.chartArea.left}px`;
mask.style.width = `${chart.chartArea.width * from}px`; mask.style.width = `${chart.chartArea.width * from}px`;
mask.style.top = `${canvas.offsetTop + chart.chartArea.top}px`; mask.style.top = `${canvas.offsetTop + chart.chartArea.top}px`;
@@ -676,6 +678,7 @@ function resizeLeftMask(chart, from) {
function resizeRightMask(chart, to) { function resizeRightMask(chart, to) {
const canvas = document.querySelector("#chartCanvasId canvas"); const canvas = document.querySelector("#chartCanvasId canvas");
const mask = document.getElementById("chart-mask-right"); const mask = document.getElementById("chart-mask-right");
if (!canvas || !mask) return;
mask.style.left = `${canvas.offsetLeft + chart.chartArea.left + chart.chartArea.width * to}px`; mask.style.left = `${canvas.offsetLeft + chart.chartArea.left + chart.chartArea.width * to}px`;
mask.style.width = `${chart.chartArea.width * (1 - to)}px`; mask.style.width = `${chart.chartArea.width * (1 - to)}px`;
mask.style.top = `${canvas.offsetTop + chart.chartArea.top}px`; mask.style.top = `${canvas.offsetTop + chart.chartArea.top}px`;