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

Problem when drawing with dynamic parameter #86

Closed
XWCHAO opened this issue Dec 2, 2017 · 3 comments
Closed

Problem when drawing with dynamic parameter #86

XWCHAO opened this issue Dec 2, 2017 · 3 comments

Comments

@XWCHAO
Copy link

XWCHAO commented Dec 2, 2017

Hi,

Sorry for the continuous questions. I have my struct Gobang here, where Board is the game board, and X,Y are the position of next step (where I will put chess on). I want to draw a circle as a chess on the position of (X, Y). So I use the template to dynamically draw it, since X and Y will change every time.

type Gobang struct {
  Board [16][16]int
  X, Y float64
}

I use the html code below: if .X and .Y are not 0, I will draw a circle on (.X, .Y).

{{if ne .X 0.0}}
      {{if ne .Y 0.0}}
          <h1>test</h1>
          <circle cx=".X" cy=".Y" r="12" fill="black" />
      {{end}}
{{end}}

But when I run it with setting g.X and g.Y to 45 in go function, I got nothing on my board. And when I change the html code into:
<circle cx="45" cy="45" r="12" fill="black" />
I can draw the circle normally on the right place.

I also tested below code:

      {{if eq .X 45.0}}
        {{if eq .Y 45.0}}
          <h1>RIGHT</h1>
        {{end}}
      {{end}}

And I can got the "RIGHT" on the app window.

So I cannot pass in a dynamic parameter when drawing a circle with svg in html? How could that be?

Thanks!

@maxence-charriere
Copy link
Owner

I think that your markup is not good. There should not be a h1 tag in a .svg

@XWCHAO
Copy link
Author

XWCHAO commented Dec 2, 2017

I don't think that's the issue. I added the <h1> only after problem showed, and I wanted to test if the two "if" conditions work.

If I changed the ".X" and ".Y" into 45, 45, in <circle> tag, I can draw like this:
image

Modify: I didn't got nothing on my board when passing .X and .Y. I got a quarter of circle whose center is on (0,0), and radius is 12. So I think the <circle> tag didn't receive any value from cx and cy, so it used the default value 0,0.

image

@XWCHAO
Copy link
Author

XWCHAO commented Dec 2, 2017

OMG!!! I fixed it by:
<circle cx="{{.X}}" cy="{{.Y}}" r="12" fill="black" />

And I don't know why it need {{}} to pass in parameters. But it works.

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

No branches or pull requests

2 participants