Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class BandAxis extends BaseAxis {
textDimensionCalculator: TextDimensionCalculator
) {
super(axisConfig, title, textDimensionCalculator, axisThemeConfig);
this.isBandAxis = true;
this.categories = categories;
this.scale = scaleBand().domain(this.categories).range(this.getRange());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export abstract class BaseAxis implements Axis {
protected outerPadding = 0;
protected titleTextHeight = 0;
protected labelTextHeight = 0;
public isBandAxis = false;

constructor(
protected axisConfig: XYChartAxisConfig,
Expand All @@ -46,7 +47,16 @@ export abstract class BaseAxis implements Axis {
}

getRange(): [number, number] {
return [this.range[0] + this.outerPadding, this.range[1] - this.outerPadding];
if (this.isBandAxis) {
return [this.range[0] + this.outerPadding, this.range[1] - this.outerPadding];
}
// This is a value axis
if (this.axisPosition === 'left' || this.axisPosition === 'right') {
// For vertical value axis, no padding at the bottom
return [this.range[0] + this.outerPadding, this.range[1]];
}
// For horizontal value axis, padding only at the end
return [this.range[0], this.range[1] - this.outerPadding];
}

setAxisPosition(axisPosition: AxisPosition): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface Axis extends ChartComponent {
getTickDistance(): number;
recalculateOuterPaddingToDrawBar(): void;
setRange(range: [number, number]): void;
isBandAxis: boolean;
}

export function getAxis(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,27 @@ export class BarPlot {

const barPaddingPercent = 0.05;

const barWidth =
Math.min(this.xAxis.getAxisOuterPadding() * 2, this.xAxis.getTickDistance()) *
(1 - barPaddingPercent);
const barWidthHalf = barWidth / 2;
let barWidth: number;
let barWidthHalf: number;

// Axis at the bottom of the bar
let bandAxis: Axis;
if (this.yAxis.isBandAxis) {
bandAxis = this.yAxis;
} else {
bandAxis = this.xAxis;
}

if (bandAxis.isBandAxis) {
barWidth =
Math.min(bandAxis.getAxisOuterPadding() * 2, bandAxis.getTickDistance()) *
(1 - barPaddingPercent);
barWidthHalf = barWidth / 2;
} else {
// For value axis, keep bars aligned and adjust width for extra half bar
barWidth = Math.min(bandAxis.getAxisOuterPadding() * 2, bandAxis.getTickDistance()) * 0.5;
barWidthHalf = 0;
}
if (this.orientation === 'horizontal') {
return [
{
Expand Down
Loading