Add mobile optimizations: smaller/bolder fonts, hide eye icon, center chart
- Smaller font sizes on mobile (10px/9px vs 13px/11px on desktop) - Bolder font weight on mobile (600) for better readability - Hide chart eye icon on narrow/stacked layouts (≤850px) - Center chart at 50% when layout is stacked (≤850px) - Dynamic font size/weight updates on resize Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
d76e80dc02
commit
f6ae4aa3de
58
app.js
58
app.js
@ -463,19 +463,16 @@ function renderChart(data) {
|
|||||||
const screenWidth = window.innerWidth;
|
const screenWidth = window.innerWidth;
|
||||||
let centerPosition;
|
let centerPosition;
|
||||||
|
|
||||||
if (screenWidth >= 1000) {
|
if (screenWidth <= 850) {
|
||||||
|
// Stacked layout: center the chart since details box is below
|
||||||
|
centerPosition = 50;
|
||||||
|
} else if (screenWidth >= 1000) {
|
||||||
// For screens 1000px and wider, keep centered at 50%
|
// For screens 1000px and wider, keep centered at 50%
|
||||||
centerPosition = 50;
|
centerPosition = 50;
|
||||||
} else if (screenWidth >= 640) {
|
|
||||||
// Gradual transition between 640-1000px
|
|
||||||
const transitionProgress = (screenWidth - 640) / 360; // 0 to 1
|
|
||||||
centerPosition = 40 + (transitionProgress * 10); // 40 to 50
|
|
||||||
} else if (screenWidth <= 500) {
|
|
||||||
// Mobile: center the chart since details box is below
|
|
||||||
centerPosition = 50;
|
|
||||||
} else {
|
} else {
|
||||||
// For smaller screens (500-640px)
|
// Gradual transition between 850-1000px (side-by-side layout)
|
||||||
centerPosition = 40;
|
const transitionProgress = (screenWidth - 850) / 150; // 0 to 1
|
||||||
|
centerPosition = 40 + (transitionProgress * 10); // 40 to 50
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mobile: scale chart to fill container, hide outside labels
|
// Mobile: scale chart to fill container, hide outside labels
|
||||||
@ -489,6 +486,13 @@ function renderChart(data) {
|
|||||||
const level3Outer = isMobile ? '100%' : '75%';
|
const level3Outer = isMobile ? '100%' : '75%';
|
||||||
const outerRadius = isMobile ? '100%' : '95%';
|
const outerRadius = isMobile ? '100%' : '95%';
|
||||||
|
|
||||||
|
// Smaller font sizes on mobile, bolder for readability
|
||||||
|
const level1FontSize = isMobile ? 10 : 13;
|
||||||
|
const level1LineHeight = isMobile ? 12 : 15;
|
||||||
|
const level1FontWeight = isMobile ? 600 : 500;
|
||||||
|
const level2FontSize = isMobile ? 9 : 11;
|
||||||
|
const level2FontWeight = isMobile ? 600 : 400;
|
||||||
|
|
||||||
option = {
|
option = {
|
||||||
backgroundColor: '#fff',
|
backgroundColor: '#fff',
|
||||||
grid: {
|
grid: {
|
||||||
@ -537,8 +541,9 @@ function renderChart(data) {
|
|||||||
label: {
|
label: {
|
||||||
show: true,
|
show: true,
|
||||||
rotate: 'radial',
|
rotate: 'radial',
|
||||||
fontSize: 13,
|
fontSize: level1FontSize,
|
||||||
lineHeight: 15,
|
lineHeight: level1LineHeight,
|
||||||
|
fontWeight: level1FontWeight,
|
||||||
verticalAlign: 'center',
|
verticalAlign: 'center',
|
||||||
position: 'inside',
|
position: 'inside',
|
||||||
formatter: function(param) {
|
formatter: function(param) {
|
||||||
@ -559,7 +564,8 @@ function renderChart(data) {
|
|||||||
// Show labels for sectors that are at least 5% of the total
|
// Show labels for sectors that are at least 5% of the total
|
||||||
return param.percent >= 0.05;
|
return param.percent >= 0.05;
|
||||||
},
|
},
|
||||||
fontSize: 11,
|
fontSize: level2FontSize,
|
||||||
|
fontWeight: level2FontWeight,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
position: 'inside',
|
position: 'inside',
|
||||||
distance: 5,
|
distance: 5,
|
||||||
@ -1781,6 +1787,13 @@ function adjustChartSize() {
|
|||||||
const level3Outer = isMobile ? '100%' : '75%';
|
const level3Outer = isMobile ? '100%' : '75%';
|
||||||
const outerRadius = isMobile ? '100%' : '95%';
|
const outerRadius = isMobile ? '100%' : '95%';
|
||||||
|
|
||||||
|
// Smaller font sizes on mobile, bolder for readability
|
||||||
|
const level1FontSize = isMobile ? 10 : 13;
|
||||||
|
const level1LineHeight = isMobile ? 12 : 15;
|
||||||
|
const level1FontWeight = isMobile ? 600 : 500;
|
||||||
|
const level2FontSize = isMobile ? 9 : 11;
|
||||||
|
const level2FontWeight = isMobile ? 600 : 400;
|
||||||
|
|
||||||
// Update layer proportions
|
// Update layer proportions
|
||||||
option.series.levels[1].r0 = level1Inner;
|
option.series.levels[1].r0 = level1Inner;
|
||||||
option.series.levels[1].r = level1Outer;
|
option.series.levels[1].r = level1Outer;
|
||||||
@ -1790,6 +1803,13 @@ function adjustChartSize() {
|
|||||||
option.series.levels[3].r = level3Outer;
|
option.series.levels[3].r = level3Outer;
|
||||||
option.series.radius = [0, outerRadius];
|
option.series.radius = [0, outerRadius];
|
||||||
|
|
||||||
|
// Update font sizes and weights
|
||||||
|
option.series.levels[1].label.fontSize = level1FontSize;
|
||||||
|
option.series.levels[1].label.lineHeight = level1LineHeight;
|
||||||
|
option.series.levels[1].label.fontWeight = level1FontWeight;
|
||||||
|
option.series.levels[2].label.fontSize = level2FontSize;
|
||||||
|
option.series.levels[2].label.fontWeight = level2FontWeight;
|
||||||
|
|
||||||
// Update level 3 labels: hide on mobile, show on desktop (with conditions)
|
// Update level 3 labels: hide on mobile, show on desktop (with conditions)
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
option.series.levels[3].label.show = false;
|
option.series.levels[3].label.show = false;
|
||||||
@ -1806,15 +1826,15 @@ function adjustChartSize() {
|
|||||||
|
|
||||||
// Calculate center position
|
// Calculate center position
|
||||||
let centerPosition;
|
let centerPosition;
|
||||||
if (screenWidth >= 1000) {
|
if (screenWidth <= 850) {
|
||||||
|
// Stacked layout: center the chart since details box is below
|
||||||
centerPosition = 50;
|
centerPosition = 50;
|
||||||
} else if (screenWidth >= 640) {
|
} else if (screenWidth >= 1000) {
|
||||||
const transitionProgress = (screenWidth - 640) / 360;
|
|
||||||
centerPosition = 40 + (transitionProgress * 10);
|
|
||||||
} else if (isMobile) {
|
|
||||||
centerPosition = 50;
|
centerPosition = 50;
|
||||||
} else {
|
} else {
|
||||||
centerPosition = 40;
|
// Gradual transition between 850-1000px (side-by-side layout)
|
||||||
|
const transitionProgress = (screenWidth - 850) / 150;
|
||||||
|
centerPosition = 40 + (transitionProgress * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update chart center position
|
// Update chart center position
|
||||||
|
|||||||
@ -363,6 +363,10 @@ body {
|
|||||||
.center-label {
|
.center-label {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chart-eye-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 500px) {
|
@media (max-width: 500px) {
|
||||||
@ -411,6 +415,10 @@ body {
|
|||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.chart-eye-btn {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 400px) {
|
@media (max-width: 400px) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user