<commit_before>/* global $ */

import { Parser, HtmlRenderer } from 'commonmark'

const Util = {
  // helper function to determine how many lines are needed
  // Line Splitter Function
  // copyright <NAME>, 19th April 2006
  // you may copy this code but please keep the copyright notice as well
  splitLine: function (st, n) {
    var b = ''
    var s = st ? st : ''
    while (s.length > n) {
      var c = s.substring(0, n)
      var d = c.lastIndexOf(' ')
      var e = c.lastIndexOf('\n')
      if (e != -1) d = e
      if (d == -1) d = n
      b += c.substring(0, d) + '\n'
      s = s.substring(d + 1)
    }
    return b + s
  },

  nowDateFormatted: function (date = new Date(Date.now())) {
    const month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
    const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    const year = date.getFullYear()

    return month + '/' + day + '/' + year
  },

  decodeEntities: function (desc) {
    var str, temp = document.createElement('p')
    temp.innerHTML = desc // browser handles the topics
    str = temp.textContent || temp.innerText
    temp = null // delete the element
    return str
  }, // decodeEntities

  getDistance: function (p1, p2) {
    return Math.sqrt(Math.pow((p2.x - p1.x), 2) + Math.pow((p2.y - p1.y), 2))
  },

  // Try using Visualize.mGraph
  coordsToPixels: function (mGraph, coords) {
    if (mGraph) {
      var canvas = mGraph.canvas,
        s = canvas.getSize(),
        p = canvas.getPos(),
        ox = canvas.translateOffsetX,
        oy = canvas.translateOffsetY,
        sx = canvas.scaleOffsetX,
        sy = canvas.scaleOffsetY
      var pixels = {
        x: (coords.x / (1 / sx)) + p.x + s.width / 2 + ox,
        y: (coords.y / (1 / sy)) + p.y + s.height / 2 + oy
      }
      return pixels
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  },

  // Try using Visualize.mGraph
  pixelsToCoords: function (mGraph, pixels) {
    var coords
    if (mGraph) {
      var canvas = mGraph.canvas,
        s = canvas.getSize(),
        p = canvas.getPos(),
        ox = canvas.translateOffsetX,
        oy = canvas.translateOffsetY,
        sx = canvas.scaleOffsetX,
        sy = canvas.scaleOffsetY
      coords = {
        x: (pixels.x - p.x - s.width / 2 - ox) * (1 / sx),
        y: (pixels.y - p.y - s.height / 2 - oy) * (1 / sy),
      }
    } else {
      coords = {
        x: 0,
        y: 0
      }
    }
    return coords
  },
  getPastelColor: function (opts = {}) {
    const rseed = opts.rseed === undefined ? Math.random() : opts.rseed
    const gseed = opts.gseed === undefined ? Math.random() : opts.gseed
    const bseed = opts.bseed === undefined ? Math.random() : opts.bseed
    var r = (Math.round(rseed * 127) + 127).toString(16)
    var g = (Math.round(gseed * 127) + 127).toString(16)
    var b = (Math.round(bseed * 127) + 127).toString(16)
    return Util.colorLuminance('#' + r + g + b, -0.4)
  },
  // darkens a hex value by 'lum' percentage
  colorLuminance: function (hex, lum) {
    // validate hex string
    hex = String(hex).replace(/[^0-9a-f]/gi, '')
    if (hex.length < 6) {
      hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
    }
    lum = lum || 0

    // convert to decimal and change luminosity
    var rgb = '#', c, i
    for (i = 0; i < 3; i++) {
      c = parseInt(hex.substr(i * 2, 2), 16)
      c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16)
      rgb += ('00' + c).substr(c.length)
    }

    return rgb
  },
  openLink: function(url){
    var win = (url !== "") ? window.open(url, '_blank') : "empty";
    
    if (win) {
        //Browser has allowed it to be opened
        return true;
    } else {
        //Browser has blocked it
        alert('Please allow popups in order to open the link');
        return false;
    }
  },
  mdToHTML: text => {
    // use safe: true to filter xss
    return new HtmlRenderer({ safe: true })
      .render(new Parser().parse(text))
  },
  logCanvasAttributes: function(canvas){<commit_msg>topic descriptions from old data can be nil<commit_after>/* global $ */

import { Parser, HtmlRenderer } from 'commonmark'

const Util = {
  // helper function to determine how many lines are needed
  // Line Splitter Function
  // copyright <NAME>, 19th April 2006
  // you may copy this code but please keep the copyright notice as well
  splitLine: function (st, n) {
    var b = ''
    var s = st ? st : ''
    while (s.length > n) {
      var c = s.substring(0, n)
      var d = c.lastIndexOf(' ')
      var e = c.lastIndexOf('\n')
      if (e != -1) d = e
      if (d == -1) d = n
      b += c.substring(0, d) + '\n'
      s = s.substring(d + 1)
    }
    return b + s
  },

  nowDateFormatted: function (date = new Date(Date.now())) {
    const month = (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)
    const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    const year = date.getFullYear()

    return month + '/' + day + '/' + year
  },

  decodeEntities: function (desc) {
    var str, temp = document.createElement('p')
    temp.innerHTML = desc // browser handles the topics
    str = temp.textContent || temp.innerText
    temp = null // delete the element
    return str
  }, // decodeEntities

  getDistance: function (p1, p2) {
    return Math.sqrt(Math.pow((p2.x - p1.x), 2) + Math.pow((p2.y - p1.y), 2))
  },

  // Try using Visualize.mGraph
  coordsToPixels: function (mGraph, coords) {
    if (mGraph) {
      var canvas = mGraph.canvas,
        s = canvas.getSize(),
        p = canvas.getPos(),
        ox = canvas.translateOffsetX,
        oy = canvas.translateOffsetY,
        sx = canvas.scaleOffsetX,
        sy = canvas.scaleOffsetY
      var pixels = {
        x: (coords.x / (1 / sx)) + p.x + s.width / 2 + ox,
        y: (coords.y / (1 / sy)) + p.y + s.height / 2 + oy
      }
      return pixels
    } else {
      return {
        x: 0,
        y: 0
      }
    }
  },

  // Try using Visualize.mGraph
  pixelsToCoords: function (mGraph, pixels) {
    var coords
    if (mGraph) {
      var canvas = mGraph.canvas,
        s = canvas.getSize(),
        p = canvas.getPos(),
        ox = canvas.translateOffsetX,
        oy = canvas.translateOffsetY,
        sx = canvas.scaleOffsetX,
        sy = canvas.scaleOffsetY
      coords = {
        x: (pixels.x - p.x - s.width / 2 - ox) * (1 / sx),
        y: (pixels.y - p.y - s.height / 2 - oy) * (1 / sy),
      }
    } else {
      coords = {
        x: 0,
        y: 0
      }
    }
    return coords
  },
  getPastelColor: function (opts = {}) {
    const rseed = opts.rseed === undefined ? Math.random() : opts.rseed
    const gseed = opts.gseed === undefined ? Math.random() : opts.gseed
    const bseed = opts.bseed === undefined ? Math.random() : opts.bseed
    var r = (Math.round(rseed * 127) + 127).toString(16)
    var g = (Math.round(gseed * 127) + 127).toString(16)
    var b = (Math.round(bseed * 127) + 127).toString(16)
    return Util.colorLuminance('#' + r + g + b, -0.4)
  },
  // darkens a hex value by 'lum' percentage
  colorLuminance: function (hex, lum) {
    // validate hex string
    hex = String(hex).replace(/[^0-9a-f]/gi, '')
    if (hex.length < 6) {
      hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]
    }
    lum = lum || 0

    // convert to decimal and change luminosity
    var rgb = '#', c, i
    for (i = 0; i < 3; i++) {
      c = parseInt(hex.substr(i * 2, 2), 16)
      c = Math.round(Math.min(Math.max(0, c + (c * lum)), 255)).toString(16)
      rgb += ('00' + c).substr(c.length)
    }

    return rgb
  },
  openLink: function(url){
    var win = (url !== "") ? window.open(url, '_blank') : "empty";
    
    if (win) {
        //Browser has allowed it to be opened
        return true;
    } else {
        //Browser has blocked it
        alert('Please allow popups in order to open the link');
        return false;
    }
  },
  mdToHTML: text => {
    const safeText = text || ''
    // use safe: true to filter xss
    return new HtmlRenderer({ safe: true })
      .render(new Parser().parse(safeText))
  },
  logCanvasAttributes: function(canvas){
{'fraction_non_alphanumeric': 0.15625, 'fraction_numerical': 0.02188715953307393, 'mean_word_length': 2.0350553505535056, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '6513413', 'n_tokens_mistral': 2992, 'n_tokens_neox': 2851, 'n_words': 813}