RaphaelJS 2.1 与 1.5.2 getBBox 错误 [英] RaphaelJS 2.1 vs. 1.5.2 getBBox Error

查看:16
本文介绍了RaphaelJS 2.1 与 1.5.2 getBBox 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个类似于 http://raphaeljs.com/graffle.html(适用于 1.5.2 和 2.1),但我想在框中包含文本.

I'm trying to create a draggable graph similar to http://raphaeljs.com/graffle.html (works in both 1.5.2 and 2.1), but I want to include text in the boxes.

我使用另一个问题中的建议添加了文本:如何组合 Raphael javascript 库中的对象?

I added the text using the suggestion in another question: How can I combine objects in the Raphael javascript library?

此解决方案适用于 RaphaelJS 1.5.2,但它在 RaphaelJS 2.1 中失效.

This solution works great with RaphaelJS 1.5.2, but it breaks in RaphaelJS 2.1.

jsFiddle 示例: http://jsfiddle.net/ScBtZ/

我发现的唯一区别是 Element.getBBox() 返回一个非常不同的结果.

The only difference I have found is that Element.getBBox() returns a very different result.

示例:

在 1.5.2 中:

SVGRect
  height: 40
  width: 100
  x: 526.5
  y: 25

在 2.1 中:

Object
  height: 500780.9482062537
  width: 1009980
  x: 526.51
  x2: 1010506.51
  y: -399735.94795512746
  y2: 101045.00025112627

我是否遗漏了从 v1.5 到 v2 的变化,或者这个奇怪的 BBox 是一个错误?有什么想法可以解决这个问题吗?

Am I missing something about the change from v1.5 to v2, or is this odd BBox a bug? Any ideas how I can fix this issue?

谢谢!

推荐答案

好吧,看起来在 Raphael 中尝试用自定义实现替换本机方法 getBBox.这背后的原因可能是原生 getBBox 方法存在一些错误,并且它对某些形状返回了不正确的结果.另一个原因可能是浏览器的可移植性,我不确定 VML 中是否有 getBBox 方法.

Well, it looks like there was an attempt to replace the native method getBBox with a custom implementation, in Raphael. The reasons behind this might be that the native getBBox method has some bugs, and it returns improper results for some shapes. Another reason might be browser portability, I'm not sure if there is a getBBox method in VML.

但是,从您指出的值来看,这个自定义实现似乎有其缺陷.您可以使用以下代码在 Raphael 2.x 中使用本机 getBBox:

However, from the values you pointed out is seems like this custom implementation has its flaws. You can use the native getBBox in Raphael 2.x with this code:

var bb1 = obj1.node.getBBox(),
    bb2 = obj2.node.getBBox(),

我测试了它,看起来不错:http://jsfiddle.net/ScBtZ/2/

I tested it and looks good: http://jsfiddle.net/ScBtZ/2/

这篇关于RaphaelJS 2.1 与 1.5.2 getBBox 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