meo-canvas
    Preparing search index...

    Function barLayout

    • Where every bar of a cartesian chart sits, as fractions of the plot area.

      This is the reference. v1 computes these in pixels against a plot rectangle it measured; the same arithmetic in fractions is independent of how big the plot turns out to be, which is what lets layout resolve it:

      groupWidth = 1 / labels                      v1: chartWidth / labels.length
      spacing    = groupWidth * 0.2                v1: groupWidth * 0.2
      barWidth   = (groupWidth - spacing) / series v1: (groupWidth - barSpacing) / datasets.length
      x          = index * groupWidth + spacing/2 + series * barWidth
      height     = value / maxValue                v1: (value / maxValue) * finalChartHeight
      

      y is not returned because a bar is anchored to the bottom of the plot: v1's barY = chartY + finalChartHeight - barHeight is what "sits on the axis" means, and a bottom-aligned box says it without arithmetic.

      Parameters

      • labels: number
      • series: number
      • values: readonly (readonly number[])[]
      • maxValue: number

      Returns { height: number; width: number; x: number }[][]

      • height: number

        Bar height, as a fraction of the plot's height.

        Zero when every value is zero, rather than the NaN the division would give — see the note in the body for why that divergence from v1 is deliberate.

      • width: number

        Bar width, as a fraction of the plot's width.

      • x: number

        Left edge, as a fraction of the plot's width.