@amcharts/amcharts5
Version:
amCharts 5
90 lines • 3.27 kB
JavaScript
import { FlowNodes } from "./FlowNodes";
import { Circle } from "../../core/render/Circle";
import { Template } from "../../core/util/Template";
import { ListTemplate } from "../../core/util/List";
import { Label } from "../../core/render/Label";
;
;
;
/**
* Holds instances of nodes for a [[ArcDiagram]] series.
*/
export class ArcDiagramNodes extends FlowNodes {
constructor() {
super(...arguments);
/**
* List of label elements.
*
* @default new ListTemplate<Label>
*/
this.labels = this.addDisposer(new ListTemplate(Template.new({}), () => Label._new(this._root, {}, [this.labels.template])));
this._dAngle = 0;
/**
* List of slice elements.
*
* @default new ListTemplate<Slice>
*/
this.circles = this.addDisposer(new ListTemplate(Template.new({}), () => Circle._new(this._root, { themeTags: ["shape"] }, [this.circles.template])));
}
/**
* @ignore
*/
makeNode(dataItem) {
const node = super.makeNode(dataItem, "ArcDiagram");
const circle = node.children.insertIndex(0, this.circles.make());
dataItem.set("circle", circle);
circle._setSoft("fill", dataItem.get("fill"));
circle._setSoft("fillPattern", dataItem.get("fillPattern"));
const label = this.labels.make();
this.labels.push(label);
label.addTag("flow");
label.addTag("arcdiagram");
label.addTag("node");
node.children.push(label);
dataItem.set("label", label);
label._setDataItem(dataItem);
circle._setDataItem(dataItem);
return node;
}
_positionBullet(bullet) {
const sprite = bullet.get("sprite");
if (sprite) {
const dataItem = sprite.dataItem;
if (dataItem) {
const circle = dataItem.get("circle");
if (circle) {
// locations are fractions of the circle's bounding box, so the
// default 0.5/0.5 sits in the middle of the node
const radius = circle.get("radius", 0);
const locationX = bullet.get("locationX", 0.5);
const locationY = bullet.get("locationY", 0.5);
sprite.setAll({
x: radius * (2 * locationX - 1),
y: radius * (2 * locationY - 1)
});
}
}
}
}
/**
* @ignore
*/
disposeDataItem(dataItem) {
super.disposeDataItem(dataItem);
let circle = dataItem.get("circle");
if (circle) {
this.circles.removeValue(circle);
circle.dispose();
}
}
_updateNodeColor(dataItem) {
const circle = dataItem.get("circle");
if (circle) {
circle.set("fill", dataItem.get("fill"));
circle.set("fillPattern", dataItem.get("fillPattern"));
}
}
}
ArcDiagramNodes.className = "ArcDiagramNodes";
ArcDiagramNodes.classNames = FlowNodes.classNames.concat([ArcDiagramNodes.className]);
//# sourceMappingURL=ArcDiagramNodes.js.map