https://github.com/plotly/plotly.js
Raw File
Tip revision: 7d16f39bbf95679060b5685de86ba2c7ab3f4d40 authored by Mojtaba Samimi on 13 March 2023, 14:30:47 UTC
2.19.0
Tip revision: 7d16f39
plotly_node.js
var fs = require('fs');
var JSDOM = require('jsdom').JSDOM;

var window = new JSDOM('', {
    runScripts: 'dangerously'
}).window;

// Mock things that jsdom doesn't support out-of-the-box
window.URL.createObjectURL = function() {};

module.exports = function plotlyNode(plotlyPath) {
    // Execute source code by inserting a <script> tag containing it
    var scriptEl = window.document.createElement('script');
    scriptEl.textContent = fs.readFileSync(plotlyPath, { encoding: 'utf-8' });
    window.document.body.appendChild(scriptEl);

    return window.Plotly;
};
back to top