Skip to content

Commit

Permalink
Fix SVG support. (#231)
Browse files Browse the repository at this point in the history
* Fix SVG support.

* Remove .js.map files from git.
  • Loading branch information
twavv authored and shashi committed Nov 21, 2018
1 parent 116956c commit 1225803
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
*.pyc
deps/build.log
*.ipynb_checkpoints
*.js.map
5 changes: 4 additions & 1 deletion packages/blink-provider/dist/blink.js
Original file line number Diff line number Diff line change
Expand Up @@ -15665,14 +15665,17 @@ function (_WebIONode) {
namespace = _data$instanceArgs.namespace,
tag = _data$instanceArgs.tag;

switch (namespace) {
switch (namespace.toLocaleLowerCase()) {
case "html"
/* HTML */
:
return document.createElement(tag);

case "http://www.w3.org/2000/svg"
/* SVG */
:
case "svg"
/* SVG_SHORTHAND */
:
return document.createElementNS("http://www.w3.org/2000/svg"
/* SVG */
Expand Down
1 change: 0 additions & 1 deletion packages/blink-provider/dist/blink.js.map

This file was deleted.

5 changes: 4 additions & 1 deletion packages/generic-http-provider/dist/generic-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -15661,14 +15661,17 @@ function (_WebIONode) {
namespace = _data$instanceArgs.namespace,
tag = _data$instanceArgs.tag;

switch (namespace) {
switch (namespace.toLocaleLowerCase()) {
case "html"
/* HTML */
:
return document.createElement(tag);

case "http://www.w3.org/2000/svg"
/* SVG */
:
case "svg"
/* SVG_SHORTHAND */
:
return document.createElementNS("http://www.w3.org/2000/svg"
/* SVG */
Expand Down
1 change: 0 additions & 1 deletion packages/generic-http-provider/dist/generic-http.js.map

This file was deleted.

5 changes: 4 additions & 1 deletion packages/jupyter-notebook-provider/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15492,14 +15492,17 @@ function (_super) {
namespace = _a.namespace,
tag = _a.tag;

switch (namespace) {
switch (namespace.toLocaleLowerCase()) {
case "html"
/* HTML */
:
return document.createElement(tag);

case "http://www.w3.org/2000/svg"
/* SVG */
:
case "svg"
/* SVG_SHORTHAND */
:
return document.createElementNS("http://www.w3.org/2000/svg"
/* SVG */
Expand Down
1 change: 0 additions & 1 deletion packages/jupyter-notebook-provider/dist/main.js.map

This file was deleted.

5 changes: 4 additions & 1 deletion packages/mux-provider/dist/mux.js
Original file line number Diff line number Diff line change
Expand Up @@ -15661,14 +15661,17 @@ function (_WebIONode) {
namespace = _data$instanceArgs.namespace,
tag = _data$instanceArgs.tag;

switch (namespace) {
switch (namespace.toLocaleLowerCase()) {
case "html"
/* HTML */
:
return document.createElement(tag);

case "http://www.w3.org/2000/svg"
/* SVG */
:
case "svg"
/* SVG_SHORTHAND */
:
return document.createElementNS("http://www.w3.org/2000/svg"
/* SVG */
Expand Down
1 change: 0 additions & 1 deletion packages/mux-provider/dist/mux.js.map

This file was deleted.

3 changes: 2 additions & 1 deletion packages/webio/lib/DomNode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import WebIONode, { WebIODomElement, WebIONodeSchema, WebIONodeContext } from ".
export declare const DOM_NODE_TYPE = "DOM";
declare const enum DomNamespace {
HTML = "html",
SVG = "http://www.w3.org/2000/svg"
SVG = "http://www.w3.org/2000/svg",
SVG_SHORTHAND = "svg"
}
/**
* Props associated with a WebIO DOM node serialization.
Expand Down
4 changes: 3 additions & 1 deletion packages/webio/src/DomNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const enum DomNamespace {
// "html" should actually be "http://www.w3.org/1999/xhtml" but it's okay
HTML = "html",
SVG = "http://www.w3.org/2000/svg",
SVG_SHORTHAND = "svg",
}

/**
Expand Down Expand Up @@ -96,10 +97,11 @@ class WebIODomNode extends WebIONode {

private static createElement(data: DomNodeData) {
const {namespace, tag} = data.instanceArgs;
switch (namespace) {
switch (namespace.toLocaleLowerCase()) {
case DomNamespace.HTML:
return document.createElement(tag);
case DomNamespace.SVG:
case DomNamespace.SVG_SHORTHAND:
return document.createElementNS(DomNamespace.SVG, tag);
default:
throw new Error(`Unknown DOM namespace: ${namespace}.`);
Expand Down
20 changes: 20 additions & 0 deletions test/blink-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@ end
end
end

@testset "SVG/Namespaces" begin
window = Window(Dict(:show => false))

n = 10
color = "yellow"
h, w = 100, 100
attributes = Dict(
"fill" => color,
"points" => join(["$(w/2*(1+sin(θ))),$(h/2*(1+cos(θ)))" for θ in 0:2π/n:2π], ' '),
)
my_svg = dom"svg:svg[width=$w, height=$h]"(
dom"svg:polygon"(attributes=attributes),
attributes=Dict("data-test-key" => "1234"),
)
body!(window, dom"div"(my_svg))
sleep(5) # wait for it to render.
child_count = @js window document.querySelector("svg[data-test-key=\"1234\"]").childElementCount
@test child_count == 1
end


example_renderable_was_rendered = false

Expand Down

0 comments on commit 1225803

Please sign in to comment.