<commit_before>var thematicalVectorConfiguratorLabel = {
    'selectValue': OpenLayers.i18n('Select a value'),
    'attribute': OpenLayers.i18n('Attribute'),
    'exact': OpenLayers.i18n('Exact'),
    'range': OpenLayers.i18n('Range'),
    'value': OpenLayers.i18n('Value'),
    'color': OpenLayers.i18n('Color'),
    'min': OpenLayers.i18n('Min'),
    'max': OpenLayers.i18n('Max'),
    'execute': OpenLayers.i18n('Execute'),
    'addInputField': OpenLayers.i18n('Add input'),
    'removeInputField': OpenLayers.i18n('Remove input'),
    'active': OpenLayers.i18n('Active'),
    'choose': OpenLayers.i18n('Choose value'),
    'noInput': OpenLayers.i18n('No entries'),
    'noLayer': OpenLayers.i18n('No layer selected'),
    'attributes': OpenLayers.i18n('Attributes'),
    'showInList': OpenLayers.i18n('Show in list'),
    'showInPopup': OpenLayers.i18n('Show in popup'),
    'apply': OpenLayers.i18n('Apply'),
    'noLayer': OpenLayers.i18n('No layer selected'),
    'noAttributes': OpenLayers.i18n('Layer have no attributes'),
    'mapSettings': OpenLayers.i18n('Map Settings'),
    'listSettings': OpenLayers.i18n('List Settings'),
    'maxListAttributesArrived': OpenLayers.i18n('Maximum of selectable shortlist attributes arrived'),
    'maxPopupAttributesArrived': OpenLayers.i18n('Maximum of selectable popup attributes arrived')
};
var ThematicalVectorConfiguratorTitles = {
    'showExact': OpenLayers.i18n('Create thematical map using exact values'),
    'rangeExact': OpenLayers.i18n('Create thematical map using ranges'),
    'addInput': OpenLayers.i18n('Add input field')
};

gbi.widgets = gbi.widgets || {};

