Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a minimal resizable container for the container size problem #262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@ using Documenter, VegaLite, UUIDs

function Base.show(io::IO, m::MIME"text/html", v::VegaLite.VLSpec)
divid = string("vl", replace(string(uuid4()), "-"=>""))
print(io, "<div id='$divid' style=\"width:100%;height:100%;\"></div>")
print(io, "<div style=\"resize:both;overflow:auto;width:50%;height:50%;\" id='$divid'></div>")
print(io, "<script type='text/javascript'>requirejs.config({paths:{'vg-embed': 'https://cdn.jsdelivr.net/npm/[email protected]?noext','vega-lib': 'https://cdn.jsdelivr.net/npm/vega-lib?noext','vega-lite': 'https://cdn.jsdelivr.net/npm/[email protected]?noext','vega': 'https://cdn.jsdelivr.net/npm/[email protected]?noext'}}); require(['vg-embed'],function(vegaEmbed){vegaEmbed('#$divid',")
VegaLite.our_json_print(io, v)
print(io, ",{mode:'vega-lite'}).catch(console.warn);})</script>")
print(io, ",{mode:'vega-lite'}).catch(console.warn);})")
print(io, "</script>")
print(io, "<script type='text/javascript'>if(ResizeObserver){const divContainer=document.querySelector('#$divid');const resizeObserver=new ResizeObserver(entries => {for (let entry of entries) {if(entry.contentBoxSize || entry.contentRect ) {window.dispatchEvent(new Event('resize'));}}});resizeObserver.observe(divContainer);}</script>")
end

function Base.show(io::IO, m::MIME"text/html", v::VegaLite.VGSpec)
divid = string("vg", replace(string(uuid4()), "-"=>""))
print(io, "<div id='$divid' style=\"width:100%;height:100%;\"></div>")
print(io, "<div style=\"resize:both;overflow:auto;width:50%;height:50%;\" id='$divid'></div>")
print(io, "<script type='text/javascript'>requirejs.config({paths:{'vg-embed': 'https://cdn.jsdelivr.net/npm/[email protected]?noext','vega-lib': 'https://cdn.jsdelivr.net/npm/vega-lib?noext','vega-lite': 'https://cdn.jsdelivr.net/npm/[email protected]?noext','vega': 'https://cdn.jsdelivr.net/npm/[email protected]?noext'}}); require(['vg-embed'],function(vegaEmbed){vegaEmbed('#$divid',")
VegaLite.our_json_print(io, v)
print(io, ",{mode:'vega'}).catch(console.warn);})</script>")
print(io, ",{mode:'vega'}).catch(console.warn);})")
print(io, "</script>")
print(io, "<script type='text/javascript'>if(ResizeObserver){const divContainer=document.querySelector('#$divid');const resizeObserver=new ResizeObserver(entries => {for (let entry of entries) {if(entry.contentBoxSize || entry.contentRect ) {window.dispatchEvent(new Event('resize'));}}});resizeObserver.observe(divContainer);}</script>")
end

makedocs(
Expand Down
44 changes: 40 additions & 4 deletions src/rendering/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function writehtml_full(io::IO, spec::VLSpec; title="VegaLite plot")
<script>$(read(asset("vega-embed.min.js"), String))</script>
</head>
<body>
<div id="$divid" style="width:100%;height:100%;"></div>
<div style="resize:both;overflow:auto;width:50%;height:50%;" id="$divid"></div>
</body>

<style media="screen">
Expand Down Expand Up @@ -54,6 +54,18 @@ function writehtml_full(io::IO, spec::VLSpec; title="VegaLite plot")
println(io, """
vegaEmbed('#$divid', spec, opt);

if(ResizeObserver) {
const divContainer = document.querySelector('#$divid');
const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
if(entry.contentBoxSize || entry.contentRect ) {
window.dispatchEvent(new Event('resize'));
}
}
});
resizeObserver.observe(divContainer);
}

</script>

</html>
Expand All @@ -73,7 +85,7 @@ function writehtml_full(io::IO, spec::VGSpec; title="Vega plot")
<script>$(read(asset("vega-embed.min.js"), String))</script>
</head>
<body>
<div id="$divid" style="width:100%;height:100%;"></div>
<div style="resize:both;overflow:auto;width:50%;height:50%;" id="$divid"></div>
</body>

<style media="screen">
Expand Down Expand Up @@ -101,6 +113,18 @@ function writehtml_full(io::IO, spec::VGSpec; title="Vega plot")
println(io, """
vegaEmbed('#$divid', spec, opt);

if(ResizeObserver) {
const divContainer = document.querySelector('#$divid');
const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
if(entry.contentBoxSize || entry.contentRect ) {
window.dispatchEvent(new Event('resize'));
}
}
});
resizeObserver.observe(divContainer);
}

</script>

</html>
Expand Down Expand Up @@ -141,7 +165,7 @@ function writehtml_partial(io::IO, spec::String; title="VegaLite plot")
"""
<html>
<body>
<div id="$divid" style="width:100%;height:100%;"></div>
<div style="resize:both;overflow:auto;width:50%;height:50%;" id="$divid"></div>
</body>

<style media="screen">
Expand Down Expand Up @@ -188,7 +212,19 @@ function writehtml_partial(io::IO, spec::String; title="VegaLite plot")

})

</script>
if(ResizeObserver) {
const divContainer = document.querySelector('#$divid');
const resizeObserver = new ResizeObserver(entries => {
for (let entry of entries) {
if(entry.contentBoxSize || entry.contentRect ) {
window.dispatchEvent(new Event('resize'));
}
}
});
resizeObserver.observe(divContainer);
}

</script>

</html>
""")
Expand Down