<commit_before>"use strict";

/*global module, require*/

var d3 = require("d3");

/*
 Wraps a d3 zoom behaviour with some custom additions.

 + modelSVG is the element which will receive the zoom events for the model.
 + modelG is a g element inside the modelSVG which will have a pan and zoom applied to it as a transform.
 
 
 */
module.exports = function(modelSVG, modelG, textControls) {
    var zoom = d3.behavior.zoom()
	    .on("zoom", function() {
		modelG.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
		textControls.update();
	    });

    zoom.scaleTranslate = function(scale, translate) {
	zoom.manual = true;

	zoom
	    .scale(scale)
	    .translate(translate)
	    .event(modelG.transition());
    };

    zoom.on("zoomend", function() {
	zoom.manual = false;
    });

    zoom.in = function() {
	zoom.scaleTranslate(zoom.scale() * 1.1);
    };
    zoom.out = function() {
	zoom.scaleTranslate(zoom.scale() / 1.1);
    };

    zoom.bbox = function(targetBBox) {
	var svgBBox = modelSVG.node().getBoundingClientRect(),
	    widthScale = svgBBox.width / targetBBox.width,
	    heightScale = svgBBox.height / targetBBox.height,
	    scale = Math.min(widthScale, heightScale),
	    scaledTargetCentre = [
		(targetBBox.left + targetBBox.right) * scale / 2,
		(targetBBox.top + targetBBox.bottom) * scale / 2
	    ];

	zoom.scaleTranslate(
	    scale,
	    [
		(svgBBox.width / 2) - scaledTargetCentre[0],
		(svgBBox.height / 2) - scaledTargetCentre[1]
	    ]
	);
    };

    zoom(modelSVG);
    modelSVG.on("dblclick.zoom", null);

    return zoom;
};
    





<commit_msg>Focusing on a bbox now uses a different mechanism, due to the following Firefox bug (now fixed, but only very recently) https://bugzilla.mozilla.org/show_bug.cgi?id=530985<commit_after>"use strict";

/*global module, require*/

var d3 = require("d3");

/*
 Wraps a d3 zoom behaviour with some custom additions.

 + modelSVG is the element which will receive the zoom events for the model.
 + modelG is a g element inside the modelSVG which will have a pan and zoom applied to it as a transform.
 
 
 */
module.exports = function(modelSVG, modelG, textControls) {
    var zoom = d3.behavior.zoom()
	    .on("zoom", function() {
		modelG.attr("transform", "translate(" + d3.event.translate + ")scale(" + d3.event.scale + ")");
		textControls.update();
	    });

    zoom.scaleTranslate = function(scale, translate) {
	zoom.manual = true;

	zoom
	    .scale(scale)
	    .translate(translate)
	    .event(modelG.transition());
    };

    zoom.on("zoomend", function() {
	zoom.manual = false;
    });

    zoom.in = function() {
	zoom.scaleTranslate(zoom.scale() * 1.1);
    };
    zoom.out = function() {
	zoom.scaleTranslate(zoom.scale() / 1.1);
    };

    zoom.bbox = function(targetBBox) {
	var svgStyles = window.getComputedStyle(modelSVG.node()),
	    svgSize = {
		width: parseInt(svgStyles.width),
		height: parseInt(svgStyles.height)
	    },

	    widthScale = svgSize.width / targetBBox.width,
	    heightScale = svgSize.height / targetBBox.height,
	    scale = Math.min(widthScale, heightScale),
	    scaledTargetCentre = [
		(targetBBox.left + targetBBox.right) * scale / 2,
		(targetBBox.top + targetBBox.bottom) * scale / 2
	    ];

	zoom.scaleTranslate(
	    scale,
	    [
		(svgSize.width / 2) - scaledTargetCentre[0],
		(svgSize.height / 2) - scaledTargetCentre[1]
	    ]
	);
    };

    zoom(modelSVG);
    modelSVG.on("dblclick.zoom", null);

    return zoom;
};
    






{'fraction_non_alphanumeric': 0.1404206935758954, 'fraction_numerical': 0.010801591813530414, 'mean_word_length': 3.040183696900115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '3585878', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1166, 'n_words': 272}