gbi.widgets.ThematicalVectorConfigurator = function(thematicalVector, options) {
    if(!(thematicalVector instanceof gbi.widgets.ThematicalVector)) {
        return;
    }
    var self = this;
    var defaults = {
        element: 'thematicalvectorconfigurator',
        mode: 'exact',
        restrictSelectableAttributes: 10,
        initOnly: false
    }
    this.options = $.extend({}, defaults, options);
    this.thematicalVector = thematicalVector
    this.editor = thematicalVector.editor;
    this.activeLayer = this.editor.layerManager.active();
    this.attributes = [];
    this.mode = this.options.mode;

    $(gbi).on('gbi.layermanager.layer.active', function(event, layer) {
        self.activeLayer = layer;
        if(self.activeLayer) {
            self._registerLayerEvents(self.activeLayer);
            self.attributes = self.activeLayer.fullListAttributes() || [];
            if(self.attributes.length == 0) {
                self.attributes = self.activeLayer.featuresAttributes() || [];
            }
        } else {
            self.attributes = [];
        }
        self.render();
    });
    if(this.activeLayer) {
        this._registerLayerEvents(this.activeLayer);
        this.attributes = this.activeLayer.fullListAttributes() || [];
        if(this.attributes.length == 0) {
            this.attributes = this.activeLayer.featuresAttributes() || [];
        }
    } else {
        this.attributes = [];
    }

    if(!this.options.initOnly) {
        self.render();
    }
};
gbi.widgets.ThematicalVectorConfigurator.prototype = {
    CLASS_NAME: 'gbi.widgets.ThematicalVectorConfigurator',
    render: function() {
        var self = this;
        var element = $('#' + this.options.element);
        element.empty();

        if(!self.activeLayer) {
            element.append($('<div class="text-center">' + thematicalVectorConfiguratorLabel.noLayer + '</div>'));
            return;
        }

        element.append(tmpl(
            gbi.widgets.ThematicalVectorConfigurator.template, {
                attributes: self.attributes,
                defaultColors: gbi.widgets.ThematicalVectorConfigurator.defaultColors
            }
        ));

        $('#rangeInputDiv').hide();

        $('#toggleExact').click(function() {
            self.toggleExact();
        });

        $('#toggleRange').click(function() {
            self.toggleRange();
        });

        $('#attribute').change(function() {
            $.each($('.exactInputControl select'), function(idx, element) {
                element = $(element);
                self.fillExactInputSelect(element, element.val());
                self.execute();
            });
        });

        $('#addInput').click(function() {
            self.addInput(self.mode);
        });

        var shortListAttributes = self.activeLayer ? self.activeLayer.shortListAttributes() : [];
        var popupAttributes = self.activeLayer ? self.activeLayer.popupAttributes() : [];

        if(shortListAttributes) {
            element.find('.list-attribute').each(function(idx, elm) {
                elm = $(elm);
                elm.change(function() {
                    if(self._restrictAttributes(element, elm, '.list-attribute')) {
                        self.setListPopupAttributes(element);
                    }
                });
                if($.inArray(elm.val(), shortListAttributes) != -1) {
                    elm.attr('checked', 'checked');
                }

            })
        }

        if(popupAttributes) {
            element.find('.popup-attribute').each(function(idx, elm) {
                elm = $(elm);
                elm.change(function() {
                    if(self._restrictAttributes(element, elm, '.popup-attribute')) {
                        self.setListPopupAttributes(element);
                    }
                });
                if($.inArray(elm.val(), popupAttributes) != -1) {
                    elm.attr('checked', 'checked');
                }
            })
        }

        element.find('#sortable').sortable({
            stop: function() {
                self.setListPopupAttributes(element);
            }
        });

        if(this.activeLayer && this.activeLayer.featureStylingRule) {
            element.find('#attribute').val(this.activeLayer.featureStylingRule.attribute);
            this.mode = this.activeLayer.featureStylingRule.type;
            switch(this.mode) {
                case 'exact':
                    this.toggleExact();
                    $.each(this.activeLayer.featureStylingRule.filterOptions, function(idx, filterOption) {
                        self.addInput('exact', filterOption);
                    });
                    this.addInput('range');
                    break;
                case 'range':
                    this.toggleRange()
                    $.each(this.activeLayer.featureStylingRule.filterOptions, function(idx, filterOption) {
                        self.addInput('range', filterOption);
                    });
                    this.addInput('exact');
                    break;
            }

        } else {
            this.addInput('exact');
            this.addInput('range');
        }
    },
    toggleExact: function() {
        var self = this;
        $('#toggleRange').removeClass('active');
        $('#toggleExact').addClass('active')
        $('#rangeInputDiv').hide();
        $('#exactInputDiv').show();
        self.mode = "exact";
    },
    toggleRange: function() {<commit_msg>use correct metadata for thematicalmap<commit_after>var thematicalVectorConfiguratorLabel = {
    'selectValue': OpenLayers.i18n('Select a value'),
    'attribute': OpenLayers.i18n('Attribute'),
    'exact': OpenLayers.i18n('Exact'),
    'range': OpenLayers.i18n('Range'),
    'value': OpenLayers.i18n('Value'),
    'color': OpenLayers.i18n('Color'),
    'min': OpenLayers.i18n('Min'),
    'max': OpenLayers.i18n('Max'),
    'execute': OpenLayers.i18n('Execute'),
    'addInputField': OpenLayers.i18n('Add input'),
    'removeInputField': OpenLayers.i18n('Remove input'),
    'active': OpenLayers.i18n('Active'),
    'choose': OpenLayers.i18n('Choose value'),
    'noInput': OpenLayers.i18n('No entries'),
    'noLayer': OpenLayers.i18n('No layer selected'),
    'attributes': OpenLayers.i18n('Attributes'),
    'showInList': OpenLayers.i18n('Show in list'),
    'showInPopup': OpenLayers.i18n('Show in popup'),
    'apply': OpenLayers.i18n('Apply'),
    'noLayer': OpenLayers.i18n('No layer selected'),
    'noAttributes': OpenLayers.i18n('Layer have no attributes'),
    'mapSettings': OpenLayers.i18n('Map Settings'),
    'listSettings': OpenLayers.i18n('List Settings'),
    'maxListAttributesArrived': OpenLayers.i18n('Maximum of selectable shortlist attributes arrived'),
    'maxPopupAttributesArrived': OpenLayers.i18n('Maximum of selectable popup attributes arrived')
};
var ThematicalVectorConfiguratorTitles = {
    'showExact': OpenLayers.i18n('Create thematical map using exact values'),
    'rangeExact': OpenLayers.i18n('Create thematical map using ranges'),
    'addInput': OpenLayers.i18n('Add input field')
};

gbi.widgets = gbi.widgets || {};

gbi.widgets.ThematicalVectorConfigurator = function(thematicalVector, options) {
    if(!(thematicalVector instanceof gbi.widgets.ThematicalVector)) {
        return;
    }
    var self = this;
    var defaults = {
        element: 'thematicalvectorconfigurator',
        mode: 'exact',
        restrictSelectableAttributes: 10,
        initOnly: false
    }
    this.options = $.extend({}, defaults, options);
    this.thematicalVector = thematicalVector
    this.editor = thematicalVector.editor;
    this.activeLayer = this.editor.layerManager.active();
    this.attributes = [];
    this.mode = this.options.mode;

    $(gbi).on('gbi.layermanager.layer.active', function(event, layer) {
        self.activeLayer = layer;
        if(self.activeLayer) {
            self._registerLayerEvents(self.activeLayer);
            self.attributes = self.activeLayer.fullListAttributes() || [];
            if(self.attributes.length == 0) {
                self.attributes = self.activeLayer.featuresAttributes() || [];
            }
        } else {
            self.attributes = [];
        }
        self.render();
    });
    if(this.activeLayer) {
        this._registerLayerEvents(this.activeLayer);
        this.attributes = this.activeLayer.fullListAttributes() || [];
        if(this.attributes.length == 0) {
            this.attributes = this.activeLayer.featuresAttributes() || [];
        }
    } else {
        this.attributes = [];
    }

    if(!this.options.initOnly) {
        self.render();
    }
};
gbi.widgets.ThematicalVectorConfigurator.prototype = {
    CLASS_NAME: 'gbi.widgets.ThematicalVectorConfigurator',
    render: function() {
        var self = this;
        var element = $('#' + this.options.element);
        element.empty();

        if(!self.activeLayer) {
            element.append($('<div class="text-center">' + thematicalVectorConfiguratorLabel.noLayer + '</div>'));
            return;
        }

        element.append(tmpl(
            gbi.widgets.ThematicalVectorConfigurator.template, {
                attributes: self.attributes,
                defaultColors: gbi.widgets.ThematicalVectorConfigurator.defaultColors
            }
        ));

        $('#rangeInputDiv').hide();

        $('#toggleExact').click(function() {
            self.toggleExact();
        });

        $('#toggleRange').click(function() {
            self.toggleRange();
        });

        $('#attribute').change(function() {
            $.each($('.exactInputControl select'), function(idx, element) {
                element = $(element);
                self.fillExactInputSelect(element, element.val());
                self.execute();
            });
        });

        $('#addInput').click(function() {
            self.addInput(self.mode);
        });

        var shortListAttributes = self.activeLayer ? self.activeLayer.shortListAttributes() : [];
        var popupAttributes = self.activeLayer ? self.activeLayer.popupAttributes() : [];

        if(shortListAttributes) {
            element.find('.list-attribute').each(function(idx, elm) {
                elm = $(elm);
                elm.change(function() {
                    if(self._restrictAttributes(element, elm, '.list-attribute')) {
                        self.setListPopupAttributes(element);
                    }
                });
                if($.inArray(elm.val(), shortListAttributes) != -1) {
                    elm.attr('checked', 'checked');
                }

            })
        }

        if(popupAttributes) {
            element.find('.popup-attribute').each(function(idx, elm) {
                elm = $(elm);
                elm.change(function() {
                    if(self._restrictAttributes(element, elm, '.popup-attribute')) {
                        self.setListPopupAttributes(element);
                    }
                });
                if($.inArray(elm.val(), popupAttributes) != -1) {
                    elm.attr('checked', 'checked');
                }
            })
        }

        element.find('#sortable').sortable({
            stop: function() {
                self.setListPopupAttributes(element);
            }
        });

        if(this.activeLayer && this.activeLayer.featureStylingRule) {
            element.find('#attribute').val(this.activeLayer.featureStylingRule.attribute);
            this.mode = this.activeLayer.featureStylingRule.filterType;
            switch(this.mode) {
                case 'exact':
                    this.toggleExact();
                    $.each(this.activeLayer.featureStylingRule.filters, function(idx, filterOption) {
                        self.addInput('exact', filterOption);
                    });
                    this.addInput('range');
                    break;
                case 'range':
                    this.toggleRange()
                    $.each(this.activeLayer.featureStylingRule.filters, function(idx, filterOption) {
                        self.addInput('range', filterOption);
                    });
                    this.addInput('exact');
                    break;
            }

        } else {
            this.addInput('exact');
            this.addInput('range');
        }
    },
    toggleExact: function() {
        var self = this;
        $('#toggleRange').removeClass('active');
        $('#toggleExact').addClass('active')
        $('#rangeInputDiv').hide();
        $('#exactInputDiv').show();
        self.mode = "exact";
    },
    toggleRange: function() {
{'fraction_non_alphanumeric': 0.14382461774767855, 'fraction_numerical': 0.008657404175102981, 'mean_word_length': 2.1502089289641524, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '980854', 'n_tokens_mistral': 4161, 'n_tokens_neox': 3892, 'n_words': 580}