Numeric tick formatter gives repeated labels in scientific notation and with bounds: 'data'
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript
- Área
- data-visualization
Línea de trabajo
Empieza con Ticks.formatters.numeric en src/core/core.ticks.js, que, según el issue, calcula las cifras decimales a partir del espaciado de las marcas. Compara ese cálculo para la notación científica y bounds: 'data' con los cuatro casos reproducidos en el issue y luego confirma que las etiquetas son distintas y coinciden con la precisión esperada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Expected behavior
Distinct ticks get distinct labels:
[1e15, 5e15]:1.0E15, 1.5E15, 2.0E15, ..., 5.0E15[0, 2e16]:0, 2E15, ..., 1.0E16, 1.2E16, ..., 2.0E16[0, 5e-5]:0, 1E-5, 2E-5, ..., 6E-5[-0.0936, 0.0917]withbounds: 'data':-0.0936, -0.0736, ..., 0.0864, 0.0917
Current behavior
["1E15","2E15","2E15","3E15","3E15","4E15","4E15","5E15","5E15"]
["0","2E15","4E15","6E15","8E15","1E16","1E16","1E16","2E16","2E16","2E16"]
["0","1.00000E-5","2.00000E-5","3.00000E-5","4.00000E-5","5.00000E-5","6.00000E-5"]
["-0.09","-0.07","-0.05","-0.03","-0.01","0.01","0.03","0.05","0.07","0.09","0.09"]
In scientific notation, 1.5e15 is shown as 2E15 and 1e-5 as 1.00000E-5; with bounds: 'data' the last two ticks (0.0864 and 0.0917) are both 0.09.
Reproducible sample
Not applicable: no CodePen (needs an account to save); the Node script below is self-contained.
Optional extra steps/info to reproduce
npm i [email protected] && node repro.js
const {Chart, registerables, BasicPlatform} = require('chart.js');
Chart.register(...registerables);
const stubCanvas = () => {
const canvas = {width: 400, height: 300};
const ctx = new Proxy({canvas}, {
get: (t, k) => (k in t ? t[k] : k === 'measureText' ? (s) => ({width: String(s).length * 6}) : () => {})
});
canvas.getContext = () => ctx;
return canvas;
};
const labels = (data, y = {}) => {
const chart = new Chart(stubCanvas(), {
platform: BasicPlatform,
type: 'line',
data: {labels: data.map((_, i) => i), datasets: [{data}]},
options: {animation: false, responsive: false, locale: 'en-US', scales: {y}}
});
return chart.scales.y.ticks.map(t => t.label);
};
console.log(JSON.stringify(labels([1e15, 5e15])));
console.log(JSON.stringify(labels([0, 2e16])));
console.log(JSON.stringify(labels([0, 5e-5])));
console.log(JSON.stringify(labels([-0.0936, 0.0917], {bounds: 'data', ticks: {autoSkip: false}})));
Possible solution
Ticks.formatters.numeric in src/core/core.ticks.js uses -Math.floor(log10(delta)) fraction digits. With notation: 'scientific' those digits apply to the significand, so they should be floor(log10(maxTick)) - floor(log10(delta)). With bounds: 'data' the ticks are min + k * spacing, not multiples of the spacing, so the digits also need to cover min.
Context
Found while plotting very large / very small values on a linear axis with default options.
chart.js version
v4.6.1 (same code on master 71d44219e)
Browser name and version
Node.js 26.13.0 with BasicPlatform (not browser specific)
Link to your project
No response
Credit: https://ucsbplse.github.io/
- Lenguaje dominante
- JavaScript
- Estrellas
- 67.8k
- Forks
- 12k
- Merge medio
- 6 h 15 min
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de chartjs/Chart.js
-
linear axis: "reverse" breaks tick align 'inner'Posiblemente ocupada @Fardin7798 la tomó hace 1 día. Abiertotype: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
fill: 'stack': a dataset's whole fill disappears when its x differs from the line below by ≤ 1e-6 px (happens in animations)Posiblemente ocupada @ump45nose la tomó hace 37 días. Abiertotype: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Legend pointStyle: 'line' does not apply dataset borderDash patternPosiblemente ocupada @HuzaifaChaudary la tomó hace 69 días. Abiertotype: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
`skipNull` is a configuration option, not a dataset fieldPosiblemente ocupada @puneetdixit200 la tomó hace 156 días. Abiertotype: documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
chartjs/Chart.js#12235 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de chartjs/Chart.js
Issues similares
-
stringify escapes leading digits in pseudo-class arguments (:nth-child(1) becomes :nth-child(\31 ))Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
digitalbazaar/forge#1170 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
getgrav/grav-plugin-form#664 ·
-
bug web-ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
jenkinsci/jenkins#27705 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
maproulette/maproulette-frontend#2978 ·
Los mantenedores suelen responder en 1 día