ag-charts-community
Version:
Advanced Charting / Charts supporting Javascript / Typescript / React / Angular / Vue
67 lines • 2.79 kB
JavaScript
import { Chart } from "./chart";
import { PolarSeries } from "./series/polar/polarSeries";
import { Padding } from "../util/padding";
import { BBox } from "../scene/bbox";
export class PolarChart extends Chart {
constructor(document = window.document) {
super(document);
this.padding = new Padding(40);
this.scene.root.append(this.legend.group);
this.padding.addEventListener('layoutChange', this.scheduleLayout, this);
}
get seriesRoot() {
return this.scene.root;
}
performLayout() {
const shrinkRect = new BBox(0, 0, this.width, this.height);
this.positionCaptions();
this.positionLegend();
const captionAutoPadding = this.captionAutoPadding;
shrinkRect.y += captionAutoPadding;
shrinkRect.height -= captionAutoPadding;
if (this.legend.enabled && this.legend.data.length) {
const legendAutoPadding = this.legendAutoPadding;
shrinkRect.x += legendAutoPadding.left;
shrinkRect.y += legendAutoPadding.top;
shrinkRect.width -= legendAutoPadding.left + legendAutoPadding.right;
shrinkRect.height -= legendAutoPadding.top + legendAutoPadding.bottom;
const legendPadding = this.legend.spacing;
switch (this.legend.position) {
case 'right':
shrinkRect.width -= legendPadding;
break;
case 'bottom':
shrinkRect.height -= legendPadding;
break;
case 'left':
shrinkRect.x += legendPadding;
shrinkRect.width -= legendPadding;
break;
case 'top':
shrinkRect.y += legendPadding;
shrinkRect.height -= legendPadding;
break;
}
}
const padding = this.padding;
shrinkRect.x += padding.left;
shrinkRect.y += padding.top;
shrinkRect.width -= padding.left + padding.right;
shrinkRect.height -= padding.top + padding.bottom;
this.seriesRect = shrinkRect;
const centerX = shrinkRect.x + shrinkRect.width / 2;
const centerY = shrinkRect.y + shrinkRect.height / 2;
const radius = Math.max(0, Math.min(shrinkRect.width, shrinkRect.height) / 2); // radius shouldn't be negative
this.series.forEach(series => {
if (series instanceof PolarSeries) {
series.centerX = centerX;
series.centerY = centerY;
series.radius = radius;
series.update();
}
});
}
}
PolarChart.className = 'PolarChart';
PolarChart.type = 'polar';
//# sourceMappingURL=polarChart.js.map