Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ exports[`compileChart snapshot (Step 7 oracle) > clipped-domain bar chart (data
"fill": "#ffffff",
"fontFamily": "system-ui, -apple-system, sans-serif",
"fontSize": 11,
"fontVariant": "tabular-nums",
"fontWeight": 600,
"lineHeight": 1.2,
"textAnchor": "end",
Expand Down Expand Up @@ -264,6 +265,7 @@ exports[`compileChart snapshot (Step 7 oracle) > clipped-domain bar chart (data
"fill": "#ffffff",
"fontFamily": "system-ui, -apple-system, sans-serif",
"fontSize": 11,
"fontVariant": "tabular-nums",
"fontWeight": 600,
"lineHeight": 1.2,
"textAnchor": "end",
Expand Down Expand Up @@ -297,6 +299,7 @@ exports[`compileChart snapshot (Step 7 oracle) > clipped-domain bar chart (data
"fill": "#ffffff",
"fontFamily": "system-ui, -apple-system, sans-serif",
"fontSize": 11,
"fontVariant": "tabular-nums",
"fontWeight": 600,
"lineHeight": 1.2,
"textAnchor": "end",
Expand Down Expand Up @@ -868,6 +871,7 @@ exports[`compileChart snapshot (Step 7 oracle) > legend-heavy multi-series line
"fill": "#71717a",
"fontFamily": ""Inter Variable", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif",
"fontSize": 12,
"fontVariant": "tabular-nums",
"fontWeight": 400,
"lineHeight": 1.25,
},
Expand Down Expand Up @@ -1800,6 +1804,7 @@ exports[`compileChart snapshot (Step 7 oracle) > watermarked column chart with g
"fill": "#0000ff",
"fontFamily": "system-ui, -apple-system, sans-serif",
"fontSize": 10,
"fontVariant": "tabular-nums",
"fontWeight": 600,
"lineHeight": 1.2,
"textAnchor": "middle",
Expand Down Expand Up @@ -1844,6 +1849,7 @@ exports[`compileChart snapshot (Step 7 oracle) > watermarked column chart with g
"fill": "#0000ff",
"fontFamily": "system-ui, -apple-system, sans-serif",
"fontSize": 10,
"fontVariant": "tabular-nums",
"fontWeight": 600,
"lineHeight": 1.2,
"textAnchor": "middle",
Expand Down Expand Up @@ -1888,6 +1894,7 @@ exports[`compileChart snapshot (Step 7 oracle) > watermarked column chart with g
"fill": "#0000ff",
"fontFamily": "system-ui, -apple-system, sans-serif",
"fontSize": 10,
"fontVariant": "tabular-nums",
"fontWeight": 600,
"lineHeight": 1.2,
"textAnchor": "middle",
Expand Down Expand Up @@ -1932,6 +1939,7 @@ exports[`compileChart snapshot (Step 7 oracle) > watermarked column chart with g
"fill": "#0000ff",
"fontFamily": "system-ui, -apple-system, sans-serif",
"fontSize": 10,
"fontVariant": "tabular-nums",
"fontWeight": 600,
"lineHeight": 1.2,
"textAnchor": "middle",
Expand Down
5 changes: 3 additions & 2 deletions packages/engine/src/__tests__/axes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,10 @@ describe('axis config properties', () => {
const scales = computeScales(lineSpec, chartArea, lineSpec.data);
const axes = computeAxes(scales, chartArea, fullStrategy, theme);

// All new properties should be undefined when not set
// All new properties should be undefined when not set (except domainLine,
// which defaults to false for non-grounded marks like line)
expect(axes.x!.orient).toBeUndefined();
expect(axes.x!.domainLine).toBeUndefined();
expect(axes.x!.domainLine).toBe(false);
expect(axes.x!.tickMarks).toBeUndefined();
expect(axes.x!.offset).toBeUndefined();
expect(axes.x!.titlePadding).toBeUndefined();
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/barlist/compile-barlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export function compileBarList(spec: unknown, options: CompileOptions): BarListL
fontWeight: VALUE_FONT_WEIGHT,
fill: valueColor,
lineHeight: 1.4,
fontVariant: 'tabular-nums',
};

const rowMark: BarListRowMark = {
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/charts/bar/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export function computeBarLabels(
lineHeight: 1.2,
textAnchor,
dominantBaseline: 'central',
fontVariant: 'tabular-nums',
},
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/charts/column/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export function computeColumnLabels(
fill: labelColor ?? getRepresentativeColor(mark.fill),
lineHeight: 1.2,
textAnchor: 'middle',
fontVariant: 'tabular-nums',
},
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/charts/dot/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function computeDotLabels(
lineHeight: 1.2,
textAnchor: 'start',
dominantBaseline: 'central',
fontVariant: 'tabular-nums',
},
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/engine/src/charts/pie/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function computePieLabels(
lineHeight: 1.2,
textAnchor: isRight ? 'start' : 'end',
dominantBaseline: 'central',
fontVariant: 'tabular-nums',
},
});

Expand Down
2 changes: 2 additions & 0 deletions packages/engine/src/endpoint-labels/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function emptyLayout(theme: ResolvedTheme): EndpointLabelsLayout {
fontWeight: ENDPOINT_VALUE_FONT_WEIGHT,
fill: theme.colors.annotationText ?? theme.colors.text,
lineHeight: ENDPOINT_LINE_HEIGHT,
fontVariant: 'tabular-nums',
};
return {
entries: [],
Expand Down Expand Up @@ -271,6 +272,7 @@ export function computeEndpointLabels(
fontWeight: ENDPOINT_VALUE_FONT_WEIGHT,
fill: theme.colors.annotationText ?? theme.colors.text,
lineHeight: ENDPOINT_LINE_HEIGHT,
fontVariant: 'tabular-nums',
};

// First pass: build entries with wrapped labels and dataY (no positions yet).
Expand Down
10 changes: 8 additions & 2 deletions packages/engine/src/layout/axes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ const WIDTH_REDUCED_THRESHOLD = 300;
/** Ordered densities from most to fewest ticks. */
const DENSITY_ORDER: AxisLabelDensity[] = ['full', 'reduced', 'minimal'];

/** Marks grounded on the x baseline that warrant a domain line. */
const GROUNDED_MARKS = new Set(['bar', 'tick', 'lollipop']);

/**
* Compute effective axis tick density by considering available space.
*
Expand Down Expand Up @@ -460,17 +463,20 @@ export function computeAxes(
// because tick labels need horizontal room around their x position).
const xTickPosition = axisConfig?.tickPosition ?? 'gutter';

const xDomainLine =
axisConfig?.domain ?? (GROUNDED_MARKS.has(dataContext?.markType ?? '') ? undefined : false);

result.x = {
ticks,
gridlines: axisConfig?.grid ? gridlines : [],
gridlines: (axisConfig?.grid ?? dataContext?.markType === 'point') ? gridlines : [],
label: axisTitle,
labelStyle: xLabelColor ? { ...axisLabelStyle, fill: xLabelColor } : axisLabelStyle,
tickLabelStyle: xLabelColor ? { ...tickLabelStyle, fill: xLabelColor } : tickLabelStyle,
tickAngle,
start: { x: chartArea.x, y: chartArea.y + chartArea.height },
end: { x: chartArea.x + chartArea.width, y: chartArea.y + chartArea.height },
orient: axisConfig?.orient,
domainLine: axisConfig?.domain,
domainLine: xDomainLine,
tickMarks: axisConfig?.ticks,
offset: axisConfig?.offset,
titlePadding: axisConfig?.titlePadding,
Expand Down
14 changes: 10 additions & 4 deletions packages/vanilla/src/__tests__/svg-renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,16 +525,22 @@ describe('axis rendering', () => {
expect(labels.length).toBeGreaterThan(0);
});

it('x-axis has a baseline line element', () => {
const { svg } = renderSpec(lineSpec);
it('x-axis has a baseline line element for grounded marks', () => {
const { svg } = renderSpec(barSpec);
const xAxis = svg.querySelector('.oc-axis-x');
const line = xAxis!.querySelector('line');
// The renderer draws an axis line for x-axis
expect(line).not.toBeNull();
});

it('x-axis hides baseline for non-grounded marks', () => {
const { svg } = renderSpec(lineSpec);
const xAxis = svg.querySelector('.oc-axis-x');
const line = xAxis!.querySelector('line');
expect(line).toBeNull();
});

it('x-tick labels hang below the axis line by the label padding (no hugging)', () => {
const { svg, layout } = renderSpec(lineSpec);
const { svg, layout } = renderSpec(barSpec);
const xAxis = svg.querySelector('.oc-axis-x')!;
const axisLineY = Number(xAxis.querySelector('line')!.getAttribute('y2'));
const labels = Array.from(xAxis.querySelectorAll('text.oc-axis-tick'));
Expand Down
Loading