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

add svg basics test and example #751

Closed

Conversation

sepiropht
Copy link
Contributor

@fitzgen
Copy link
Member

fitzgen commented Aug 25, 2018

Looks like there's a bunch of compilation errors: https://travis-ci.org/rustwasm/wasm-bindgen/jobs/420500433#L3876

Does this compile and run OK for you locally?

@sepiropht sepiropht force-pushed the feature_svg_basics_exaple_testing branch 8 times, most recently from d47f71c to 6e7e82f Compare August 27, 2018 12:11
@sepiropht
Copy link
Contributor Author

In fact locally my example doesn't build but neither the old one (dom, hello-word...etc)
I used the script ./build.sh or i tried manually with wasm-bindgen cli i keep getting this errors.
`svg git:feature_svg_basics_exaple_testing ❯ ./build.sh ⏎ ✹

  • cargo +nightly build --target wasm32-unknown-unknown
    error: failed to resolve patches for https://github.com/rust-lang/crates.io-index
    Caused by:
    patch for wasm-bindgen in https://github.com/rust-lang/crates.io-index did not resolve to any crates. If this is unexpected, you may wish to consult: https://github.com/rust-lang/cargo/issues/4678`
    This why i push to see the build result in travis, sorry for that.

@sepiropht
Copy link
Contributor Author

sepiropht commented Aug 28, 2018

In the end of the build, I get this errors: Module not found: Error: Can't resolve './svg' in '/home/travis/build/rustwasm/wasm-bindgen/examples/svg'
It seems to me that i followed exactly the same structure that the others examples, but i'm certainly missing something, as it is not working.

@fitzgen
Copy link
Member

fitzgen commented Aug 28, 2018

Have you tried a cargo update perhaps?

@sepiropht sepiropht force-pushed the feature_svg_basics_exaple_testing branch from 6e7e82f to f886559 Compare August 29, 2018 20:55
@sepiropht
Copy link
Contributor Author

Thanks @fitzgen cargo update solved all issues !

crates/web-sys/tests/wasm/svg_element.rs Outdated Show resolved Hide resolved
// signatures documented on MDN, for example
#[wasm_bindgen]
extern "C" {
type HTMLDocument;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this should instead be using web-sys; the goal is to show off an example of working with SVG using web-sys.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i understand that, but even in raw javascript we don't use any svg class to create and append svg in the dom.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't clear: it should be using web_sys::HtmlDocument isntead of a custom import, and web_sys::HtmlDocument::create_element_ns etc..

package-lock.json
dom.js
dom_bg.js
dom_bg.wasm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dom" -> "svg" for all these

let path = document.createElementNS("http://www.w3.org/2000/svg", "path");
path.set_attribute("d", &JsValue::from("M100,0 L200,100 100,200 0,100Z"));
path.set_attribute("fill", &JsValue::from("red"));
svg.append_child(&path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want something that is slightly more compelling than a red diamond (I think that's what this is?)

How about porting

  <svg width="100%" height="100%">
    <rect width="100%" height="100%" fill="red" />
    <circle cx="100%" cy="100%" r="150" fill="blue" stroke="black" />
    <polygon points="120,0 240,225 0,225" fill="green"/>
    <text x="50" y="100" font-family="Verdana" font-size="55"
          fill="white" stroke="black" stroke-width="2">
            Hello!
    </text>
  </svg>

from https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Adding_vector_graphics_to_the_Web to web-sys?

@sepiropht sepiropht force-pushed the feature_svg_basics_exaple_testing branch from f886559 to 902d367 Compare August 30, 2018 14:27
@sepiropht sepiropht force-pushed the feature_svg_basics_exaple_testing branch from 902d367 to 87a7e78 Compare September 3, 2018 22:24
@ghost
Copy link

ghost commented Sep 26, 2018

What's the status for this?

@alexcrichton
Copy link
Contributor

I'm gonna close this as it's been a bit quiet and stale for some time now, but we can of course resubmit at any time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants