Skip to content

Commit

Permalink
fix: prefer user-defined tickMinStep to defaultTickMinStep (#9461)
Browse files Browse the repository at this point in the history
## PR Description

Fixes #9034 by only using
`defaultTickMinStep` if the user hasn't explicitly provided a
`tickMinStep`.

### example 1
```
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "description": "A simple bar chart with embedded data.",
  "data": {
    "values": [
      {"a": "A", "b": 2}, {"a": "B", "b": 1}, {"a": "C", "b": 1},
      {"a": "D", "b": 1}, {"a": "E", "b": 2}, {"a": "F", "b": 2},
      {"a": "G", "b": 3}, {"a": "H", "b": 3}, {"a": "I", "b": 1}
    ]
  },
  "mark": "bar",
  "encoding": {
    "x": {"field": "a", "type": "nominal", "axis": {"labelAngle": 0}},
    "y": {"field": "b", "type": "quantitative", "axis": {"tickMinStep": 1}}
  }
}
```

| **Before**  | **After** |
| ------------- | ------------- |
|
![visualization](https://github.com/user-attachments/assets/ecfa38da-3912-4a27-9583-a108812adca1)
| ![visualization
(1)](https://github.com/user-attachments/assets/06a05e7e-7cc3-424c-83bb-376d3c8f2683)
|

### example 2
```
{
  "config": {"view": {"continuousWidth": 300, "continuousHeight": 300}},
  "data": {"name": "data-4a0cb25b0716723cd309daa74d88bb73"},
  "mark": {"type": "point"},
  "encoding": {
    "x": {"axis": {"tickMinStep": 1}, "field": "x", "type": "quantitative"},
    "y": {"field": "y", "type": "quantitative"}
  },
  "$schema": "https://vega.github.io/schema/vega-lite/v5.8.0.json",
  "datasets": {
    "data-4a0cb25b0716723cd309daa74d88bb73": [
      {"x": 0, "y": 0},
      {"x": 1, "y": 1},
      {"x": 2, "y": 2},
      {"x": 3, "y": 3},
      {"x": 4, "y": 4}
    ]
  }
}
```

| **Before**  | **After** |
| ------------- | ------------- |
| ![visualization
(2)](https://github.com/user-attachments/assets/d003f580-f883-4eb2-b495-6b2898202ab9)
| ![visualization
(3)](https://github.com/user-attachments/assets/9373991d-4b13-4215-8946-682f207e1d53)
|

### example 3
```
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "data/movies.json"},
  "mark": "bar",
  "encoding": {
    "x": {
      "bin": true,
      "field": "IMDB Rating",
      "axis": {
        "grid": true,
        "tickMinStep": 2
      }
    },
    "y": {"aggregate": "count"}
  }
}

```

| **Before**  | **After** |
| ------------- | ------------- |
| ![visualization
(5)](https://github.com/user-attachments/assets/58a6e296-0ca9-4598-a70d-40c4a6b28751)
| ![visualization
(6)](https://github.com/user-attachments/assets/addd2209-eed0-4f35-8b18-c9f7cb71cd61)
|
  • Loading branch information
datananda authored Feb 11, 2025
1 parent 9356e8e commit 31a76e7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/compile/axis/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const axisRules: {
return axis.tickCount ?? defaultTickCount({fieldOrDatumDef, scaleType, size, values: axis.values});
},

tickMinStep: defaultTickMinStep,
tickMinStep: ({axis, format, fieldOrDatumDef}) => axis.tickMinStep ?? defaultTickMinStep({format, fieldOrDatumDef}),

title: ({axis, model, channel}) => {
if (axis.title !== undefined) {
Expand Down

0 comments on commit 31a76e7

Please sign in to comment.