Skip to content

Absolute spacing between facets #2402

Description

@mwaibel-go

Status Quo

Currently the spacing between facets needs to be set via the implied band scale’s padding option. [1] However, that option only allows adjusting the spacing relative to the band width (or height). [2]

Motivation

For my use case, I’d like to reserve some space between the facets to repeat the x axis between them. Since I know the amount of space the tick labels will need, I’d like to instruct Plot to leave a gap of a certain fixed size.

Problem

With the current API I need to guess the amount of space Plot will use for a single facet and find a fraction that will leave an appropriate amount of space. If Plot decides that a facet should be larger (in the examples below I forced bigger facets), then my space is at risk of being too small or too large.

Examples

The examples are based on [3].

Appropriate spacing

Plot.plot({
  fy: {
    padding: .15
  },
  marks: [    
    Plot.barY(brands, {
      x: "name",
      y: "value",
      fy: (d, i) => i % 3,
    }),
    Plot.axisX({
      facetAnchor: null,
    })
  ],
})
Image

Excessive spacing

Plot.plot({
  fy: {
    padding: .15
  },
  marks: [    
    Plot.barY(brands, {
      x: "name",
      y: "value",
      fy: (d, i) => i % 3,
    }),
    Plot.axisX({
      facetAnchor: null,
    })
  ],
  height: 1000,
})
Image

[1] https://observablehq.com/plot/features/facets#facet-scales
[2] https://observablehq.com/plot/features/scales#discrete-scales
[3] https://observablehq.com/@observablehq/plot-vertical-bars-rotated-labels

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions