<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * Initializes a legend root scene.
 * 
 * @name pvc.visual.legend.LegendRootScene
 * 
 * @extends pvc.visual.Scene
 * 
 * @constructor
 * @param {pvc.visual.Scene} [parent] The parent scene, if any.
 * @param {object} [keyArgs] Keyword arguments.
 * See {@link pvc.visual.Scene} for supported keyword arguments.
 */
/*global pvc_Sides:true, pvc_Size:true */
def
.type('pvc.visual.legend.LegendRootScene', pvc.visual.Scene)
.init(function(parent, keyArgs) {
    
    this.base(parent, keyArgs);
    
    this._unresolvedMarkerDiam  = def.get(keyArgs, 'markerSize');
    this._unresolvedItemPadding = new pvc_Sides(def.get(keyArgs, 'itemPadding', 5));
    this._unresolvedItemSize    = pvc_Size.to(def.get(keyArgs, 'itemSize')) || new pvc_Size();

    def.set(this.vars,
        'horizontal',  def.get(keyArgs, 'horizontal', false),
        'font',        def.get(keyArgs, 'font'),
        // Space between marker and text.
        // -3 is to compensate for now the label being anchored to 
        // the panel instead of the rule or the dot...
        'textMargin',  (def.get(keyArgs, 'textMargin', 6) - 3));
})
.add(/** @lends pvc.visual.legend.LegendRootScene# */{
    layout: function(layoutInfo) {
        // Any size available?
        var clientSize = layoutInfo.clientSize;
        if(!(clientSize.width > 0 && clientSize.height > 0)) return new pvc_Size(0,0);

        var desiredClientSize = layoutInfo.desiredClientSize,

            // The size of the biggest cell
            itemPadding = this._unresolvedItemPadding.resolve(clientSize),

            // This facilitates making the calculations for the margins of border items
            //  to not be included.
            extClientSize = {
                width:  clientSize.width  + itemPadding.width,
                height: clientSize.height + itemPadding.height
            },

            // May come with both width/height to null
            desiredItemSize = this._unresolvedItemSize.resolve(extClientSize),
            desiredItemClientSize = {
                width:  desiredItemSize.width  && Math.max(0, desiredItemSize.width  - itemPadding.width ),
                height: desiredItemSize.height && Math.max(0, desiredItemSize.height - itemPadding.height)
            },

            markerDiam = this._unresolvedMarkerDiam || desiredItemClientSize.height || 15;
        
        this.vars.itemPadding           = itemPadding;
        this.vars.desiredItemSize       = desiredItemSize;
        this.vars.desiredItemClientSize = desiredItemClientSize;
        this.vars.markerSize            = markerDiam;
        
        var textLeft      = markerDiam + this.vars.textMargin,
            labelWidthMax = Math.max(0,
                Math.min(
                    (desiredItemClientSize.width || Infinity),
                    (desiredClientSize.width     || Infinity), 
                    clientSize.width) - 
                textLeft),
            // Names are for legend items when laid out in sections
            a_width  = this.vars.horizontal ? 'width' : 'height',
            a_height = pvc.BasePanel.oppositeLength[a_width], // height or width
            section,
            sections = [],
            contentSize = {width: 0, height: 0},
            $maxSectionWidth = desiredClientSize[a_width];

        if(!$maxSectionWidth || $maxSectionWidth < 0) $maxSectionWidth = clientSize[a_width]; // row or col

        this.childNodes.forEach(function(groupScene) { groupScene.childNodes.forEach(layoutItem, this); }, this);
        
        // If there's no pending section to commit, there are no sections...
        // No items or just items with no text -> hide
        if(!section) return new pvc_Size(0,0);
        
        commitSection(/* isLast */ true);
        
        def.set(this.vars,
            'sections',      sections,
            'contentSize',   contentSize,
            'labelWidthMax', labelWidthMax);
        
        var isV1Compat = this.compatVersion() <= 1,
            // Request used width / all available width (V1)
            $w = isV1Compat ? $maxSectionWidth : contentSize[a_width],
            $h = desiredClientSize[a_height];

        if(!$h || $h < 0) $h = contentSize[a_height];

        // requestSize<commit_msg>[CDF-303] - CCC - Explicitly setting the size of the legend is not taking effect.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * Initializes a legend root scene.
 * 
 * @name pvc.visual.legend.LegendRootScene
 * 
 * @extends pvc.visual.Scene
 * 
 * @constructor
 * @param {pvc.visual.Scene} [parent] The parent scene, if any.
 * @param {object} [keyArgs] Keyword arguments.
 * See {@link pvc.visual.Scene} for supported keyword arguments.
 */
/*global pvc_Sides:true, pvc_Size:true */
def
.type('pvc.visual.legend.LegendRootScene', pvc.visual.Scene)
.init(function(parent, keyArgs) {
    
    this.base(parent, keyArgs);
    
    this._unresolvedMarkerDiam  = def.get(keyArgs, 'markerSize');
    this._unresolvedItemPadding = new pvc_Sides(def.get(keyArgs, 'itemPadding', 5));
    this._unresolvedItemSize    = pvc_Size.to(def.get(keyArgs, 'itemSize')) || new pvc_Size();

    def.set(this.vars,
        'horizontal',  def.get(keyArgs, 'horizontal', false),
        'font',        def.get(keyArgs, 'font'),
        // Space between marker and text.
        // -3 is to compensate for now the label being anchored to 
        // the panel instead of the rule or the dot...
        'textMargin',  (def.get(keyArgs, 'textMargin', 6) - 3));
})
.add(/** @lends pvc.visual.legend.LegendRootScene# */{
    layout: function(layoutInfo) {
        // Any size available?
        var clientSize = layoutInfo.clientSize;
        if(!(clientSize.width > 0 && clientSize.height > 0)) return new pvc_Size(0,0);

        var desiredClientSize = layoutInfo.desiredClientSize,

            // The size of the biggest cell
            itemPadding = this._unresolvedItemPadding.resolve(clientSize),

            // This facilitates making the calculations for the margins of border items
            //  to not be included.
            extClientSize = {
                width:  clientSize.width  + itemPadding.width,
                height: clientSize.height + itemPadding.height
            },

            // May come with both width/height to null
            desiredItemSize = this._unresolvedItemSize.resolve(extClientSize),
            desiredItemClientSize = {
                width:  desiredItemSize.width  && Math.max(0, desiredItemSize.width  - itemPadding.width ),
                height: desiredItemSize.height && Math.max(0, desiredItemSize.height - itemPadding.height)
            },

            markerDiam = this._unresolvedMarkerDiam || desiredItemClientSize.height || 15;
        
        this.vars.itemPadding           = itemPadding;
        this.vars.desiredItemSize       = desiredItemSize;
        this.vars.desiredItemClientSize = desiredItemClientSize;
        this.vars.markerSize            = markerDiam;
        
        var textLeft      = markerDiam + this.vars.textMargin,
            labelWidthMax = Math.max(0,
                Math.min(
                    (desiredItemClientSize.width || Infinity),
                    (desiredClientSize.width     || Infinity), 
                    clientSize.width) - 
                textLeft),
            // Names are for legend items when laid out in sections
            a_width  = this.vars.horizontal ? 'width' : 'height',
            a_height = pvc.BasePanel.oppositeLength[a_width], // height or width
            section,
            sections = [],
            contentSize = {width: 0, height: 0},
            desiredSectionWidth = desiredClientSize[a_width],
            $maxSectionWidth = desiredSectionWidth;

        if(!$maxSectionWidth || $maxSectionWidth < 0) $maxSectionWidth = clientSize[a_width]; // row or col

        this.childNodes.forEach(function(groupScene) { groupScene.childNodes.forEach(layoutItem, this); }, this);
        
        // If there's no pending section to commit, there are no sections...
        // No items or just items with no text -> hide
        if(!section) return new pvc_Size(0,0);
        
        commitSection(/* isLast */ true);
        
        def.set(this.vars,
            'sections',      sections,
            'contentSize',   contentSize,
            'labelWidthMax', labelWidthMax);
        
        var isV1Compat = this.compatVersion() <= 1,
            // Request used width / all available width (V1)
            $w = isV1Compat ? $maxSectionWidth : desiredSectionWidth,
            $h = desiredClientSize[a_height];

        if(!$w || $w < 0) $w = contentSize[a_width ];
        if(!$h || $h < 0) $h = contentSize[a_height];

        // requestSize
{'fraction_non_alphanumeric': 0.11005047180162388, 'fraction_numerical': 0.006363835856923414, 'mean_word_length': 2.1859489688919957, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, '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': '138305', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2532, 'n_words': 656}