<commit_before>/*
 designer.js -  Licence: GNU GPL Affero, Author: <NAME> / Chaveiro

 The dashboard designer works around the concept of html elements with fixed positions
 and specified widths and heights. Its a box model where each box can hold a widget.
 A box specifies which widget it is by its class. The properties of a widget such as
 the feedid to use is also specified in the html element:

 <div class="dial" feedid="1" style="position:absolute; top:50px; left:50px; width:200px; height:100px;" ></div>

 render.js and associated widget render scripts then inserts the dial javascript into the element specified in the designer.
 The dashboard designer creates a canvas layer above the dashboard html elements layer and uses jquery to get the mouse positions and actions that specify the box position and dimentions.
 The functions: draw_options(box_options, options_type) and widget_buttons() draw the menu and widget options interface.
*/

var selected_edges = {none : 0, left : 1, right : 2, top : 3, bottom : 4, center : 5};

var designer = {

    'grid_size':20,
    'page_width':500,
    'page_height':500,

    'cnvs':null,
    'canvas':null,
    'designer.ctx':null,
    'widgets':null,

    'boxlist': {},
    'resize': {},

    'selected_box': null,
    'selected_edge': selected_edges.none,
    'edit_mode': true,
    'create': null,

    'boxi': 0,

    'mousedown': false,

    'init': function(){
        designer.cnvs = document.getElementById("can");
        designer.ctx = designer.cnvs.getContext("2d");

        $("#when-selected").hide();
        designer.scan();
        designer.draw();
        designer.widget_buttons();
        designer.add_events();
    },


    'snap': function(pos) {return Math.round(pos/designer.grid_size)*designer.grid_size;},

    'modified': function(){
        $("#save-dashboard").attr('class','btn btn-warning').text(_Tr("Changed, press to save"));
    },

    'onbox': function(x,y){
        var box = null;
        for (z in designer.boxlist) {
        if (x>designer.boxlist[z]['left']-4 && x<(designer.boxlist[z]['left']+designer.boxlist[z]['width']+4)) {
            if (y>designer.boxlist[z]['top']-4 && y<(designer.boxlist[z]['top']+designer.boxlist[z]['height']+4)) {
            box = z;
            }
        }
        }
        return box;
    },<commit_msg>Treat a zero grid size as no snapping<commit_after>/*
 designer.js -  Licence: GNU GPL Affero, Author: <NAME> / Chaveiro

 The dashboard designer works around the concept of html elements with fixed positions
 and specified widths and heights. Its a box model where each box can hold a widget.
 A box specifies which widget it is by its class. The properties of a widget such as
 the feedid to use is also specified in the html element:

 <div class="dial" feedid="1" style="position:absolute; top:50px; left:50px; width:200px; height:100px;" ></div>

 render.js and associated widget render scripts then inserts the dial javascript into the element specified in the designer.
 The dashboard designer creates a canvas layer above the dashboard html elements layer and uses jquery to get the mouse positions and actions that specify the box position and dimentions.
 The functions: draw_options(box_options, options_type) and widget_buttons() draw the menu and widget options interface.
*/

var selected_edges = {none : 0, left : 1, right : 2, top : 3, bottom : 4, center : 5};

var designer = {

    'grid_size':20,
    'page_width':500,
    'page_height':500,

    'cnvs':null,
    'canvas':null,
    'designer.ctx':null,
    'widgets':null,

    'boxlist': {},
    'resize': {},

    'selected_box': null,
    'selected_edge': selected_edges.none,
    'edit_mode': true,
    'create': null,

    'boxi': 0,

    'mousedown': false,

    'init': function(){
        designer.cnvs = document.getElementById("can");
        designer.ctx = designer.cnvs.getContext("2d");

        $("#when-selected").hide();
        designer.scan();
        designer.draw();
        designer.widget_buttons();
        designer.add_events();
    },


    'snap': function(pos) {
        if (designer.grid_size > 0) {
            return Math.round(pos/designer.grid_size)*designer.grid_size;
        } else {
            return Math.round(pos);
        }
    },

    'modified': function(){
        $("#save-dashboard").attr('class','btn btn-warning').text(_Tr("Changed, press to save"));
    },

    'onbox': function(x,y){
        var box = null;
        for (z in designer.boxlist) {
        if (x>designer.boxlist[z]['left']-4 && x<(designer.boxlist[z]['left']+designer.boxlist[z]['width']+4)) {
            if (y>designer.boxlist[z]['top']-4 && y<(designer.boxlist[z]['top']+designer.boxlist[z]['height']+4)) {
            box = z;
            }
        }
        }
        return box;
    },
{'fraction_non_alphanumeric': 0.13718561629598836, 'fraction_numerical': 0.013094990646435253, 'mean_word_length': 3.1093082835183603, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, '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': '3264646', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1431, 'n_words': 441}