mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
feat: Implement fluid aspect ratio for syntax errors chart
This commit is contained in:
parent
de7c1484f2
commit
cc0960620c
1 changed files with 34 additions and 3 deletions
|
@ -1,8 +1,21 @@
|
||||||
<canvas id="syntaxErrorsChart" width="800" height="400" style="margin-bottom: 20px"></canvas>
|
<style>
|
||||||
|
.chart-container {
|
||||||
|
position: relative;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="chart-container">
|
||||||
|
<canvas id="syntaxErrorsChart"></canvas>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
var ctx = document.getElementById('syntaxErrorsChart').getContext('2d');
|
var ctx = document.getElementById('syntaxErrorsChart').getContext('2d');
|
||||||
|
var chartContainer = document.querySelector('.chart-container');
|
||||||
|
|
||||||
var yamlData = {{ site.data.code-in-json | jsonify }};
|
var yamlData = {{ site.data.code-in-json | jsonify }};
|
||||||
|
|
||||||
|
@ -36,11 +49,19 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
datasets: datasets
|
datasets: datasets
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getAspectRatio() {
|
||||||
|
var width = chartContainer.offsetWidth;
|
||||||
|
// Gradually change aspect ratio from 2 (landscape) to 1 (square)
|
||||||
|
return Math.max(1, Math.min(2, width / 300));
|
||||||
|
}
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: data,
|
data: data,
|
||||||
options: {
|
options: {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
|
maintainAspectRatio: true,
|
||||||
|
aspectRatio: getAspectRatio(),
|
||||||
scales: {
|
scales: {
|
||||||
x: {
|
x: {
|
||||||
title: {
|
title: {
|
||||||
|
@ -103,6 +124,16 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
new Chart(ctx, config);
|
var chart = new Chart(ctx, config);
|
||||||
|
|
||||||
|
function resizeChart() {
|
||||||
|
chart.options.aspectRatio = getAspectRatio();
|
||||||
|
chart.resize();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('resize', resizeChart);
|
||||||
|
|
||||||
|
// Initial resize to set correct size
|
||||||
|
resizeChart();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue