_renderItems()

in client/client/modules/render/tracks/wig/wigRenderer.js [174:361]


    _renderItems(items, color, lineColor, viewport, wig, coordinateSystem) {
        if (coordinateSystem && coordinateSystem.isHeatMap) {
            return this._renderHeatMapItems(
                items,
                color,
                lineColor,
                viewport,
                wig,
                coordinateSystem,
            );
        }
        const block = new PIXI.Graphics();
        const line = new PIXI.Graphics();

        const pixelsPerBp = viewport.factor;

        block.beginFill(color, 1);
        const lineThickness = 1;
        line.lineStyle(lineThickness, lineColor, 1);

        // eslint-disable-next-line no-unused-vars
        let count = 0;

        for (let i = 0; i < items.length; i++) {
            const item = items[i];
            count++;
            if (item.points.length > 0) {
                const start = item.points[0];
                const padding = 0.5;
                if (
                    item.points.length === 1 ||
                    (wig.isDetailed &&
                        pixelsPerBp >= this._config.wig.detailedStyleStartingAtPixelsPerBP)
                ) {
                    const startX1 = this.correctCanvasXPosition(
                        Math.round(
                            viewport.project.brushBP2pixel(start.startIndex - VIEWPORT_PADDING) + padding
                        ),
                        viewport
                    );
                    let startX2 = this.correctCanvasXPosition(
                        Math.round(
                            viewport.project.brushBP2pixel(start.endIndex + VIEWPORT_PADDING) - padding
                        ),
                        viewport
                    );

                    if (startX1 === startX2) {
                        startX2++; // bar should have minimum 1px width
                    }

                    block.moveTo(startX1, this._getYValue(wig.baseAxis, coordinateSystem));
                    block.lineTo(startX1, this._getYValue(start.dataValue, coordinateSystem));
                    block.lineTo(startX2, this._getYValue(start.dataValue, coordinateSystem));
                    block.lineTo(startX2, this._getYValue(wig.baseAxis, coordinateSystem));

                    line.moveTo(
                        startX1,
                        this._getYValue(start.dataValue, coordinateSystem) - lineThickness / 2,
                    );
                    line.lineTo(
                        startX2,
                        this._getYValue(start.dataValue, coordinateSystem) - lineThickness / 2,
                    );

                    let prevX = startX2;

                    for (let j = 1; j < item.points.length; j++) {
                        count++;
                        const point = item.points[j];
                        let startX = this.correctCanvasXPosition(
                            Math.round(
                                viewport.project.brushBP2pixel(point.startIndex - VIEWPORT_PADDING) + padding
                            ),
                            viewport
                        );
                        const endX = this.correctCanvasXPosition(
                            Math.round(
                                viewport.project.brushBP2pixel(point.endIndex + VIEWPORT_PADDING) - padding
                            ),
                            viewport
                        );
                        if (startX === prevX) {
                            startX++;
                        }
                        block.lineTo(startX, this._getYValue(wig.baseAxis, coordinateSystem));
                        block.lineTo(startX, this._getYValue(point.dataValue, coordinateSystem));
                        block.lineTo(endX, this._getYValue(point.dataValue, coordinateSystem));
                        block.lineTo(endX, this._getYValue(wig.baseAxis, coordinateSystem));

                        line.moveTo(
                            startX,
                            this._getYValue(point.dataValue, coordinateSystem) - lineThickness / 2,
                        );
                        line.lineTo(
                            endX,
                            this._getYValue(point.dataValue, coordinateSystem) - lineThickness / 2,
                        );

                        prevX = endX;
                    }

                    block.lineTo(startX1, this._getYValue(wig.baseAxis, coordinateSystem));
                } else {
                    const startX1 = this.correctCanvasXPosition(
                        Math.round(
                            viewport.project.brushBP2pixel(start.startIndex - VIEWPORT_PADDING) + padding
                        ),
                        viewport
                    );
                    const startX2 = this.correctCanvasXPosition(
                        Math.round(
                            viewport.project.brushBP2pixel(start.endIndex + VIEWPORT_PADDING) - padding
                        ),
                        viewport
                    );

                    block.moveTo(startX1, this._getYValue(wig.baseAxis, coordinateSystem));
                    block.lineTo(startX1, this._getYValue(start.dataValue, coordinateSystem));
                    block.lineTo(startX2, this._getYValue(start.dataValue, coordinateSystem));

                    line.moveTo(
                        startX1 - lineThickness / 2,
                        this._getYValue(wig.baseAxis, coordinateSystem),
                    );
                    line.lineTo(
                        startX1 - lineThickness / 2,
                        this._getYValue(start.dataValue, coordinateSystem) - lineThickness / 2,
                    );
                    line.lineTo(
                        startX1,
                        this._getYValue(start.dataValue, coordinateSystem) - lineThickness / 2,
                    );
                    line.lineTo(
                        startX2,
                        this._getYValue(start.dataValue, coordinateSystem) - lineThickness / 2,
                    );

                    for (let j = 1; j < item.points.length; j++) {
                        count++;
                        const point = item.points[j];
                        const x1 = this.correctCanvasXPosition(
                            Math.round(
                                viewport.project.brushBP2pixel(point.startIndex - VIEWPORT_PADDING) + padding
                            ),
                            viewport
                        );
                        const x2 = this.correctCanvasXPosition(
                            Math.round(
                                viewport.project.brushBP2pixel(point.endIndex + VIEWPORT_PADDING) - padding
                            ),
                            viewport
                        );
                        block.lineTo(x1, this._getYValue(point.dataValue, coordinateSystem));
                        block.lineTo(x2, this._getYValue(point.dataValue, coordinateSystem));

                        line.lineTo(
                            x1,
                            this._getYValue(point.dataValue, coordinateSystem) - lineThickness / 2,
                        );
                        line.lineTo(
                            x2,
                            this._getYValue(point.dataValue, coordinateSystem) - lineThickness / 2,
                        );
                    }

                    const end = item.points[item.points.length - 1];
                    const endX = this.correctCanvasXPosition(
                        Math.round(viewport.project.brushBP2pixel(end.endIndex + VIEWPORT_PADDING) - padding),
                        viewport
                    );
                    block.lineTo(endX, this._getYValue(wig.baseAxis, coordinateSystem));
                    block.lineTo(startX1, this._getYValue(wig.baseAxis, coordinateSystem));

                    line.lineTo(
                        endX - lineThickness / 2,
                        this._getYValue(end.dataValue, coordinateSystem) - lineThickness / 2,
                    );
                    line.lineTo(
                        endX - lineThickness / 2,
                        this._getYValue(wig.baseAxis, coordinateSystem) - lineThickness / 2,
                    );
                }
            }
        }
        block.endFill();
        return { block, line };
    }