Browse Source

fix triangles sizes

merge-requests/5/head
vargburz 3 years ago
parent
commit
836992a453
  1. 3
      demo.html
  2. 1
      dist/index.d.ts
  3. 2
      dist/index.js
  4. 35
      src/index.ts

3
demo.html

@ -26,7 +26,8 @@
}, },
stacked: true, stacked: true,
matching: true, matching: true,
maxBarWidth: 20, // maxBarWidth: 2,
minBarWidth: 40,
zoomEvents: { zoomEvents: {
scroll: { zoom: { isActive: false }, pan: { isActive: false } }, scroll: { zoom: { isActive: false }, pan: { isActive: false } },
}, },

1
dist/index.d.ts vendored

@ -7,6 +7,7 @@ export declare class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptio
protected renderMetrics(): void; protected renderMetrics(): void;
setBarPodScales(): void; setBarPodScales(): void;
renderSerie(data: any): void; renderSerie(data: any): void;
getTrianglePath1(x: number, y: number, length: number): string;
getTrianglePath(x: number, y: number, length: number): string; getTrianglePath(x: number, y: number, length: number): string;
getBarOpacity(rowValues: RowValues): number; getBarOpacity(rowValues: RowValues): number;
mergeMacthedSeriesAndSort(matchedSeries: any[]): any; mergeMacthedSeriesAndSort(matchedSeries: any[]): any;

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

35
src/index.ts

@ -88,15 +88,40 @@ export class ChartwerkBarPod extends ChartwerkPod<BarTimeSerie, BarOptions> {
container.append('path') container.append('path')
.attr('d', () => { .attr('d', () => {
const x = Math.ceil(_.toNumber(rectSelection.attr('x'))); const x = Math.ceil(_.toNumber(rectSelection.attr('x')));
const y = Math.ceil(_.toNumber(rectSelection.attr('y'))) - this.barWidth; const y = Math.ceil(_.toNumber(rectSelection.attr('y')));
return this.getTrianglePath(x, y, this.barWidth); return this.getTrianglePath1(x, y, this.barWidth);
}) })
.attr('fill', annotation.color) .attr('fill', annotation.color);
.attr('stroke', '#565862')
.attr('stroke-width', '1px');
}); });
} }
getTrianglePath1(x: number, y: number, length: number): string {
// (x, y) - top left corner of bar
const minTriangleSize = 6;
const maxTriagleSize = 10;
const yOffset = 4; // offset between triangle and bar
const centerX = x + length / 2;
const correctedLength = _.clamp(length, minTriangleSize, maxTriagleSize);
const topY = Math.max(y - correctedLength - yOffset, 4);
const topLeftCorner = {
x: centerX - correctedLength / 2,
y: topY,
};
const topRightCorner = {
x: centerX + correctedLength / 2,
y: topY,
};
const bottomMiddleCorner = {
x: centerX,
y: topY + correctedLength,
};
return `M ${topLeftCorner.x} ${topLeftCorner.y}
L ${topRightCorner.x} ${topRightCorner.y}
L ${bottomMiddleCorner.x} ${bottomMiddleCorner.y} z`;
}
getTrianglePath(x: number, y: number, length: number): string { getTrianglePath(x: number, y: number, length: number): string {
// (x, y) - top left corner // (x, y) - top left corner
const Y_OFFSET = 2; const Y_OFFSET = 2;

Loading…
Cancel
Save