add native range charts
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript
- Área
- data-visualization
Línea de trabajo
No se identifican archivos fuente, pruebas ni puntos de entrada. Empieza con el ejemplo personalizado de range-chart del issue y compara su comportamiento con los enfoques indicados de scatter, overlaid-bar y stacked-bar; se considera terminado cuando Plotly.js tenga compatibilidad nativa con range-chart que gestione correctamente las bases distintas de cero y las bases negativas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
MinutePhysics called us out (by name!) for not having native support for range charts: https://www.youtube.com/watch?v=5zBg9pH_6bE
However, to be clear, it is possible to build this chart type in Plotly using the base attribute for bar charts and doing a bit of data preparation.
Here's a live demo of a custom range chart and our built-ins: https://codepen.io/ndrezn/pen/XJrWboB
Code snippet
/**
* Creates a range bar chart using Plotly.js.
*
* @param {Object} data - The dataset, with keys as categories (e.g., cities) and values as arrays of measurements.
* @param {Array} labels - The labels for each measurement (e.g., temperature metrics).
* @param {string} containerId - The ID of the HTML container to render the chart.
* @param {string} title - The title of the chart.
*/
function rangeChart(data, labels, containerId, title) {
const categories = Object.keys(data); // Extract categories (e.g., cities)
// Generate bar traces for each label
const barTraces = labels.map((label, index) => {
const bases = categories.map((category) =>
index === 0 ? data[category][index] : data[category][index - 1]
); // base, i.e. the previous value
const heights = categories.map(
(category) => data[category][index] - bases[categories.indexOf(category)]
); // Height relative to the base, i.e. the current value
return {
x: categories,
y: heights, // Bar heights
base: bases, // Starting points for each bar
name: label,
type: "bar"
};
});
// Layout for the chart
const layout = {
title: title,
barmode: "overlay", // Overlapping bars to show ranges
xaxis: { title: "Category" },
yaxis: { title: "Value" }
};
// Render the chart
Plotly.newPlot(containerId, barTraces, layout);
}
const ranges = {
Ontario: [-9, 3, 8, 13, 27],
England: [3, 8, 12, 16, 24],
Kentucky: [-3, 8, 14, 20, 30]
};
const labels = [
"Winter mean low",
"Annual mean low",
"Annual mean",
"Annual mean high",
"Summer mean high"
];
rangeChart(
ranges,
labels,
"rangePlot",
"Temperature Ranges in Three Londons (range)"
);
That being said, having this chart-type built in would be great. The mental gymnastics are a bit tricky to get a true range chart working correctly.
Here are the built-in ways to achieve a similar chart:
Code snippet
// Data for the three Londons
const ranges = {
Ontario: [-9, 3, 8, 13, 27],
England: [3, 8, 12, 16, 24],
Kentucky: [-3, 8, 14, 20, 30]
};
const labels = [
"Winter mean low",
"Annual mean low",
"Annual mean",
"Annual mean high",
"Summer mean high"
];
const cities = Object.keys(ranges);
// Scatter plot traces
const scatterTraces = labels.map((label, index) => ({
x: cities,
y: cities.map((city) => ranges[city][index]),
mode: "markers",
name: label,
type: "scatter"
}));
const scatterLayout = {
title: "Temperature Ranges in Three Londons (scatter)",
xaxis: { title: "City" },
yaxis: { title: "Temperature" }
};
Plotly.newPlot("scatterPlot", scatterTraces, scatterLayout);
// Bar plot traces
const barTraces = labels.map((label, index) => ({
x: cities,
y: cities.map((city) => ranges[city][index]),
name: label,
type: "bar"
}));
const barLayout = {
title: "Temperature Ranges in Three Londons (overlay)",
barmode: "overlay",
xaxis: { title: "City" },
yaxis: { title: "Temperature" }
};
Plotly.newPlot("barPlot", barTraces, barLayout);
// Bar plot traces
const stackedBarTraces = labels.map((label, index) => ({
x: cities,
y: cities.map((city) => ranges[city][index]),
name: label,
type: "bar"
}));
const stackedBarLayout = {
title: "Temperature Ranges in Three Londons (stacked)",
barmode: "stack",
xaxis: { title: "City" },
yaxis: { title: "Temperature" }
};
Plotly.newPlot("stackedBarPlot", stackedBarTraces, stackedBarLayout);
However, these aren't quite right.
- The scatter plot is most legible, but doesn't depict a range
- The overlaid bar shows the right data, but because the
baseof all positive points is0, they actually overlap on top of each other. We want the base to he previous, and for England, we want the base to be3, not0. - The stacked bar chart looks right at first glance, but it's actually summing all the temperatures (and of course, the
basefor England is at0, not3. And the negative values stack a bit weirdly.
- Lenguaje dominante
- JavaScript
- Estrellas
- 18.3k
- Forks
- 2k
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 28
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 plotly/plotly.js
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
chore P1 plotly-internal size: 1 task
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
-
chore P3 plotly-internal size: 1 task
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
bug infrastructure P2
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
Todos los issues de plotly/plotly.js
Issues similares
-
curation good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
amponce/archive-movie-browser#186 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
clerk/javascript#9852 ·
-
bug p1 tools
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
HarperFast/skills#96 ·
-
factory-active factory-automatic task-bug-reproduction-cannot-reproduce task-identify-harness-labels-done task-identify-issue-type-done
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100