private renderLegend()

in src/TornadoChart.ts [1123:1166]


    private renderLegend(): void {
        let settings: TornadoChartSettings = this.dataView.settings;
        if (settings.showLegend) {

            let legend: LegendData = this.dataView.legend;
            if (!legend) {
                return;
            }
            let legendData: LegendData = {
                title: legend.title,
                dataPoints: legend.dataPoints,
                fontSize: settings.legendFontSize,
                labelColor: settings.legendColor
            };

            if (this.dataView.legendObjectProperties) {
                let position: string;
                LegendDataModule.update(legendData, this.dataView.legendObjectProperties);

                position = <string>this.dataView.legendObjectProperties[legendProps.position];

                if (position) {
                    this.legend.changeOrientation(LegendPosition[position]);
                }
            }

            // Draw the legend on a viewport with the original height and width
            let viewport: IViewport = {
                height: this.viewport.height + this.margin.top + this.margin.bottom,
                width: this.viewport.width + this.margin.left + this.margin.right,
            };

            this.legend.drawLegend(legendData, { ...this.viewport });
            LegendModule.positionChartArea(this.root, this.legend);

            if (legendData.dataPoints.length > 0 && settings.showLegend) {
                this.updateViewport();
            }
        }
        else {
            this.legend.reset();
            this.legend.drawLegend({ dataPoints: [] }, this.viewport);
        }
    }