From: Eric Theise Date: Sat, 30 Oct 2021 13:23:14 +0000 (-0700) Subject: Define with let to avoid "assignment to constant" errors (#9803) X-Git-Tag: v3.6.1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67c5a851445b3d25a9ceec344404b4ab65ed8ff1;p=thirdparty%2FChart.js.git Define with let to avoid "assignment to constant" errors (#9803) * Define with let to avoid "assignment to constant" errors Thanks for this example. Defining `label` with `const` rather than `let` results in `Uncaught TypeError: Assignment to constant variable.` * Another case where const needs to be replaced with let. * Requested cases where const needs to be replaced with let +1 (style). --- diff --git a/docs/configuration/tooltip.md b/docs/configuration/tooltip.md index 527b15d99..53fd72716 100644 --- a/docs/configuration/tooltip.md +++ b/docs/configuration/tooltip.md @@ -5,7 +5,7 @@ Namespace: `options.plugins.tooltip`, the global options for the chart tooltips is defined in `Chart.defaults.plugins.tooltip`. :::warning -The bubble, doughnut, pie, polar area, and scatter charts override the tooltip defaults. To change the overrides for those chart types, the options are defined in `Chart.overrides[type].plugins.tooltip`. +The bubble, doughnut, pie, polar area, and scatter charts override the tooltip defaults. To change the overrides for those chart types, the options are defined in `Chart.overrides[type].plugins.tooltip`. ::: | Name | Type | Default | Description @@ -157,7 +157,7 @@ const chart = new Chart(ctx, { tooltip: { callbacks: { label: function(context) { - const label = context.dataset.label || ''; + let label = context.dataset.label || ''; if (label) { label += ': '; @@ -282,7 +282,7 @@ const myPieChart = new Chart(ctx, { external: function(context) { // Tooltip Element - const tooltipEl = document.getElementById('chartjs-tooltip'); + let tooltipEl = document.getElementById('chartjs-tooltip'); // Create element on first render if (!tooltipEl) { @@ -316,7 +316,7 @@ const myPieChart = new Chart(ctx, { const titleLines = tooltipModel.title || []; const bodyLines = tooltipModel.body.map(getBody); - const innerHtml = ''; + let innerHtml = ''; titleLines.forEach(function(title) { innerHtml += '' + title + ''; @@ -325,7 +325,7 @@ const myPieChart = new Chart(ctx, { bodyLines.forEach(function(body, i) { const colors = tooltipModel.labelColors[i]; - const style = 'background:' + colors.backgroundColor; + let style = 'background:' + colors.backgroundColor; style += '; border-color:' + colors.borderColor; style += '; border-width: 2px'; const span = ''; @@ -333,7 +333,7 @@ const myPieChart = new Chart(ctx, { }); innerHtml += ''; - const tableRoot = tooltipEl.querySelector('table'); + let tableRoot = tooltipEl.querySelector('table'); tableRoot.innerHTML = innerHtml; } diff --git a/docs/developers/updates.md b/docs/developers/updates.md index 697d25bd3..76aac266e 100644 --- a/docs/developers/updates.md +++ b/docs/developers/updates.md @@ -66,8 +66,8 @@ Variables referencing any one from `chart.scales` would be lost after updating s ```javascript function updateScales(chart) { - const xScale = chart.scales.x; - const yScale = chart.scales.y; + let xScale = chart.scales.x; + let yScale = chart.scales.y; chart.options.scales = { newId: { display: true