Skip to content

Commit e100bbd

Browse files
committed
fix linear alignement
1 parent 24a89b2 commit e100bbd

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

  • packages/x-charts-pro/src/FunnelChart/curves

packages/x-charts-pro/src/FunnelChart/curves/linear.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ export class Linear implements CurveGenerator {
121121
return;
122122
}
123123

124+
// Add gaps where they are needed.
125+
this.points = this.points.map((point, index) => {
126+
const slopeStart = this.points.at(index <= 1 ? 0 : 3)!;
127+
const slopeEnd = this.points.at(index <= 1 ? 1 : 2)!;
128+
129+
if (this.isHorizontal) {
130+
const yGetter = lerpY(slopeStart.x - this.gap, slopeStart.y, slopeEnd.x, slopeEnd.y);
131+
132+
return {
133+
x: point.x,
134+
y: yGetter(point.x),
135+
};
136+
}
137+
138+
const xGetter = lerpX(slopeStart.x, slopeStart.y - this.gap, slopeEnd.x, slopeEnd.y);
139+
140+
return {
141+
x: xGetter(point.y),
142+
y: point.y,
143+
};
144+
});
145+
124146
if (this.pointShape === 'sharp') {
125147
// In the last section, to form a triangle we need 3 points instead of 4
126148
// Else the algorithm will break.

0 commit comments

Comments
 (0)