async () => { // set testFn() function on globalThis, so you html onlclick can access it globalThis.testFn = () => { document.getElementById('demo').innerHTML = "Hello-bertviz?" }; // await import * as mod from "/my-module.js"; const d3 = await import("https://cdn.jsdelivr.net/npm/d3@5/+esm"); const $ = await import("https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js"); globalThis.$ = $; // const $ = await import("https://cdn.jsdelivr.net/npm/jquery@2/+esm"); // import $ from "jquery"; // import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm"; // await import("https://cdn.jsdelivr.net/npm/jquery@2/+esm"); // export for others scripts to use // window.$ = window.jQuery = jQuery; // const d3 = await import("https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min"); // const $ = await import("https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min"); globalThis.d3Fn = () => { d3.select('#viz').append('svg') .append('rect') .attr('width', 50) .attr('height', 50) .attr('fill', 'black') .on('mouseover', function(){d3.select(this).attr('fill', 'red')}) .on('mouseout', function(){d3.select(this).attr('fill', 'black')}); }; // globalThis.testFn_out = (val,model) => { // document.getElementById('demo').innerHTML = val console.log(val); // globalThis.d3Fn(); return([val,model]); }; globalThis.testFn_out_json = (data) => { console.log(data); var $ = jQuery; console.log($('#viz')); attViz(data); return(['string', {}]) }; function attViz(PYTHON_PARAMS) { var $ = jQuery; const params = PYTHON_PARAMS; // HACK: PYTHON_PARAMS is a template marker that is replaced by actual params. const TEXT_SIZE = 15; const BOXWIDTH = 110; const BOXHEIGHT = 22.5; const MATRIX_WIDTH = 115; const CHECKBOX_SIZE = 20; const TEXT_TOP = 30; console.log("d3 version in ffuntions", d3.version) let headColors; try { headColors = d3.scaleOrdinal(d3.schemeCategory10); } catch (err) { console.log('Older d3 version') headColors = d3.scale.category10(); } let config = {}; // globalThis. initialize(); renderVis(); function initialize() { // globalThis.initialize = () => { console.log("init") config.attention = params['attention']; config.filter = params['default_filter']; config.rootDivId = params['root_div_id']; config.nLayers = config.attention[config.filter]['attn'].length; config.nHeads = config.attention[config.filter]['attn'][0].length; config.layers = params['include_layers'] if (params['heads']) { config.headVis = new Array(config.nHeads).fill(false); params['heads'].forEach(x => config.headVis[x] = true); } else { config.headVis = new Array(config.nHeads).fill(true); } config.initialTextLength = config.attention[config.filter].right_text.length; config.layer_seq = (params['layer'] == null ? 0 : config.layers.findIndex(layer => params['layer'] === layer)); config.layer = config.layers[config.layer_seq] // '#' + temp1.root_div_id+ ' #layer' $('#' + config.rootDivId+ ' #layer').empty(); let layerEl = $('#' + config.rootDivId+ ' #layer'); console.log(layerEl) for (const layer of config.layers) { layerEl.append($("