export class AxisLabelComponentSvg { addLabel(parent, viewModel) { if (!viewModel) { return; } let label = viewModel.label, x = viewModel.x, y = viewModel.y, rotation = viewModel.rotation; parent.append("text") .attr("class", "axis-label") // this makes it easy to centre the text as the transform is applied to the anchor .attr("text-anchor", "middle") // text is drawn off the screen top left, move down and out and rotate .attr("transform", `translate(${x}, ${y}) rotate(${rotation})`) .text(label); } updateView(parent, viewModel): AxisLabelComponentSvg { this.addLabel(parent, viewModel.labelLeft); this.addLabel(parent, viewModel.labelBottom); this.addLabel(parent, viewModel.labelRight); return this; } }