Source file resource_strings.ml
1
2
let flux_js = "\"use strict\"\n\nfunction fluxMap(configuration) {\n var that = this;\n this.configuration = configuration;\n this.selfInfluence = false;\n this.flux = { \"din_start\" : 0.0, \"din_end\" : 0.0,\n\t\t \"din_kind\" : \"ABSOLUTE\",\n\t\t \"din_rules\" : [],\n\t\t \"din_hits\" : [],\n\t\t \"din_fluxs\" : [] };\n\n this.setFlux = function(flux){\n\tif(!is_same(that.flux.din_rules,flux.din_rules)){\n\t that.selectedRules = flux.din_rules.map(function (v,i) {return (i !== 0);});\n\t that.flux = flux;\n that.render_controls();\n\t} else {\n\t that.flux = flux;\n\t}\n that.render();\n };\n\n this.aClick = function(id) {\n that.selectedRules[id] = (that.selectedRules[id]) ? false : true;\n that.drawDIM();\n };\n this.toggleSelfInfluence = function() {\n that.selfInfluence = (that.selfInfluence) ? false : true;\n that.drawDIM();\n };\n\n this.toggleSelectedRules = function() {\n\tthat.selectedRules.forEach(function (b,i,a) {a[i] = (b) ? false : true; });\n\tthat.render_controls();\n\tthat.drawDIM();\n };\n\n this.filterRules = function(val,id) {\n return that.selectedRules[id];\n };\n\n this.pointValue = function(i,j,e) {\n var correction = document.getElementById(that.configuration.selectCorrectionId).value;\n if (that.selfInfluence || i !== j)\n { if (correction === \"hits\")\n {return (that.flux.din_hits[i] === 0.) ? 0 : Math.abs(e) / that.flux.din_hits[i];}\n else if (correction === \"time\")\n {return Math.abs(e) / (that.flux.din_end - that.flux.din_start);}\n else {return Math.abs(e);}\n }\n else {return 0;}\n };\n\n this.fade = function fade(svg,opacity)\n { return function(g, i) { svg\n .selectAll(\".chord path\")\n .filter(function(d) { return d.source.index != i && d.target.index != i; })\n .transition().style(\"opacity\", opacity); }; };\n\n var svg = (that.configuration.svgId)?d3.select(\"#\"+that.configuration.svgId):d3.select(\"body\").select(\"#flux_container\").append(\"svg\");\n this.drawDIM = function(){\n var matrix = that.flux.din_fluxs\n .map(function(a,i){return a.map(function (e,j)\n {return that.pointValue (i,j,e)})\n .filter(that.filterRules);}).filter(that.filterRules),\n rules = that.flux.din_rules.filter(that.filterRules),\n color = that.flux.din_fluxs.map(function(a)\n {return a.map(function (x) {return (x < 0) ? \"#FF0000\" : \"#00FF00\";})\n .filter(that.filterRules);}).filter(that.filterRules);\n\tvar width = configuration.width?configuration.width:960,\n height = configuration.height?configuration.height:700,\n innerRadius = Math.min(width, height) * .37,\n\t outerRadius = innerRadius + 8;\n svg.attr(\"width\", width)\n .attr(\"height\", height)\n\t .select(\"g\")\n\t .attr(\"transform\", \"translate(\" + width / 2 + \",\" + height / 2 + \")\");\n svg.selectAll(\"*\").remove();\n\n\n\tvar formatValue = d3.formatPrefix(\",.0\", 1e3);\n\n\tvar chord = d3.chord()\n\t .padAngle(0.05)\n\t .sortSubgroups(d3.descending);\n\n\tvar arc = d3.arc()\n\t .innerRadius(innerRadius)\n\t .outerRadius(outerRadius);\n\n\tvar ribbon = d3.ribbon()\n\t .radius(innerRadius);\n\n\tvar color = d3.scaleOrdinal()\n\t .domain(d3.range(matrix.length))\n\t .range([\"#FF0000\" , \"#00FF00\"]);\n\n\tvar g = svg.append(\"g\")\n\t .attr(\"transform\", \"translate(\" + width / 2 + \",\" + height / 2 + \")\")\n\t .datum(chord(matrix));\n\tvar group = g.append(\"g\")\n\t .attr(\"class\", \"groups\")\n\t .selectAll(\"g\")\n\t .data(function(chords) { return chords.groups; })\n\t .enter().append(\"g\");\n\n\tgroup.append(\"path\")\n\t .style(\"fill\", function(d) { return d3.rgb(\"#000000\"); })\n\t .style(\"stroke\", function(){ return d3.rgb(\"#000000\"); } )\n\t .attr(\"d\", arc);\n\n var legends = group.append(\"g\");\n legends.append(\"text\")\n\t .each(function(d) { d.angle = (d.startAngle + d.endAngle) / 2; })\n .attr(\"dy\", \".1em\")\n\t .attr(\"transform\", function(d) {\n return \"rotate(\" + (d.angle * 180 / Math.PI - 90) + \")\"\n\t\t + \"translate(\" + (innerRadius + 10) + \")\"\n\t\t + (d.angle > Math.PI ? \"rotate(180)\" : \"\"); })\n\t .style(\"text-anchor\", function(d) { return d.angle > Math.PI ? \"end\" : null; })\n\t .text(function(d) { return rules[d.index]; });\n legends.append(\"path\").style(\"fill\", \"#222222\").attr(\"d\", arc)\n .on(\"mouseover\", that.fade(svg,.1)).on(\"mouseout\", that.fade(svg,1));\n\n\tvar ribbon = g.append(\"g\")\n\t .attr(\"class\", \"ribbons\")\n\t .selectAll(\"path\")\n\t .data(function(chords) { return chords; })\n\t .enter().append(\"path\")\n\t .attr(\"d\", ribbon)\n\t .style(\"fill\", function(d) { return color(d.target.index); })\n\t .style(\"stroke\", function(d) { return d3.rgb(color(d.target.index)).darker(); });\n\n\n\tribbon.data(function(chords){ return chords; })\n\t .enter()\n \t .append(\"text\")\n\t .each(function(d) { d.labelAngle = ( d.source.startAngle + d.source.endAngle) / 2; })\n .attr(\"dy\", \".1em\")\n .attr(\"transform\", function(d) {\n return \"rotate(\" + (d.angle * 180 / Math.PI - 90) + \")\"\n + \"translate(\" + (innerRadius - 10) + \")\"\n + (d.labelAngle > Math.PI ? \"rotate(180)\" : \"\"); })\n .style(\"text-anchor\", function(d) { return d.labelAngle > Math.PI ? null : \"end\" ; })\n .text(function (d) { return d.source.value.toExponential(2);});\n\n };\n\n this.render_other = function(){\n that.drawDIM();\n };\n this.render_controls = function(){\n var rulesCheckboxes = document.getElementById(that.configuration.rulesCheckboxesId);\n\n while (rulesCheckboxes.hasChildNodes()){\n rulesCheckboxes.removeChild(rulesCheckboxes.lastChild);\n };\n var correction_select =\n\t document.getElementById(that.configuration.selectCorrectionId);\n\tcorrection_select.value = \"none\";\n\tif (that.flux.din_kind !== \"ABSOLUTE\")\n\t correction_select.style.visibility=\"hidden\";\n\telse\n\t correction_select.style.visibility=\"visible\";\n that.selectedRules.forEach(function (val,id,a) {\n var group = document.createElement(\"div\")\n group.setAttribute(\"class\",\"input-group\");\n var boxbox = document.createElement(\"label\"),\n box = document.createElement(\"input\");\n boxbox.setAttribute(\"class\",\"checkbox-inline\")\n box.setAttribute(\"type\", \"checkbox\");\n if (val) {box.setAttribute(\"checked\",\"\")};\n box.addEventListener(\"change\",function () { that.aClick(id);});\n boxbox.appendChild(box);\n boxbox.appendChild(document.createTextNode(\n\t\tthat.flux.din_rules[id].concat(\" (\",that.flux.din_hits[id],\" occurences)\")));\n group.appendChild(boxbox);\n rulesCheckboxes.appendChild(group);\n });\n };\n\n this.render_labels = function(){\n d3.select(\"#\"+that.configuration.beginTimeId).text(that.flux.din_start);\n d3.select(\"#\"+that.configuration.endTimeId).text(that.flux.din_end);\n d3.select(\"#\"+that.configuration.nbEventsId).text(that.flux.din_hits.reduce(function (acc,v) {return acc + v;},0));\n\n };\n this.add_handlers = function(){\n d3.select(\"#\"+that.configuration.selectCorrectionId).on(\"change\",function() { that.drawDIM()});\n d3.select(\"#\"+that.configuration.checkboxSelfInfluenceId).on(\"click\",function() { that.toggleSelfInfluence()});\n\td3.select(\"#\"+that.configuration.toggleRulesId).on(\"click\",function() { that.toggleSelectedRules()});\n };\n\n this.exportJSON = function(filename){\n\ttry { var json = JSON.stringify(that.flux);\n\t saveFile(json,\"application/json\",filename);\n\t} catch (e) {\n\t alert(e);\n\t}\n }\n\n this.render = function() {\n that.render_labels();\n that.render_other();\n };\n that.add_handlers();\n\n}\n";;
let common_js = "\"use strict\";\n// http://stackoverflow.com/questions/326596/how-do-i-wrap-a-function-in-javascript\nvar wrap = function(fn){\n return function(){\n try { return fn.apply(this, arguments);\n } catch(ex){\n console.error(ex.stack);\n throw ex;\n }\n };\n};\n\nvar assert = function(condition, message) {\n if (!condition) {\n message = message || \"Assertion failed\";\n if (typeof Error !== \"undefined\") {\n throw new Error(message);\n }\n throw message; // Fallback\n }\n}\n\n// http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-url-parameter\nvar args = function () {\n var query_string = {};\n var query = window.location.search.substring(1);\n var vars = query.split(\"&\");\n for (var i=0;i<vars.length;i++) {\n var pair = vars[i].split(\"=\");\n if (typeof query_string[pair[0]] === \"undefined\") {\n query_string[pair[0]] = decodeURIComponent(pair[1]);\n } else if (typeof query_string[pair[0]] === \"string\") {\n var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];\n query_string[pair[0]] = arr;\n } else {\n query_string[pair[0]].push(decodeURIComponent(pair[1]));\n }\n }\n return query_string;\n}();\n\n// add logging functions\n// in the url place level=debug for most verbose\n(function(){\n var found = false;\n window.level = {};\n\n var levels = [\"debug\",\"info\",\"log\",\"warn\",\"error\"];\n for (var i in levels){\n var level = levels[i];\n // allow other modules to access levels via window.level[level]\n window.level[level] = level;\n if(args.level && args.level === level) { found = true; }\n if(found) {\n // returning the function in a bind.call allows to keep the line info\n window[level] = function(){\n return Function.prototype.bind.call(console[level], console);\n }();\n } else {\n window[level] = function(x){ }\n }\n }\n\n window.log_group = function(x){console.group(x)};\n window.log_group_end = function(){console.groupEnd()};\n})();\n\nvar modal_next_id = 1;\n\n// Duplicated in ocaml in ui_common.ml. TODO: merge the logic?\nfunction modalError(error_str) {\n const modal_id = 'modal_error_id-' + modal_next_id.toString();\n modal_next_id += 1;\n\n const h = '<div class=\"modal fade in\" id=\"' + modal_id \n + '\" tabindex=\"-1\" role=\"dialog\" data-backdrop=\"static\" style=\"display: block;\"><div class=\"modal-dialog\" role=\"document\"><form class=\"modal-content\"><div class=\"modal-header\"><button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\"><span aria-hidden=\"true\">\195\151</span></button><h4>Critical error.</h4></div><div class=\"modal-body\">The Kappa app has encountered a critical error:<pre><code>'\n + error_str\n + '</code></pre>The app will not behave properly after this, please save your files to avoid data loss and reload the app. Consider <a href=\"https://github.com/Kappa-Dev/KappaTools/issues\">opening an issue</a>.</div><div class=\"modal-footer\"><button type=\"button\" class=\"btn btn-danger\" data-dismiss=\"modal\">Return to app</button></div></form></div></div>';\n\n document.body.insertAdjacentHTML( 'afterbegin', h );\n $('#' +modal_id).modal()\n}\n\n\n\n// https://medium.com/@graeme_boy/how-to-optimize-cpu-intensive-work-in-node-js-cdc09099ed41#.2vhd0cp4g\n// http://www.codingdefined.com/2014/08/difference-between-fork-spawn-and-exec.html\n// param {command,args,onStdout,onStderr,onClose}\nvar stdsimProcesses = [];\n\nfunction spawnProcess(param){\n const spawn = require('child_process').spawn;\n const process = spawn(param.command, param.args);\n\n process.on('spawn', () => {debug(\"[Process] SPAWNED\", param.command)});\n process.on('exit', (code) => {\n var error_str = \"[Process] EXIT \" + param.command + \" code: \" + code + ' ' + process.stderr.read();\n error(error_str);\n modalError(error_str);\n });\n process.on('error', (error) => {\n var error_str = \"[Process] ERROR \" + param.command + \" error: \" + error + ' ' + process.stderr.read();\n error(error_str);\n });\n process.on('close', (code) => {error(\"[Process] CLOSE\", param.command, \"code:\", code)});\n process.on('message', () => {debug(\"[Process] MESSAGE\", param.command)});\n\n function spawnFailure(param,message){\n if(param.onError){\n // pid is logged here\n console.error(message);\n modalError(message);\n param.onError();\n }\n return null;\n }\n\n try {\n\tprocess.stdout.setEncoding('utf8');\n\tconsole.debug(`spawned process ${param.command} ${param.args} pid ${process.pid}`);\n\tif(param.onStdout) {\n\t process.stdout.on('data',\n\t\t\t function (data) {\n\t\t\t\t console.debug(`received stdout from process with command ${param.command} pid ${process.pid}:`, data);\n\t\t\t\t param.onStdout(data); } );\n\t}\n\tif(param.onStderr) {\n\t process.stderr.on('data',function (data) {\n\t\t\t\tconsole.error(`received stderr from process with command ${param.command} pid ${process.pid}:`, data);\n\t\tparam.onStderr(`${data}`);\n\t } );\n\t}\n\tif(param.onClose){\n\t process.on('close',param.onClose);\n\t}\n\tif(param.onError){\n\t process.on('error',param.onError);\n\t}\n\tif(process && process.pid) {\n\t return { \n write : function(data){ \n\t\t\t\t console.debug(`send data to process with command ${param.command} pid ${process.pid}:`, data);\n\t\t\t process.stdin.write(data); } ,\n\t\t kill : function(){ process.kill(); }\n\t\t };\n\t} else {\n\t return spawnFailure(param,\n\t\t\t `spawned failed ${param.command} ${param.args} pid ${process.pid}`);\n\t}\n\tstdsimProcesses.push(process);\n } catch(err){\n\treturn spawnFailure(param,err.message);\n }\n}\n\nfunction jqueryOn(selector,event,handler){\n $(document.body).on(event,\n\t\t\tselector,\n\t\t\tfunction (e) { handler(e); });\n\n}\n\n// http://stackoverflow.com/questions/22395357/how-to-compare-two-arrays-are-equal-using-javascript-or-jquery\nfunction is_same(array1,array2){\n var same =\n (array1.length == array2.length)\n\t&&\n\tarray1.every(function(element, index) {\n return element === array2[index];\n\t});\n return same;\n}\n/* needed to add the stylesheet to the export */\nvar cssTextToken = \"/* stylesheet : a5f23ffb-e635-435c-ae44-c10779c2a843 */\";\nfunction createSVGDefs(svg){\n var svgDefs = svg.append('defs')\n\t .append(\"style\")\n\t .attr(\"type\",\"text/css\")\n\t .text(cssTextToken);\n return svgDefs;\n}\nfunction plotPNG(plotDivId,title,plotName,plotStyleId){\n try { var html = d3.select(\"#\"+plotDivId)\n .select(\"svg\")\n .attr(\"title\", title)\n .attr(\"version\", 1.1)\n .attr(\"xmlns\", \"http://www.w3.org/2000/svg\")\n .attr(\"xmlns:xlink\", \"http://www.w3.org/1999/xlink\")\n .node()\n .outerHTML;\n var style = plotStyleId?d3.select(\"#\"+plotStyleId).text():\"\";\n style = \"<![CDATA[\"+style+\"]]>\";\n html = html.replace(cssTextToken,style);\n var imgsrc = 'data:image/svg+xml;base64,'+ btoa(html);\n var canvas = document.createElement(\"canvas\");\n var width = parseInt(d3.select(\"#\"+plotDivId)\n\t\t\t .select(\"svg\")\n\t\t\t .style(\"width\")\n \t\t\t .replace(\"px\", \"\"));\n var height = parseInt(d3.select(\"#\"+plotDivId)\n\t\t\t\t .select(\"svg\")\n\t\t\t\t .style(\"height\")\n\t\t\t\t .replace(\"px\", \"\"));\n canvas.width = width; // get original canvas width\n canvas.height = height; //get original canvas height\n var context = canvas.getContext(\"2d\");\n var image = new Image(width, height);\n image.onload = function() {\n context.fillStyle = \"white\";\n context.fillRect(0, 0, width, height);\n context.drawImage(image, 0, 0, width, height);\n var canvasdata = canvas.toDataURL(\"image/png\");\n var a = document.createElement(\"a\");\n a.style = \"display: none\";\n document.body.appendChild(a);\n a.download = plotName;\n a.href = canvasdata;\n a.click();\n document.body.removeChild(a);\n };\n image.onerror = function(e){\n console.error(\"Error when plotting PNG: \", e);\n }\n image.src = imgsrc;\n\n } catch (e) {\n alert(e);\n }\n}\n\nfunction saveFile(data,mime,filename){\n var blob = new Blob([data], {type: mime });\n var url = window.URL.createObjectURL(blob);\n var a = document.createElement(\"a\");\n document.body.appendChild(a);\n a.style = \"display: none\";\n a.href = url;\n a.download = filename;\n a.click();\n document.body.removeChild(a);\n}\n\nfunction plotSVG(plotDivId,title,plotName,plotStyleId){\n try { var html = d3.select(\"#\"+plotDivId)\n .select(\"svg\")\n //.attr(\"title\", title)\n .attr(\"version\", 1.1)\n .attr(\"xmlns\", \"http://www.w3.org/2000/svg\")\n .node()\n .outerHTML;\n var style = plotStyleId?d3.select(\"#\"+plotStyleId).text():\"\";\n style = \"<![CDATA[\"+style+\"]]>\";\n html = html.replace(cssTextToken,style);\n\t var header =\n\t\t\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\" standalone=\\\"no\\\"?>\\n\"\n + \"<!DOCTYPE svg PUBLIC \\\"-//W3C//DTD SVG 1.1//EN\\\"\\n\"\n + \"\\\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\\\">\\n\";\n\t html = header+html;\n saveFile(html,\"image/svg+xml\",plotName);\n } catch (e) {\n alert(e);\n }\n}\n\n// http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/\nfunction hashCode(s){\n s = s+s+s+s+s+s+s;\n var hash = 0;\n if (s.length == 0) return hash;\n var i = 0;\n for (i = 0; i < s.length; i++) {\n var char = s.charCodeAt(i);\n hash = ((hash<<5)-hash)+char;\n hash = hash & hash; // Convert to 32bit integer\n }\n return hash;\n}\n\n// http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript\nfunction hashColor(s){\n var hashInt = hashCode(s);\n if (hashInt < 0)\n { hashInt = 0xFFFFFFFF + hashInt + 1; }\n var hashColor = hashInt.toString(16);\n var hashString = String(\"000000\" + hashColor).slice(-6);\n return \"#\"+hashString;\n}\n\nfunction ajaxRequest(url,type,data,handler,timeout){\n var parameter = { url : url , type : type };\n if(timeout){\n\tparameter.timeout = timeout;\n }\n if(data){ parameter.data = data; }\n console.group(\"ajax request: \");\n console.debug(parameter);\n console.groupEnd();\n $.ajax(parameter)\n .done(function( data, textStatus, jqXHR )\n\t { var status = jqXHR.status;\n\t var response_text = jqXHR.responseText;\n\t wrap(handler(status,response_text));\n\t })\n .fail(function(jqXHR, textStatus, errorThrown )\n\t { var status = jqXHR.status;\n\t var response_text = jqXHR.responseText;\n\t if(textStatus===\"timeout\") {\n\t\t wrap(handler(408,\"Timeout\"));\n\t } else {\n\t\t wrap(handler(status,response_text));\n\t }\n\t });\n\n}\n/* Apply an action to a modal window. */\nfunction modal(id,action){\n $(id).modal(action);\n}\n// http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript/2117523#2117523\n/* Used primarily to create a client id */\nfunction guid(){\n return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {\n\tvar r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);\n\treturn v.toString(16);\n });\n}\n/* Throw an exception */\nfunction toss(e){ throw e; }\n\n/* Return the data of an element. */\nfunction elementData(element,label){\n var result = $(element).data(label);\n return result;\n}\n\n/* create a jquery ui sort */\nfunction createSort(id,handler){\n $(\"#\"+id).sortable({\n items : \"li:not(.ui-sort-disabled)\",\n\tchange : function() {\n\t var list = $(this).closest('ul');\n\t /* used to pin elements to the top */\n\t var topAnchor = $(list).find('.ui-sort-top-anchor');\n\t /* used to pin elements to the bottom */\n\t var bottomAnchor = $(list).find('.ui-sort-bottom-anchor');\n\t $(list).prepend($(topAnchor).detach());\n\t $(list).append($(bottomAnchor).detach());\n\t}\n });\n $(\"#\"+id).on(\"sortupdate\",handler);\n}\n/* apply a map over the child nodes */\nfunction childrenValue(element,selector,map){\n var result = [];\n $(element).children(selector).each(function(index){ result.push(map(this)); })\n return result;\n}\n\nfunction hideCodeMirror(){\n $.each($('.CodeMirror'),(_,cm) => $(cm.CodeMirror.getWrapperElement()).hide());\n}\n\nfunction showCodeMirror(){\n $.each($('.CodeMirror'),(_,cm) => $(cm.CodeMirror.getWrapperElement()).show());\n}\n";;