protected handleClickEvent()

in clns-acuity-vahub/vahub/src/main/webapp/src/app/common/trellising/grid/plot/plottypes/rangeplot/RangePlotComponent.ts [295:414]


    protected handleClickEvent(event: ChartMouseEvent): boolean {
        if (event.point.selected) {
            this.displayMarkingDialogue.emit({x: event.chartX, y: event.chartY});
        } else {
            const x = event.point.category;
            const yMin = event.point.y;
            const yMax = event.point.y;
            let newRanges = [];
            let selection: List<IChartSelection>;
            let trellising;
            if (event.point.series.name === 'All'
                || this.tabId === TabId.LAB_LINEPLOT
                || this.tabId === TabId.SINGLE_SUBJECT_LAB_LINEPLOT) {
                trellising = this.trellising;
            } else {
                trellising = this.trellising.concat([{
                    trellisedBy: this.series[0].trellisedBy,
                    trellisOption: event.point.series.name,
                    category: this.series[0].category
                }]);
            }

            // Appending selection
            if (event.ctrlKey) {
                newRanges = _.cloneDeep(this.currentSelection);
                newRanges = newRanges ? newRanges : [];

                const trellisOption: string = trellising[0].trellisOption;
                const categories = _.flatten(this.selection
                    .filter(i =>
                        !trellisOption || i.toJS().trellising[0].trellisOption === trellisOption)
                    .map(i => i.get('bars'))
                    .toJS());

                let selectionInPlot;

                if (this.tabId === TabId.LAB_LINEPLOT || this.tabId === TabId.SINGLE_SUBJECT_LAB_LINEPLOT) {
                    const newCategory = {
                        category: x,
                        series: event.point.series.name
                    };
                    categories.push(newCategory);

                    newRanges.push({
                        categories: [newCategory],
                        yMin: yMin,
                        yMax: yMax
                    });

                    selectionInPlot = fromJS({
                        series: this.series,
                        trellising: trellising,
                        bars: categories,
                        range: newRanges
                    });
                } else {
                    newRanges.push({
                        categories: [x],
                        yMin: yMin,
                        yMax: yMax
                    });

                    selectionInPlot = fromJS({
                        series: this.series,
                        trellising: trellising,
                        range: newRanges
                    });
                }
                if (this.selection && this.selection.size > 0) {
                    const currentSelection = [];
                    this.selection
                        .filter((selectionItem) => {
                            const currentTrellising = selectionItem.get('trellising', null);
                            return !(currentTrellising && _.isEqual(currentTrellising.toJS(), this.trellising));
                        })
                        .forEach(subSelection => currentSelection.push(subSelection));
                    currentSelection.push(selectionInPlot);
                    selection = List(currentSelection);
                } else {
                    selection = List.of(selectionInPlot);
                }
            } else {
                let categories = [x];
                if (this.tabId === TabId.LAB_LINEPLOT || this.tabId === TabId.SINGLE_SUBJECT_LAB_LINEPLOT) {
                    categories = [{
                        category: x,
                        series: event.point.series.name
                    }];
                    newRanges.push({
                        categories,
                        yMin: yMin,
                        yMax: yMax
                    });

                    selection = List.of(fromJS({
                        bars: categories,
                        series: this.series,
                        trellising: trellising,
                        range: newRanges
                    }));
                } else {
                    newRanges.push({
                        categories,
                        yMin: yMin,
                        yMax: yMax
                    });

                    selection = List.of(fromJS({
                        series: this.series,
                        trellising: trellising,
                        range: newRanges
                    }));
                }
            }

            this.trellisingMiddleware.updateSelection(selection);
            this.displayMarkingDialogue.emit({x: event.chartX, y: event.chartY});
        }
        return false;
    }