<commit_before>var phylocanvas;

HTMLWidgets.widget({

  name: 'radial_phylo',

  type: 'output',

  initialize: function(el, width, height) {

    return {
        width: el.offsetWidth,
        height: el.offsetHeight
    }

  },

  renderValue: function(el, x, instance) {
    
    // function to add css to <head>
    var addCSS = function(css) {
        var head = document.head || document.getElementsByTagName('head')[0];
        var style = document.createElement('style');
        style.type = "text/css";
        if (style.styleSheet) {
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }
        head.appendChild(style);
    };
                   
    // if 'canvas_size' is a number (auto-calcuated or user-input) then use it
    var width;
    var height;
    if (typeof(x.canvas_size === 'number') && x.canvas_size%1 === 0) {
        width = x.canvas_size;
        height = x.canvas_size;
    } else {
        // get width and height of current window
        width = Math.max(instance.width, instance.height);
        height = Math.max(instance.width, instance.height);
    }

    // if user provides large canvas_size give the svg that width and height
    if (x.scale === true) {
        addCSS("svg { width: 100%; height: 100%; }");
    } else {
        addCSS("svg { height: " + width + "px; width: " + height + "px; }");
        addCSS("body { overflow: scroll !important; }");
    }

    // set some options of the phylogram
    Smits.PhyloCanvas.Render.Parameters.Circular.bufferRadius = 0.28;
    Smits.PhyloCanvas.Render.Parameters.Circular.bufferOuterLabels = 0;

    // get xml file's contents and plot the phylogram
    var xml_relpath = HTMLWidgets.getAttachmentUrl('phyloxml', 'xml');
    $.get(xml_relpath, function(xmldata) {

        var dataObject = {
            phyloxml: xmldata,
            fileSource: true
        };

        phylocanvas = new Smits.PhyloCanvas(
            dataObject,
            el.id,
            width, height,
            'circular',
            x.scale  // holds true or false
        );

    });

	// Create 'Save Image' text link
	var a = document.createElement('a');
	a.href = "#";
	a.title = "Save as PNG";
	a.id = "download_link";
	var widget = document.body.children[0];
	document.body.insertBefore(a, widget);  // Insert the link
	var download_image = new Image();
	var img_gray = HTMLWidgets.getAttachmentUrl('images', 'download_sheet_gray');
	var img_blue = HTMLWidgets.getAttachmentUrl('images', 'download_sheet_blue');
	$(download_image).attr("src", img_gray);
	a.appendChild(download_image);  // Insert the image inside the link
	$(download_image)
	  .mouseover(function() {
	    $(this).attr("src", img_blue);
	  })
	  .mouseout(function() {
	    $(this).attr("src", img_gray);
	  })
	  .mousedown(function() {
	    var current_pos = parseInt($(this).css("top"));
	    $(this).css("padding-top", 1 + "px");
	  })
	  .bind("mouseup mouseleave", function() {
	    $(this).css("padding-top", 0 + "px");
  });<commit_msg>Change DL radial phylo tooltip and hover if viewing in RStudio   - RStudio's Viewer won't let the user download the image, so     change the tooltip to tell the user to open the widget in     a browser window to download the PNG.   - Hover and click effects are removed if viewing the widget     in RStudio.<commit_after>var phylocanvas;

HTMLWidgets.widget({

  name: 'radial_phylo',

  type: 'output',

  initialize: function(el, width, height) {

    return {
        width: el.offsetWidth,
        height: el.offsetHeight
    }

  },

  renderValue: function(el, x, instance) {
    
    // function to add css to <head>
    var addCSS = function(css) {
        var head = document.head || document.getElementsByTagName('head')[0];
        var style = document.createElement('style');
        style.type = "text/css";
        if (style.styleSheet) {
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }
        head.appendChild(style);
    };
                   
    // if 'canvas_size' is a number (auto-calcuated or user-input) then use it
    var width;
    var height;
    if (typeof(x.canvas_size === 'number') && x.canvas_size%1 === 0) {
        width = x.canvas_size;
        height = x.canvas_size;
    } else {
        // get width and height of current window
        width = Math.max(instance.width, instance.height);
        height = Math.max(instance.width, instance.height);
    }

    // if user provides large canvas_size give the svg that width and height
    if (x.scale === true) {
        addCSS("svg { width: 100%; height: 100%; }");
    } else {
        addCSS("svg { height: " + width + "px; width: " + height + "px; }");
        addCSS("body { overflow: scroll !important; }");
    }

    // set some options of the phylogram
    Smits.PhyloCanvas.Render.Parameters.Circular.bufferRadius = 0.28;
    Smits.PhyloCanvas.Render.Parameters.Circular.bufferOuterLabels = 0;

    // get xml file's contents and plot the phylogram
    var xml_relpath = HTMLWidgets.getAttachmentUrl('phyloxml', 'xml');
    $.get(xml_relpath, function(xmldata) {

        var dataObject = {
            phyloxml: xmldata,
            fileSource: true
        };

        phylocanvas = new Smits.PhyloCanvas(
            dataObject,
            el.id,
            width, height,
            'circular',
            x.scale  // holds true or false
        );

    });

  // Create DL image as PNG link
	var a = document.createElement('a');
	a.href = "#";
	a.id = "download_link";
	var widget = document.body.children[0];
	var img_gray = HTMLWidgets.getAttachmentUrl('images', 'download_sheet_gray');
	var download_image = new Image();
	$(download_image).attr("src", img_gray);
  if (this.queryVar("viewer_pane") === "1") {
    // If widgets shown in RStudio, DL as PNG link tells user to open in browser
  	a.title = "Must view in browser to save as PNG";
  } else {
  	// Otherwise create the button hover effects
  	a.title = "Save as PNG";
  	var img_blue = HTMLWidgets.getAttachmentUrl('images',
  	                                            'download_sheet_blue');
  	$(download_image)
  	  .mouseover(function() {
  	    $(this).attr("src", img_blue);
  	  })
  	  .mouseout(function() {
  	    $(this).attr("src", img_gray);
  	  })
  	  .mousedown(function() {
  	    var current_pos = parseInt($(this).css("top"));
  	    $(this).css("padding-top", 1 + "px");
  	  })
  	  .bind("mouseup mouseleave", function() {
  	    $(this).css("padding-top", 0 + "px");
    });
  }
	a.appendChild(download_image);  // Insert the image inside the link
	document.body.insertBefore(a, widget);  // Insert the link
{'fraction_non_alphanumeric': 0.13505917159763314, 'fraction_numerical': 0.004881656804733727, 'mean_word_length': 2.454777721001533, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6865684', 'n_tokens_mistral': 2171, 'n_tokens_neox': 2081, 'n_words': 530}