client/webserver/site/src/js/charts.js
// screen size, context, and label spacing.
screen size, context, and label spacing.
screen size context and label spacing .
function makeLabels (ctx, screenW, min, max, spacingGuess, step, unit) {
  const n = screenW / spacingGuess
  const diff = max - min
  const tickGuess = diff / n
  const tick = tickGuess + step - (tickGuess % step)
  let x = min + tick - (min % tick)
  const absMax = Math.max(Math.abs(max), Math.abs(min))
  const sigFigs = Math.round(Math.log10(absMax / tick)) + 2
  const pts = []
  let widest = 0
  while (x < max) {
    x = Number(x.toPrecision(sigFigs))
    const lbl = formatLabelValue(x)
    widest = Math.max(widest, ctx.measureText(lbl).width)
    pts.push({
      val: x,
      txt: lbl
    })
    x += tick
  }
  const unitW = ctx.measureText(unit).width
  if (unitW > widest) widest = unitW
  return {
    widest: widest,
    lbls: pts
  }
}
function makeLabels ( ctx , screenW , min , max , spacingGuess , step , unit ) { const n = screenW / spacingGuess const diff = max - min const tickGuess = diff / n const tick = tickGuess + step - ( tickGuess % step ) let x = min + tick - ( min % tick ) const absMax = Math . max ( Math . abs ( max ) , Math . abs ( min ) ) const sigFigs = Math . round ( Math . log10 ( absMax / tick ) ) + 2 const pts = [ ] let widest = 0 while ( x < max ) { x = Number ( x . toPrecision ( sigFigs ) ) const lbl = formatLabelValue ( x ) widest = Math . max ( widest , ctx . measureText ( lbl ) . width ) pts . push ( { val : x , txt : lbl } ) x += tick } const unitW = ctx . measureText ( unit ) . width if ( unitW > widest ) widest = unitW return { widest : widest , lbls : pts } }
screen size, context, and label spacing.
screen size context and label spacing .
// make the tick spacing a multiple of the step // The Math.round part is the minimum precision required to see the change in the numbers. // The 2 accounts for the precision of the tick.