<commit_before>import FeatureBaseRenderer from '../../../../../gene/internal/renderer/features/drawing/featureBaseRenderer';
import PIXI from 'pixi.js';
import {ColorProcessor, PixiTextSize} from '../../../../../../utilities';
import drawStrandDirection from '../../../../../gene/internal/renderer/features/drawing/strandDrawing';
import {drawingConfiguration} from '../../../../../../core';

const Math = window.Math;

export default class BedItemFeatureRenderer extends FeatureBaseRenderer {
    constructor(track, config, registerLabel, registerDockableElement, registerFeaturePosition, registerAttachedElement) {
        super(config, registerLabel, registerDockableElement, registerFeaturePosition, registerAttachedElement);
        this.track = track;
    }

    analyzeBoundaries(feature, viewport) {
        const boundaries = super.analyzeBoundaries(feature, viewport);
        const labelSize = PixiTextSize.getTextSize(feature.name, this.config.bed.label);
        let descriptionLabelSize = {height: 0, width: 0};
        if (feature.description && feature.description.length < this.config.bed.description.maximumDisplayLength) {
            descriptionLabelSize = PixiTextSize.getTextSize(feature.description, this.config.bed.description.label);
        }
        if (boundaries.rect) {
            boundaries.rect.x2 = Math.max(boundaries.rect.x2, boundaries.rect.x1 + labelSize.width);
            if (boundaries.rect.x2 - boundaries.rect.x1 < descriptionLabelSize.width) {
                descriptionLabelSize.height = 0;
            }
            boundaries.rect.y2 = 2 * this.config.bed.margin + this.config.bed.height + labelSize.height + descriptionLabelSize.height;
        }
        return boundaries;
    }

    _getFeatureColor(feature, state) {
        if (state && state.color && !feature.rgb) {
            return state.color;
        }
        let color = this.config.bed.defaultColor;
        const oneByte = 256;
        if (feature.rgb) {
            color = feature.rgb[0] * oneByte * oneByte + feature.rgb[1] * oneByte + feature.rgb[2];
        }
        return color;
    }

