<commit_before>"use strict";
/**
 * Since only a single constructor is being exported as module.exports this comment isn't documented.
 * The class and module are the same thing, the contructor comment takes precedence.
 * @module DrawnItemContext
 */
 
var paper = require('browserifyable-paper');

/**
 * A generic context that draws items from the provided dataSource using the provided factory
 * Can do paths, vectors, badges and more without needing to impliment a new context
 * @implements {Context}
 * @constructor
 * @param {module:DataSource} dataSource - The source of item DTOs to draw
 * @param {DrawnItemFactory} drawnItemFactory - The factory which produces the paper.js representation of the dataSource items
 * @param {external:cartesian-hexagonal} hexDimensions - The DTO defining the hex <--> cartesian relation
 */
module.exports = function DrawnItemContext(dataSource, drawnItemFactory, hexDimensions) {
    //Protect the constructor from being called as a normal method
    if (!(this instanceof DrawnItemContext)) {
        return new DrawnItemContext(dataSource, drawnItemFactory, hexDimensions);
    }
    var context = this;
    this.dataSource = dataSource;
    this.drawnItemFactory = drawnItemFactory;
    this.hexDimensions = hexDimensions;
    this.dx = 0;
    this.dy = 0;
    this.drawnItemCache = {};

    //Add this as a listener to the dataSource. this.onDataChanged will be called when items change.
    dataSource.addListener(this);
    
    // Documentation inherited from Context#init
    this.init = function(group) {
        context.group = group;
    };

    // Documentation inherited from Context#mouseDown
    this.mouseDown = function(clickedX, clickedY) {
        //Hit test for items
        var result = context.group.hitTest(new paper.Point(clickedX, clickedY));
        if (result) {
            context.clickedItem = result.item.parent;
            return true;
            //Check if the clickedItem is one the layer claims further mouse events for
        }
        return;
        
    };

    /**
     * Method called to update the position of the global view, either through drags or programmatic manpulation
     */
    this.updatePosition = function( dx, dy) {
        context.group.position.x = dx;
        context.group.position.y = dy;
        context.dx = dx;
        context.dy = dy;
    };

    // Documentation inherited from Context#mouseDragged
    this.mouseDragged = function( x, y, eventDx, eventDy) {
        context.clickedItem.data.onDrag( x, y, eventDx, eventDy, context.dx, context.dy);
    };
};


/**
 * Called when objects are added to datasource, removed from datasource, re-ordered in datasource,
 */<commit_msg>Fixed issue introduced during generalization refactor. Only claim mouse interactivity if the clicked item has a onDrag or onClick method<commit_after>"use strict";
/**
 * Since only a single constructor is being exported as module.exports this comment isn't documented.
 * The class and module are the same thing, the contructor comment takes precedence.
 * @module DrawnItemContext
 */
 
var paper = require('browserifyable-paper');

/**
 * A generic context that draws items from the provided dataSource using the provided factory
 * Can do paths, vectors, badges and more without needing to impliment a new context
 * @implements {Context}
 * @constructor
 * @param {module:DataSource} dataSource - The source of item DTOs to draw
 * @param {DrawnItemFactory} drawnItemFactory - The factory which produces the paper.js representation of the dataSource items
 * @param {external:cartesian-hexagonal} hexDimensions - The DTO defining the hex <--> cartesian relation
 */
module.exports = function DrawnItemContext(dataSource, drawnItemFactory, hexDimensions) {
    //Protect the constructor from being called as a normal method
    if (!(this instanceof DrawnItemContext)) {
        return new DrawnItemContext(dataSource, drawnItemFactory, hexDimensions);
    }
    var context = this;
    this.dataSource = dataSource;
    this.drawnItemFactory = drawnItemFactory;
    this.hexDimensions = hexDimensions;
    this.dx = 0;
    this.dy = 0;
    this.drawnItemCache = {};

    //Add this as a listener to the dataSource. this.onDataChanged will be called when items change.
    dataSource.addListener(this);
    
    // Documentation inherited from Context#init
    this.init = function(group) {
        context.group = group;
    };

    // Documentation inherited from Context#mouseDown
    this.mouseDown = function(clickedX, clickedY) {
        //Hit test for items
        var result = context.group.hitTest(new paper.Point(clickedX, clickedY));
        if (result) {
            context.clickedItem = result.item.parent;
            if (context.clickedItem.data.hasOwnProperty('onDrag') || context.clickedItem.data.hasOwnProperty('onClick')) {
                return true;
            }
        }
        return;
        
    };

    /**
     * Method called to update the position of the global view, either through drags or programmatic manpulation
     */
    this.updatePosition = function( dx, dy) {
        context.group.position.x = dx;
        context.group.position.y = dy;
        context.dx = dx;
        context.dy = dy;
    };

    // Documentation inherited from Context#mouseDragged
    this.mouseDragged = function( x, y, eventDx, eventDy) {
        if(context.clickedItem.data.hasOwnProperty('onDrag')) {
            context.clickedItem.data.onDrag( x, y, eventDx, eventDy, context.dx, context.dy);
        }
    };
};


/**
 * Called when objects are added to datasource, removed from datasource, re-ordered in datasource,
 */
{'fraction_non_alphanumeric': 0.0885896527285613, 'fraction_numerical': 0.0007087172218284905, 'mean_word_length': 3.0905797101449277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7227200', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1500, 'n_words': 520}