lib/vega/spec.rb in vega-0.1.3 vs lib/vega/spec.rb in vega-0.2.0

- old
+ new

@@ -9,11 +9,18 @@ def to_s html, js = generate_output output = <<~EOS #{html} <script> - #{js} + (function() { + var createChart = function() { #{js} }; + if ("vegaEmbed" in window) { + createChart(); + } else { + window.addEventListener("vega:load", createChart, true); + } + })(); </script> EOS output.respond_to?(:html_safe) ? output.html_safe : output end @@ -23,15 +30,16 @@ output = <<~EOS #{html} <script> require.config({ paths: { - 'vega': 'https://cdn.jsdelivr.net/npm/vega@5.19.1?noext', - 'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@4.17.0?noext', - 'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6.15.1?noext' + 'vega': 'https://cdn.jsdelivr.net/npm/vega@5.21.0?noext', + 'vega-util': 'https://cdn.jsdelivr.net/npm/vega-util@1.17.0?noext', + 'vega-lite': 'https://cdn.jsdelivr.net/npm/vega-lite@5.1.1?noext', + 'vega-embed': 'https://cdn.jsdelivr.net/npm/vega-embed@6.19.1?noext' } }); - require(['vega', 'vega-lite', 'vega-embed'], function(vega, vegaLite, vegaEmbed) { + require(['vega', 'vega-util', 'vega-lite', 'vega-embed'], function(vega, vegaUtil, vegaLite, vegaEmbed) { #{js} }); </script> EOS ["text/html", output]