<commit_before><!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!--  Copyright © 2015      <NAME> (<EMAIL>)            -->
<!--                        <NAME> (<EMAIL>)             -->
<!--                        <NAME> (<EMAIL>)               -->
<!--                                                                           -->
<!--  Licensed under the Apache License, Version 2.0 (the "License");          -->
<!--  you may not use this file except in compliance with the License.         -->
<!--  You may obtain a copy of the License at                                  -->
<!--              http://www.apache.org/licenses/LICENSE-2.0                   -->
<!--                                                                           -->
<!--  Unless required by applicable law or agreed to in writing, software      -->
<!--  distributed under the License is distributed on an "AS IS" BASIS,        -->
<!--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!--  See the License for the specific language governing permissions and      -->
<!--  limitations under the License.                                           -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

        <link rel="shortcut icon" href="{{ asset('favicon.ico') }}" />
        <title>{% if palette != null %}{{ palette.name }} :: {% endif %}Palette editor :: project O-GIS</title>
        
        <link rel="stylesheet" href="{{ asset('./css/ogis_styles.css') }}" />
        <link rel="stylesheet" href="{{ asset('./css/jstree-types.css') }}" />
        <link rel="stylesheet" href="{{ asset('./js/jquery/themes/default/style.css') }}" />
        <link rel="stylesheet" href="{{ asset('./js/jquery-ui/jquery-ui.css') }}" />
        <link rel="stylesheet" href="{{ asset('./js/colors/jquery.minicolors.css') }}" />
        
        <style>
            .ui-dialog{ z-index: 9999 !important; }
            .ui-front{ z-index: 9998 !important; }
        </style>
        
        <script type="text/javascript" src="{{ asset('./js/jquery/jquery-2.min.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/jquery/jstree.min.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/jquery-ui/jquery-ui.min.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/addtofavorites.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/colors/jquery.minicolors.min.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/paletteEditor.js') }}"></script>
        
        <script type="text/javascript">
            {% if palette != null %}
                var palette_colors = "{{ palette.colors }}";
                var keyValues = "{{ palette.keyValues }}";
                var new_palette = false;
                var palette = {     id: {{ palette.id }},
                                    name: "{{ palette.name }}",
                                    desc: "{{ palette.description }}",
                                    publ: {{ palette.public }}
                              };
            {% else %}
                var palette = null;
                var colors = null;
                var new_palette = true;
            {% endif %}
            var catalogData = "{{ path('loadcatalogdata', {'catid': 'PATH' }) }}";
            var rootFavNodes = "{{ path('loadusercatalogs', {'holderid': app.user.id}) }}";
            
            var keyColors = new Array();
            var cellBeingEdited = null;
            var paletteEditor = null;
            
            // Initialize the grid
            function initiateEditor(){
                paletteEditor = new PaletteEditor();
                paletteEditor.setGridCellOnclickFunction('beginEditCellColor');
                paletteEditor.generateGrid('palettebox', 'paletteelement');
                {% if palette != null %}
                    var r, g, b, a;
                    for(var i = 0; i < 2048; i += 8){
                        r = parseInt('0x' + palette_colors.substring(i, i + 2));
                        g = parseInt('0x' + palette_colors.substring(i + 2, i + 4));
                        b = parseInt('0x' + palette_colors.substring(i + 4, i + 6));
                        a = parseInt('0x' + palette_colors.substring(i + 6, i + 8)) / 255;
                        var rgba = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
                        var id = parseInt(i / 8);
                        paletteEditor.setGridCellColor(id, rgba);
                    }
                    var keyVals = keyValues.split(',');
                    for (var i = 0; i < keyVals.length; i++){
                        keyColors[parseInt(keyVals[i]) - 1] = 1;
                    }
                {% endif %}
            }
            
            // Load the color of a grid cell into the colorpicker
            function beginEditCellColor(cell_id){
                cellBeingEdited = cell_id;
                var color = paletteEditor.getGridCellColor(cell_id);
                var color_components = color.substring(5, color.length - 1).split(',');
                var hexColor = paletteEditor.convertToHex(color_components);
                $('#colorpicker').minicolors('value', hexColor);
                $('#colorpicker').minicolors('opacity', color_components[3]);
                $('#msgbox').empty().append('Editing cell #' + cell_id + '<br/>Current color: ' + hexColor);
            }
            
            // perform a gradient fill on the palette
            function doGradientFill(){
                var min = parseInt(document.getElementById('lowedgegr').value);
                var max = parseInt(document.getElementById('highedgegr').value);
                if (max < min){
                    var tmp = min;
                    min = max;
                    max = tmp;
                }
                if (min < 0){ min = 0; }
                if (max > 255){ max = 255; }
                paletteEditor.applyGradientFill(min, max);
            }
            
            // perform a flood fill on the palette
            function doFloodFill(){
                var min = parseInt(document.getElementById('lowedgecp').value);
                var max = parseInt(document.getElementById('highedgecp').value);
                var val = parseInt(document.getElementById('targetcp').value);
                if (max < min){
                    var tmp = min;
                    min = max;
                    max = tmp;
                }
                if (min < 0){ min = 0; }
                if (val < 0){ val = 0; }
                if (max > 255){ max = 255; }
                if (val > 255){ val = 255; }
                paletteEditor.applyFloodFill(min, max, val);
                var tmp;
                // move keyColors to the sides if possible
                if (min !== 0){
                    tmp = min - 1;
                    var minColor = paletteEditor.getGridCellColor(min);
                    var tmpColor = paletteEditor.getGridCellColor(tmp);
                    while (tmp > 0 && tmpColor === minColor){ tmp--; }
                    keyColors[min] = 0;
                    keyColors[tmp] = 1;
                }
                if (max !== 255){
                    tmp = max + 1;
                    var maxColor = paletteEditor.getGridCellColor(max);
                    var tmpColor = paletteEditor.getGridCellColor(tmp);
                    while (tmp < 255 && tmpColor === maxColor){ tmp++; }
                    keyColors[max] = 0;
                    keyColors[tmp] = 1;
                }
            }
            
            // clear the palette
            function clearPalette(){
                if(!confirm('Сбросить палитру?')){ return; }
                $('#msgbox').empty().append('Please choose a cell...<br/>&nbsp;');
                paletteEditor.resetPaletteEditorGrid();
                keyColors = new Array();
            }

            // start a new palette
            function newPalette(){
                if(!confirm('Begin editing new palette?')){ return; }
                window.location.href = "{{ path('paletteeditor', {'id': null}) }}";
            }
            
            // open a list of available palettes
            function loadPalette(){
                if ($('#loadpalettewindow').children().length === 0){
                    $('#loadpalettewindow').append('<iframe style="width:95%;height:95%;" src="{{ path('showpalettelist') }}" />');
                }
                $('#loadpalettewindow').dialog('open');
            }
            
            // saving the palette
            function savePalette(overwrite){
                // overwriting existing palette
                if (!new_palette && overwrite){
                    // we don't need to show this to the user
                    document.getElementById('palette_name').value = palette.name;
                    document.getElementById('palette_description').value = palette.desc;<commit_msg>Update editpalette.html.twig<commit_after><!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!--  Copyright © 2015      <NAME> (<EMAIL>)            -->
<!--                        <NAME> (<EMAIL>)             -->
<!--                        <NAME> (<EMAIL>)               -->
<!--                                                                           -->
<!--  Licensed under the Apache License, Version 2.0 (the "License");          -->
<!--  you may not use this file except in compliance with the License.         -->
<!--  You may obtain a copy of the License at                                  -->
<!--              http://www.apache.org/licenses/LICENSE-2.0                   -->
<!--                                                                           -->
<!--  Unless required by applicable law or agreed to in writing, software      -->
<!--  distributed under the License is distributed on an "AS IS" BASIS,        -->
<!--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!--  See the License for the specific language governing permissions and      -->
<!--  limitations under the License.                                           -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

        <link rel="shortcut icon" href="{{ asset('favicon.ico') }}" />
        <title>{% if palette != null %}{{ palette.name }} :: {% endif %}Palette editor :: project O-GIS</title>
        
        <link rel="stylesheet" href="{{ asset('./css/ogis_styles.css') }}" />
        <link rel="stylesheet" href="{{ asset('./css/jstree-types.css') }}" />
        <link rel="stylesheet" href="{{ asset('./js/jquery/themes/default/style.css') }}" />
        <link rel="stylesheet" href="{{ asset('./js/jquery-ui/jquery-ui.css') }}" />
        <link rel="stylesheet" href="{{ asset('./js/colors/jquery.minicolors.css') }}" />
        
        <style>
            .ui-dialog{ z-index: 9999 !important; }
            .ui-front{ z-index: 9998 !important; }
        </style>
        
        <script type="text/javascript" src="{{ asset('./js/jquery/jquery-2.min.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/jquery/jstree.min.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/jquery-ui/jquery-ui.min.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/addtofavorites.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/colors/jquery.minicolors.min.js') }}"></script>
        <script type="text/javascript" src="{{ asset('./js/paletteEditor.js') }}"></script>
        
        <script type="text/javascript">
            {% if palette != null %}
                var palette_colors = "{{ palette.colors }}";
                var keyValues = "{{ palette.keyValues }}";
                var new_palette = false;
                var palette = {     id: {{ palette.id }},
                                    name: "{{ palette.name }}",
                                    desc: "{{ palette.description }}",
                                    publ: {{ palette.public }}
                              };
            {% else %}
                var palette = null;
                var colors = null;
                var new_palette = true;
            {% endif %}
            var catalogData = "{{ path('loadcatalogdata', {'catid': 'PATH' }) }}";
            var rootFavNodes = "{{ path('loadusercatalogs', {'holderid': app.user.id}) }}";
            
            var keyColors = new Array();
            var cellBeingEdited = null;
            var paletteEditor = null;
            
            // Initialize the grid
            function initiateEditor(){
                paletteEditor = new PaletteEditor();
                paletteEditor.setGridCellOnclickFunction('beginEditCellColor');
                paletteEditor.generateGrid('palettebox', 'paletteelement');
                {% if palette != null %}
                    var r, g, b, a;
                    for(var i = 0; i < 2048; i += 8){
                        r = parseInt('0x' + palette_colors.substring(i, i + 2));
                        g = parseInt('0x' + palette_colors.substring(i + 2, i + 4));
                        b = parseInt('0x' + palette_colors.substring(i + 4, i + 6));
                        a = parseInt('0x' + palette_colors.substring(i + 6, i + 8)) / 255;
                        var rgba = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
                        var id = parseInt(i / 8);
                        paletteEditor.setGridCellColor(id, rgba);
                    }
                    var keyVals = keyValues.split(',');
                    for (var i = 0; i < keyVals.length; i++){
                        keyColors[parseInt(keyVals[i]) - 1] = 1;
                    }
                {% endif %}
            }
            
            // Load the color of a grid cell into the colorpicker
            function beginEditCellColor(cell_id){
                cellBeingEdited = cell_id;
                var color = paletteEditor.getGridCellColor(cell_id);
                var color_components = color.substring(5, color.length - 1).split(',');
                var hexColor = paletteEditor.convertToHex(color_components);
                $('#colorpicker').minicolors('value', hexColor);
                $('#colorpicker').minicolors('opacity', color_components[3]);
                $('#msgbox').empty().append('Editing cell #' + cell_id + '<br/>Current color: ' + hexColor);
            }
            
            // perform a gradient fill on the palette
            function doGradientFill(){
                var min = parseInt(document.getElementById('lowedgegr').value);
                var max = parseInt(document.getElementById('highedgegr').value);
                if (max < min){
                    var tmp = min;
                    min = max;
                    max = tmp;
                }
                if (min < 0){ min = 0; }
                if (max > 255){ max = 255; }
                paletteEditor.applyGradientFill(min, max);
            }
            
            // perform a flood fill on the palette
            function doFloodFill(){
                var min = parseInt(document.getElementById('lowedgecp').value);
                var max = parseInt(document.getElementById('highedgecp').value);
                var val = parseInt(document.getElementById('targetcp').value);
                if (max < min){
                    var tmp = min;
                    min = max;
                    max = tmp;
                }
                if (min < 0){ min = 0; }
                if (val < 0){ val = 0; }
                if (max > 255){ max = 255; }
                if (val > 255){ val = 255; }
                paletteEditor.applyFloodFill(min, max, val);
                var tmp;
                // move keyColors to the sides if possible
                if (min !== 0){
                    tmp = min - 1;
                    var minColor = paletteEditor.getGridCellColor(min);
                    var tmpColor = paletteEditor.getGridCellColor(tmp);
                    while (tmp > 0 && tmpColor === minColor){ tmp--; }
                    keyColors[min] = 0;
                    keyColors[tmp] = 1;
                }
                if (max !== 255){
                    tmp = max + 1;
                    var maxColor = paletteEditor.getGridCellColor(max);
                    var tmpColor = paletteEditor.getGridCellColor(tmp);
                    while (tmp < 255 && tmpColor === maxColor){ tmp++; }
                    keyColors[max] = 0;
                    keyColors[tmp] = 1;
                }
            }
            
            // clear the palette
            function clearPalette(){
                if(!confirm('Clear palette?')){ return; }
                $('#msgbox').empty().append('Please choose a cell...<br/>&nbsp;');
                paletteEditor.resetPaletteEditorGrid();
                keyColors = new Array();
            }

            // start a new palette
            function newPalette(){
                if(!confirm('Begin editing new palette?')){ return; }
                window.location.href = "{{ path('paletteeditor', {'id': null}) }}";
            }
            
            // open a list of available palettes
            function loadPalette(){
                if ($('#loadpalettewindow').children().length === 0){
                    $('#loadpalettewindow').append('<iframe style="width:95%;height:95%;" src="{{ path('showpalettelist') }}" />');
                }
                $('#loadpalettewindow').dialog('open');
            }
            
            // saving the palette
            function savePalette(overwrite){
                // overwriting existing palette
                if (!new_palette && overwrite){
                    // we don't need to show this to the user
                    document.getElementById('palette_name').value = palette.name;
                    document.getElementById('palette_description').value = palette.desc;
{'fraction_non_alphanumeric': 0.1493281317728652, 'fraction_numerical': 0.00953619419159081, 'mean_word_length': 1.297933266932271, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 115, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5562750', 'n_tokens_mistral': 4968, 'n_tokens_neox': 4543, 'n_words': 1098}