@@ -3,7 +3,7 @@ import { calculateNiceTicks, formatDistanceLabel, formatElevationLabel, computeD
33import { getSlopeColor } from './colors'
44
55const DEFAULT_MARGIN = { top : 10 , right : 15 , bottom : 26 , left : 48 }
6- const DETAIL_BAR_HEIGHT = 20
6+ const DETAIL_BAR_HEIGHT = 50
77const FONT = '12px sans-serif'
88const AXIS_COLOR = '#666'
99const GRID_COLOR = '#e8e8e8'
@@ -34,8 +34,11 @@ export default class ChartRenderer {
3434 private getEffectiveMargin ( ) {
3535 const base = this . config . margin
3636 let left = base . left
37- // Widen left margin for 4+ digit elevation labels (e.g. "1200 m")
38- if ( this . data && this . data . elevation . length > 0 ) {
37+ const isBarDetail = this . selectedDetail != null && this . selectedDetail . type !== 'line'
38+ if ( isBarDetail ) {
39+ left = 15
40+ } else if ( this . data && this . data . elevation . length > 0 ) {
41+ // Widen left margin for 4+ digit elevation labels (e.g. "1200 m")
3942 const { eleMax } = this . getElevationRange ( )
4043 if ( Math . abs ( eleMax ) >= 1000 ) left = 56
4144 }
@@ -146,7 +149,6 @@ export default class ChartRenderer {
146149
147150 const x = margin . left + ( hit . distance / totalDist ) * plotWidth
148151 const plotBottom = this . cssHeight - margin . bottom
149- const detailBarH = this . selectedDetail && this . selectedDetail . type !== 'line' ? DETAIL_BAR_HEIGHT : 0
150152
151153 ctx . beginPath ( )
152154 ctx . strokeStyle = '#333'
@@ -155,13 +157,11 @@ export default class ChartRenderer {
155157 ctx . lineTo ( Math . round ( x ) + 0.5 , plotBottom )
156158 ctx . stroke ( )
157159
158- const isLineDetail = this . selectedDetail ?. type === 'line'
159-
160- // Draw elevation dot (only when not showing a line-type detail)
161- if ( ! isLineDetail ) {
160+ // Draw elevation dot only when no detail is active
161+ if ( ! this . selectedDetail ) {
162162 const { eleMin, eleMax } = this . getElevationRange ( )
163- const plotHeight = plotBottom - margin . top - detailBarH
164- const elevY = plotBottom - detailBarH - ( ( hit . elevation - eleMin ) / ( eleMax - eleMin || 1 ) ) * plotHeight
163+ const plotHeight = plotBottom - margin . top
164+ const elevY = plotBottom - ( ( hit . elevation - eleMin ) / ( eleMax - eleMin || 1 ) ) * plotHeight
165165
166166 ctx . beginPath ( )
167167 ctx . arc ( x , elevY , 4 , 0 , Math . PI * 2 )
@@ -259,7 +259,9 @@ export default class ChartRenderer {
259259 const margin = this . getEffectiveMargin ( )
260260 const plotWidth = this . cssWidth - margin . left - margin . right
261261 const plotBottom = this . cssHeight - margin . bottom
262- const detailBarH = this . selectedDetail && this . selectedDetail . type !== 'line' ? DETAIL_BAR_HEIGHT : 0
262+ const isLineDetail = this . selectedDetail ?. type === 'line'
263+ const isBarDetail = this . selectedDetail != null && ! isLineDetail
264+ const detailBarH = isBarDetail ? DETAIL_BAR_HEIGHT : 0
263265 const plotHeight = plotBottom - margin . top - detailBarH
264266
265267 const elev = this . data . elevation
@@ -271,19 +273,19 @@ export default class ChartRenderer {
271273 : ( _d : number ) => margin . left + plotWidth / 2
272274 const yScale = ( e : number ) => plotBottom - detailBarH - ( ( e - eleMin ) / ( eleMax - eleMin ) ) * plotHeight
273275
274- // Draw grid
275- this . drawGrid ( ctx , eleMin , eleMax , totalDist , xScale , yScale , plotWidth , plotHeight , detailBarH )
276-
277- const isLineDetail = this . selectedDetail ?. type === 'line'
276+ // Draw grid (skip for bar details since bars fill the chart area)
277+ if ( ! isBarDetail ) {
278+ this . drawGrid ( ctx , eleMin , eleMax , totalDist , xScale , yScale , plotWidth , plotHeight , detailBarH )
279+ }
278280
279- // Draw elevation area only when no line-type detail is active
280- if ( ! isLineDetail ) {
281+ // Draw elevation area only when no detail is active
282+ if ( ! this . selectedDetail ) {
281283 // Draw main elevation area with slope coloring
282- this . drawElevationArea ( ctx , elev , xScale , yScale , plotBottom - detailBarH )
284+ this . drawElevationArea ( ctx , elev , xScale , yScale , plotBottom )
283285
284286 // Draw alternative elevation on top so it's clearly visible
285287 if ( this . visibleAlternativeIndex >= 0 && this . visibleAlternativeIndex < this . data . alternativeElevations . length ) {
286- this . drawAlternativeElevation ( ctx , this . data . alternativeElevations [ this . visibleAlternativeIndex ] , plotWidth , plotBottom , detailBarH , plotHeight , eleMin , eleMax )
288+ this . drawAlternativeElevation ( ctx , this . data . alternativeElevations [ this . visibleAlternativeIndex ] , plotWidth , plotBottom , 0 , plotHeight , eleMin , eleMax )
287289 }
288290 }
289291
@@ -301,8 +303,8 @@ export default class ChartRenderer {
301303
302304 // Draw axes
303305 this . drawXAxis ( ctx , totalDist , xScale , plotBottom )
304- if ( ! isLineDetail ) {
305- this . drawYAxis ( ctx , eleMin , eleMax , yScale , margin . left , margin . top , plotBottom - detailBarH )
306+ if ( ! this . selectedDetail ) {
307+ this . drawYAxis ( ctx , eleMin , eleMax , yScale , margin . left , margin . top , plotBottom )
306308 }
307309
308310 ctx . restore ( )
0 commit comments