Skip to content

Commit

Permalink
fix(core): center x axis label
Browse files Browse the repository at this point in the history
Somewhere along the way this position logic became more convoluted than it needs to be. The result was an x axis text label that is sometimes positioned slightly off-center relative to the mark content. This is visible when the number of axis ticks or nominal bands on the axis is both small and odd – it's easy to see that there's a disagreement about what constitutes the "center" when there are only three bars, for example.

The underlying cause for this is an accidental philosophical disagreement about what dimensions should mean. The original Vega Lite renderer uses them to define the dimensions of the marks area, and adds extra things like axes or titles on top of that. In contrast, bisonica has always interpreted dimensions instructions as describing the outer bounds of the node, the total size of the chart.

One could argue that this is an incompatibility between the two renderers, but it may also be fair to say that bisonica chose the interpretation that is more useful in the real world.
  • Loading branch information
vijithassar committed May 29, 2024
1 parent 0b6ba7b commit f0462c5
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions source/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { feature } from './feature.js'
import { layerMatch } from './views.js'
import { parseScales } from './scales.js'
import { renderStyles } from './styles.js'
import { margin, tickMargin } from './position.js'
import { tickMargin } from './position.js'
import { timeMethod, timePeriod } from './time.js'
import { axisDescription } from './descriptions.js'

Expand Down Expand Up @@ -248,11 +248,9 @@ const axisTitleX = (s, dimensions) => {
}
return selection => {
const xTitle = selection.append('text').attr('class', 'title')
const bar = feature(s).isBar() ? barWidth(s, dimensions) : 0

xTitle
.attr('x', () => {
return (dimensions.x - margin(s, dimensions).left + bar) * 0.5
return dimensions.x * 0.5
})
.attr('y', () => {
const axisHeight = selection.node().getBBox().height * 2
Expand Down

0 comments on commit f0462c5

Please sign in to comment.