private updateTaskLabels()

in src/gantt.ts [1852:2043]


    private updateTaskLabels(
        tasks: GroupedTask[],
        width: number): void {

        let axisLabel: Selection<any>;
        let taskLabelsShow: boolean = this.viewModel.settings.taskLabels.show;
        let displayGridLines: boolean = this.viewModel.settings.general.displayGridLines;
        let taskLabelsColor: string = this.viewModel.settings.taskLabels.fill;
        let taskLabelsFontSize: number = this.viewModel.settings.taskLabels.fontSize;
        let taskLabelsWidth: number = this.viewModel.settings.taskLabels.width;
        let taskConfigHeight: number = this.viewModel.settings.taskConfig.height || DefaultChartLineHeight;
        const categoriesAreaBackgroundColor: string = this.colorHelper.getThemeColor();
        const isHighContrast: boolean = this.colorHelper.isHighContrast;

        if (taskLabelsShow) {
            this.lineGroupWrapper
                .attr("width", taskLabelsWidth)
                .attr("fill", isHighContrast ? categoriesAreaBackgroundColor : Gantt.DefaultValues.TaskCategoryLabelsRectColor)
                .attr("stroke", this.colorHelper.getHighContrastColor("foreground", Gantt.DefaultValues.TaskLineColor))
                .attr("stroke-width", 1);

            this.lineGroup
                .selectAll(Selectors.Label.selectorName)
                .remove();

            axisLabel = this.lineGroup
                .selectAll(Selectors.Label.selectorName)
                .data(tasks);

            let axisLabelGroup = axisLabel
                .enter()
                .append("g")
                .merge(axisLabel);

            axisLabelGroup.classed(Selectors.Label.className, true)
                .attr("transform", (task: GroupedTask) => SVGManipulations.translate(0, this.margin.top + this.getTaskLabelCoordinateY(task.index)));

            const clickableArea = axisLabelGroup
                .append("g")
                .classed(Selectors.ClickableArea.className, true)
                .merge(axisLabelGroup);

            clickableArea
                .append("text")
                .attr("x", (task: GroupedTask) => (Gantt.TaskLineCoordinateX +
                    (_.every(task.tasks, (task: Task) => !!task.parent)
                        ? Gantt.SubtasksLeftMargin
                        : (task.tasks[0].children && !!task.tasks[0].children.length) ? this.parentLabelOffset : 0)))
                .attr("class", (task: GroupedTask) => task.tasks[0].children ? "parent" : task.tasks[0].parent ? "child" : "normal-node")
                .attr("y", (task: GroupedTask) => (task.index + 0.5) * this.getResourceLabelTopMargin())
                .attr("fill", taskLabelsColor)
                .attr("stroke-width", Gantt.AxisLabelStrokeWidth)
                .style("font-size", PixelConverter.fromPoint(taskLabelsFontSize))
                .text((task: GroupedTask) => task.name)
                .call(AxisHelper.LabelLayoutStrategy.clip, width - Gantt.AxisLabelClip, textMeasurementService.svgEllipsis)
                .append("title")
                .text((task: GroupedTask) => task.name);

            const buttonSelection = clickableArea
                .filter((task: GroupedTask) => task.tasks[0].children && !!task.tasks[0].children.length)
                .append("svg")
                .attr("viewBox", "0 0 32 32")
                .attr("width", Gantt.DefaultValues.IconWidth)
                .attr("height", Gantt.DefaultValues.IconHeight)
                .attr("y", (task: GroupedTask) => (task.index + 0.5) * this.getResourceLabelTopMargin() - Gantt.DefaultValues.IconMargin)
                .attr("x", Gantt.DefaultValues.BarMargin);

            clickableArea
                .append("rect")
                .attr("width", 2 * Gantt.DefaultValues.IconWidth)
                .attr("height", 2 * Gantt.DefaultValues.IconWidth)
                .attr("y", (task: GroupedTask) => (task.index + 0.5) * this.getResourceLabelTopMargin() - Gantt.DefaultValues.IconMargin)
                .attr("x", Gantt.DefaultValues.BarMargin)
                .attr("fill", "transparent");

            const buttonPlusMinusColor = this.colorHelper.getHighContrastColor("foreground", Gantt.DefaultValues.PlusMinusColor);
            buttonSelection
                .each(function (task: GroupedTask) {
                    let element = d3.select(this);
                    if (!task.tasks[0].children[0].visibility) {
                        drawPlusButton(element, buttonPlusMinusColor);
                    } else {
                        drawMinusButton(element, buttonPlusMinusColor);
                    }
                });

            let parentTask: string = "";
            let childrenCount = 0;
            let currentChildrenIndex = 0;
            axisLabelGroup
                .append("rect")
                .attr("x", (task: GroupedTask) => {
                    const isGrouped = this.viewModel.settings.general.groupTasks;
                    const drawStandartMargin: boolean = !task.tasks[0].parent || task.tasks[0].parent && task.tasks[0].parent !== parentTask;
                    parentTask = task.tasks[0].parent ? task.tasks[0].parent : task.tasks[0].name;
                    if (task.tasks[0].children) {
                        parentTask = task.tasks[0].name;
                        childrenCount = isGrouped ? _.uniqBy(task.tasks[0].children, "name").length : task.tasks[0].children.length;
                        currentChildrenIndex = 0;
                    }

                    if (task.tasks[0].parent === parentTask) {
                        currentChildrenIndex++;
                    }
                    const isLastChild = childrenCount && childrenCount === currentChildrenIndex;
                    return drawStandartMargin || isLastChild ? Gantt.DefaultValues.ParentTaskLeftMargin : Gantt.DefaultValues.ChildTaskLeftMargin;
                })
                .attr("y", (task: GroupedTask) => (task.index + 1) * this.getResourceLabelTopMargin() + (taskConfigHeight - this.viewModel.settings.taskLabels.fontSize) / 2)
                .attr("width", () => displayGridLines ? this.viewport.width : 0)
                .attr("height", 1)
                .attr("fill", this.colorHelper.getHighContrastColor("foreground", Gantt.DefaultValues.TaskLineColor));

            axisLabel
                .exit()
                .remove();

            this.collapseAllGroup
                .selectAll("svg")
                .remove();

            this.collapseAllGroup
                .selectAll("rect")
                .remove();

            this.collapseAllGroup
                .selectAll("text")
                .remove();

            if (this.viewModel.isParentFilled) {
                let categoryLabelsWidth: number = this.viewModel.settings.taskLabels.width;
                this.collapseAllGroup
                    .append("rect")
                    .attr("width", categoryLabelsWidth)
                    .attr("height", 2 * Gantt.TaskLabelsMarginTop)
                    .attr("fill", categoriesAreaBackgroundColor);

                const expandCollapseButton = this.collapseAllGroup
                    .append("svg")
                    .classed(Selectors.CollapseAllArrow.className, true)
                    .attr("viewBox", "0 0 48 48")
                    .attr("width", this.groupLabelSize)
                    .attr("height", this.groupLabelSize)
                    .attr("x", 0)
                    .attr("y", this.secondExpandAllIconOffset)
                    .attr(this.collapseAllFlag, (this.collapsedTasks.length ? "1" : "0"));

                expandCollapseButton
                    .append("rect")
                    .attr("width", this.groupLabelSize)
                    .attr("height", this.groupLabelSize)
                    .attr("x", 0)
                    .attr("y", this.secondExpandAllIconOffset)
                    .attr("fill", "transparent");

                const buttonExpandCollapseColor = this.colorHelper.getHighContrastColor("foreground", Gantt.DefaultValues.CollapseAllColor);
                if (this.collapsedTasks.length) {
                    drawExpandButton(expandCollapseButton, buttonExpandCollapseColor);
                } else {
                    drawCollapseButton(expandCollapseButton, buttonExpandCollapseColor);
                }

                this.collapseAllGroup
                    .append("text")
                    .attr("x", this.secondExpandAllIconOffset + this.groupLabelSize)
                    .attr("y", this.groupLabelSize)
                    .attr("font-size", "12px")
                    .attr("fill", this.colorHelper.getHighContrastColor("foreground", Gantt.DefaultValues.CollapseAllTextColor))
                    .text(this.collapsedTasks.length ? "Expand All" : "Collapse All");
            }

        } else {
            this.lineGroupWrapper
                .attr("width", 0)
                .attr("fill", "transparent");

            this.collapseAllGroup
                .selectAll("image")
                .remove();

            this.collapseAllGroup
                .selectAll("rect")
                .remove();

            this.collapseAllGroup
                .selectAll("text")
                .remove();

            this.lineGroup
                .selectAll(Selectors.Label.selectorName)
                .remove();
        }
    }