    render(feature, viewport, graphics, hoveredGraphics, labelContainer, dockableElementsContainer, attachedElementsContainer,  position) {
        super.render(feature, viewport, graphics, hoveredGraphics, labelContainer, dockableElementsContainer, attachedElementsContainer, position);
        const pixelsInBp = viewport.factor;
        const label = new PIXI.Text(feature.name, this.config.bed.label);
        label.resolution = drawingConfiguration.resolution;
        label.x = Math.round(position.x);
        label.y = Math.round(position.y);
        dockableElementsContainer.addChild(label);
        const yStart = position.y;
        this.registerLabel(label, position, {end: feature.endIndex, start: feature.startIndex});
        if (feature.description && feature.description.length < this.config.bed.description.maximumDisplayLength) {
            const descriptionLabelWidth = PixiTextSize.getTextSize(feature.description, this.config.bed.description.label).width;
            if (descriptionLabelWidth < position.width) {
                const descriptionLabel = new PIXI.Text(feature.description, this.config.bed.description.label);
                descriptionLabel.resolution = drawingConfiguration.resolution;
                descriptionLabel.x = Math.round(position.x);
                descriptionLabel.y = Math.round(position.y + label.height);
                dockableElementsContainer.addChild(descriptionLabel);
                this.registerLabel(descriptionLabel, {
                    x: position.x,
                    y: Math.round(position.y + label.height)
                }, {
                    end: feature.endIndex,
                    start: feature.startIndex
                });
                position.y += descriptionLabel.height;
            }
        }
        
        position.y += label.height;

        this.registerFeaturePosition(feature, {
            x1: viewport.project.brushBP2pixel(feature.startIndex) - pixelsInBp / 2,
            x2: Math.max(viewport.project.brushBP2pixel(feature.endIndex) + pixelsInBp / 2, position.x + label.width),
            y1: yStart,
            y2: position.y + this.config.bed.height
        });

        const color = this._getFeatureColor(feature, this.track ? this.track.state : undefined);
        let structureToDisplay = null;
<commit_msg>Support for the narrowPeak and broadPeak (#356) - don't show '.' feature names<commit_after>import FeatureBaseRenderer from '../../../../../gene/internal/renderer/features/drawing/featureBaseRenderer';
import PIXI from 'pixi.js';
import {ColorProcessor, PixiTextSize} from '../../../../../../utilities';
import drawStrandDirection from '../../../../../gene/internal/renderer/features/drawing/strandDrawing';
import {drawingConfiguration} from '../../../../../../core';

const Math = window.Math;

export default class BedItemFeatureRenderer extends FeatureBaseRenderer {
    constructor(track, config, registerLabel, registerDockableElement, registerFeaturePosition, registerAttachedElement) {
        super(config, registerLabel, registerDockableElement, registerFeaturePosition, registerAttachedElement);
        this.track = track;
    }

    analyzeBoundaries(feature, viewport) {
        const boundaries = super.analyzeBoundaries(feature, viewport);
        let descriptionLabelSize = {height: 0, width: 0};
        let labelSize = {height: 0, width: 0};
        if (feature.name && feature.name !== '.') {
            labelSize = PixiTextSize.getTextSize(feature.name, this.config.bed.label);
        }
        if (feature.description && feature.description.length < this.config.bed.description.maximumDisplayLength) {
            descriptionLabelSize = PixiTextSize.getTextSize(feature.description, this.config.bed.description.label);
        }
        if (boundaries.rect) {
            boundaries.rect.x2 = Math.max(boundaries.rect.x2, boundaries.rect.x1 + labelSize.width);
            if (boundaries.rect.x2 - boundaries.rect.x1 < descriptionLabelSize.width) {
                descriptionLabelSize.height = 0;
            }
            boundaries.rect.y2 = 2 * this.config.bed.margin + this.config.bed.height + labelSize.height + descriptionLabelSize.height;
        }
        return boundaries;
    }

    _getFeatureColor(feature, state) {
        if (state && state.color && !feature.rgb) {
            return state.color;
        }
        let color = this.config.bed.defaultColor;
        const oneByte = 256;
        if (feature.rgb) {
            color = feature.rgb[0] * oneByte * oneByte + feature.rgb[1] * oneByte + feature.rgb[2];
        }
        return color;
    }

    render(feature, viewport, graphics, hoveredGraphics, labelContainer, dockableElementsContainer, attachedElementsContainer,  position) {
        super.render(feature, viewport, graphics, hoveredGraphics, labelContainer, dockableElementsContainer, attachedElementsContainer, position);
        const pixelsInBp = viewport.factor;
        const yStart = position.y;
        let labelHeight = 0;
        let labelWidth = 0;
        if (feature.name && feature.name !== '.') {
            const label = new PIXI.Text(feature.name, this.config.bed.label);
            label.resolution = drawingConfiguration.resolution;
            label.x = Math.round(position.x);
            label.y = Math.round(position.y);
            dockableElementsContainer.addChild(label);
            labelHeight = label.height;
            labelWidth = label.width;
            this.registerLabel(label, position, {end: feature.endIndex, start: feature.startIndex});
        }
        if (feature.description && feature.description.length < this.config.bed.description.maximumDisplayLength) {
            const descriptionLabelWidth = PixiTextSize.getTextSize(feature.description, this.config.bed.description.label).width;
            if (descriptionLabelWidth < position.width) {
                const descriptionLabel = new PIXI.Text(feature.description, this.config.bed.description.label);
                descriptionLabel.resolution = drawingConfiguration.resolution;
                descriptionLabel.x = Math.round(position.x);
                descriptionLabel.y = Math.round(position.y + labelHeight);
                dockableElementsContainer.addChild(descriptionLabel);
                this.registerLabel(descriptionLabel, {
                    x: position.x,
                    y: Math.round(position.y + labelHeight)
                }, {
                    end: feature.endIndex,
                    start: feature.startIndex
                });
                position.y += descriptionLabel.height;
            }
        }
        
        position.y += labelHeight;

        this.registerFeaturePosition(feature, {
            x1: viewport.project.brushBP2pixel(feature.startIndex) - pixelsInBp / 2,
            x2: Math.max(viewport.project.brushBP2pixel(feature.endIndex) + pixelsInBp / 2, position.x + labelWidth),
            y1: yStart,
            y2: position.y + this.config.bed.height
        });

        const color = this._getFeatureColor(feature, this.track ? this.track.state : undefined);
        let structureToDisplay = null;

{'fraction_non_alphanumeric': 0.113197367001187, 'fraction_numerical': 0.005935038307974533, 'mean_word_length': 2.52797868290826, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1379228', 'n_tokens_mistral': 2451, 'n_tokens_neox': 2376, 'n_words': 459}