[Ur] Unable to use d3.js library

Mark Clements mark.clements at ki.se
Wed Sep 25 17:13:05 EDT 2019


In developing an FFI for the rmath standalone library
(https://github.com/mclements/urweb-rmath), I wanted to plot some
values. I was able to get urweb-canvas going (very nice) and SVG [1],
but it would be nice to use some pre-existing libraries for axes,
labels, etc.

As an initial approach, I tried using c3 [2], which depends on the d3
library. However, the d3 library requires:

   <script src="/path/to/d3.min.js" charset="utf-8"></script>

which is not currently allowed in Ur/Web's xml. Moreover, the
allScripts() function in cjr_print.sml does not include an option to
change the charset. Is there another way to include a script with a
particular charset? Plotly.js also depends on d3, so it would be nice to
address this issue.

Kindly, Mark.

[1]
// Update urweb-examples/SVGTest/SVG.urs:
val path : svgTag ([D = string, PathLength = string, Stroke = string,
Fill = string, StrokeWidth = string] ++ typicalAttrs)

[2]
// c3ffi.js
function c3generate(id, x, y) {
     function listToArray(l) {
     var acc = [];
     var ll = l;
     for (; ll !== null; ll=ll._2) {
         acc.push(ll._1);
     }
     return acc;
     }
     var x2 = listToArray(x);
     var y2 = listToArray(y);
     x2.unshift('x');
     y2.unshift('y');
     var args = {bindto: document.getElementById(id), data: {x: 'x',
columns: [x2,y2]}};
     var chart = c3.generate(args);
     return chart;
}

// c3ffi.urs
type c3chart
val c3generate : id -> list float -> list float -> c3chart


När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter<https://ki.se/medarbetare/integritetsskyddspolicy>.


Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here<https://ki.se/en/staff/data-protection-policy>.


More information about the Ur mailing list