html5 canvas绘制带有额外数据的圆形变量
所以我基本上试图创建一个座位表,用圆圈标记点,然后在鼠标悬停时显示一个工具提示,其中包含该人的名字、姓氏,也许还有一些其他信息。我可能会使用 Kinetic.JS 来支持区域/工具提示,因为我似乎最常遇到它的教程。
我想为每人创建 1 个变量,其中不仅包含命名信息,还包含有关圆圈的一些详细信息,这可能很简单,但我对 JS 总体来说是新手。这就是我提出的更多理论,因为它实际上似乎并不简单地工作:
Function seat(centerX, centerY, radius, fillStyle, firstName, lastName, id) { This.centerX=ctx.arc(centerX); This.centerY=ctx.arc(centerY); This.radius=ctx.arc(radius); This.fillStyle=ctx.fillStyle; This.firstName=firstName; This.lastName=lastName; This.id=id; } var johnSmith = new seat (100, 120, 10, #999, John, Smith, 123); var canvas = document.getElementById("seatingChart"); var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.arc(johnSmith); ctx.moveTo(…); ctx.arc(nextPerson); ect…
我知道为了使圆正常工作,我需要将弧信息的最后一部分放在 ctx. arc(.., .., .., 0, 2 * Math.PI, false);
我只是不确定它应该在哪里,所以我不必为每个变量重复它?
有人愿意帮助我以正确的方式进行设置吗?我目前正在阅读一本 JS 书,但似乎无法正确设置此设置..
谢谢
So I am basically trying to create a seating chart that will mark spots with circles and then onMouseover displays a tooltip with the person’s first name, last name, and maybe some other information. I will likely be using Kinetic.JS for region/tooltip support as I seem to come across tutorials for it most often.
I would like to create 1 variable per person that contains not only the naming info, but also some details about the circle, this may be simple but I am new to JS in general. This is what I have come up with more as theory since it doesn’t seem to actually work this simply:
Function seat(centerX, centerY, radius, fillStyle, firstName, lastName, id) { This.centerX=ctx.arc(centerX); This.centerY=ctx.arc(centerY); This.radius=ctx.arc(radius); This.fillStyle=ctx.fillStyle; This.firstName=firstName; This.lastName=lastName; This.id=id; } var johnSmith = new seat (100, 120, 10, #999, John, Smith, 123); var canvas = document.getElementById("seatingChart"); var ctx = canvas.getContext("2d"); ctx.beginPath(); ctx.arc(johnSmith); ctx.moveTo(…); ctx.arc(nextPerson); ect…
I know in order for a circle to work properly I need to have the last part of the arc info somewhere ctx.arc(.., .., .., 0, 2 * Math.PI, false);
I am just not sure where it should be so i don't have to repeat it for every variable?
Would someone be willing to help me set this set up in the proper way? I am currently working my way through a JS book, but simply can’t seem to get this setup properly..
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 jcubed 所说:“您无法将包含这些属性的对象传递给 arc。”
你可以做的是创建你自己的函数,例如:
如果你这样做,你也可以轻松地改变将来如何画一个人。
如果您只想更容易地绘制一般的圈子,您可以这样做:
As jcubed says: "You cannot pass an object to arc containing those properties."
What you could do is to create your own function like:
If you do it this way, you can also easily change how to draw a person in the future.
If you only want it to be easier to draw cricles in general you could do:
你不能像这样调用 javascript 中的函数。您必须使用逗号分隔的参数,例如 ctx.arc(centerX, centerY, radius,startingAngle,endingAngle, antiClockwise);。您不能将对象传递给包含这些属性的弧。
做:
对每个人来说,就像在 for 循环或其他东西中一样。
You cannot call functions in javascript like that. You have to have comma separated parameters, like
ctx.arc(centerX, centerY, radius, startingAngle, endingAngle, antiClockwise);
. You cannot pass an object to arc containing those properties.Do:
for every person, like in a for loop or something.