Skip to content

Commit 185b752

Browse files
authored
fix(chart) :: make xticks count tick positions
1 parent f2e1b10 commit 185b752

5 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## unreleased
44

55
- Numeric x values on Cartesian charts now explicitly use a continuous numeric axis, preventing fractional tick positions from being displayed as misleading rounded integers.
6+
- `xticks` now represents the requested number of tick positions on numeric x-axes, rather than the number of intervals between them.
67

78
## v0.46.1
89

‎examples/official-site/sqlpage/migrations/01_documentation.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
669669
('xtitle', 'Title of the x axis, displayed below it.', 'TEXT', TRUE, TRUE),
670670
('ytitle', 'Title of the y axis, displayed to its left.', 'TEXT', TRUE, TRUE),
671671
('ztitle', 'Title of the z axis, displayed in tooltips.', 'TEXT', TRUE, TRUE),
672-
('xticks', 'Number of intervals used to generate a numeric x-axis, normally producing one more tick position. On category and time axes, this is a target for label density, so the visible label count may differ.', 'INTEGER', TRUE, TRUE),
672+
('xticks', 'Number of tick positions on a numeric x-axis. On category and time axes, this is a target for label density, so the visible label count may differ.', 'INTEGER', TRUE, TRUE),
673673
('yticks', 'Number of ticks on the y axis.', 'INTEGER', TRUE, TRUE),
674674
('ystep', 'Step between ticks on the y axis.', 'REAL', TRUE, TRUE),
675675
('marker', 'Marker size', 'REAL', TRUE, TRUE),

‎sqlpage/apexcharts.js‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ sqlpage_chart = (() => {
386386
series,
387387
};
388388
if (labels) options.labels = labels;
389-
// Numeric axes count intervals; category and time axes use tickAmount as a
390-
// target for label density.
391-
if (data.xticks) options.xaxis.tickAmount = data.xticks;
389+
// ApexCharts counts numeric intervals rather than tick positions.
390+
if (data.xticks)
391+
options.xaxis.tickAmount =
392+
xaxis_type === "numeric" ? Math.max(1, data.xticks - 1) : data.xticks;
392393
const chart = new ApexCharts(chartContainer, options);
393394
chart.render();
394395
if (window.charts) window.charts.push(chart);

‎tests/end-to-end/fixtures/chart/numeric-axis-xticks.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
SELECT
22
'chart' AS component,
33
'test-chart' AS id,
4-
'Explicit numeric x intervals' AS title,
4+
'Explicit numeric x tick count' AS title,
55
'bar' AS type,
6-
2 AS xticks;
6+
3 AS xticks;
77

88
SELECT 'A' AS series, 1 AS x, 1 AS y
99
UNION ALL SELECT 'A', 4, 4

‎tests/end-to-end/fixtures/chart/test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,12 @@ test("keeps irregular numeric x values proportionately spaced", async ({
175175
);
176176
});
177177

178-
test("keeps an explicit x interval count", async ({ page }) => {
178+
test("renders the requested number of numeric x ticks", async ({ page }) => {
179179
const chart = await renderChart(page, "numeric-axis-xticks");
180180

181181
expect(chart.failures).toEqual([]);
182182
expect(chart.xaxis).toEqual({ type: "numeric", tickAmount: 2 });
183+
expect(chart.axisLabels).toHaveLength(3);
183184
});
184185

185186
test("keeps text x values as categories", async ({ page }) => {

0 commit comments

Comments
 (0)