@amcharts/amcharts5
Version:
amCharts 5
48 lines • 2.04 kB
JavaScript
import { CurveChart } from "./CurveChart";
import { p50 } from "../../core/util/Percent";
import * as $math from "../../core/util/Math";
import * as $utils from "../../core/util/Utils";
/**
* A spiral chart.
*
* For this chart to work, it needs curve points provided via renderer of
* its X-axis.
*
* Note: it is an experimental chart type and does not support all the
* functionality of the [[XYChart]].
*
* @see {@link https://www.amcharts.com/docs/v5/charts/timeline/} for more info
* @since 5.12.0
* @important
*/
export class SpiralChart extends CurveChart {
_prepareChildren() {
super._prepareChildren();
if (this.isDirty("levelCount") || this.isDirty("yAxisRadius") || this.isDirty("startAngle") || this.isDirty("endAngle") || this.isDirty("innerRadius")) {
this._updateMasks();
}
}
_updateMasks() {
let w = this.plotContainer.innerWidth();
let h = this.plotContainer.innerHeight();
let radius = Math.min(w, h) / 2;
let innerRadius = $utils.relativeToValue(this.get("innerRadius", 0), radius);
let radiusStep = (radius - innerRadius) / this.get("levelCount", 1);
let yAxisRadius = $utils.relativeToValue(this.get("yAxisRadius", p50), radiusStep);
const points = $math.spiralPoints(0, 0, radius, radius, innerRadius, 20, radiusStep, this.get("startAngle", 0), this.get("endAngle", 360));
this.yAxes.each((axis) => {
const renderer = axis.get("renderer");
renderer._setC("axisLength", yAxisRadius);
axis.markDirtySize();
});
this.xAxes.each((axis) => {
const renderer = axis.get("renderer");
renderer.setPrivate("autoScale", false);
renderer._setC("points", points);
});
super._updateMasks();
}
}
SpiralChart.className = "SpiralChart";
SpiralChart.classNames = CurveChart.classNames.concat([SpiralChart.className]);
//# sourceMappingURL=SpiralChart.js.map