Raphael.js How to get the central position of the paper and the scale relative to the center?

I defined my raphael paper as below:

var paper = Raphael("my-paper", '100%', '100%'); //render some shapes on my paper var e = paper.ellipse(50, 50, 40, 20); var c = paper.circle(50, 50, 40); var r = paper.rect(40, 40, 50, 50, 10); 

As you saw above, I defined my Raphael paper, then drew some shapes on my paper. I have the following two questions:

1. How to get the value of x and y at the central point of my article. (x: horizontal, y: vertical)

2. I would like to scale everything on my paper to twice the size, I know that I can use the Raphel scale function . I would like to scale all the elements on the paper relative to the center of my paper , so I need to do something like:

 e.scale(2, 2, CENTER_X, CENTER_Y) 

( CENTER_X and CENTER_Y are asked in question 1 )

I would like the result to look like an increase, am I using it correctly or are there other ways to do this?

+6
source share
2 answers

paper.width and paper.height should return the paper sizes that will give you the center.

+7
source

You can find a center of paper like this

 var x = this.paper.canvas.offsetLeft; var y = this.paper.canvas.offsetTop; var centerX = x + paper.width/2 ; var centerY= y + paper.height/2; 
0
source

Source: https://habr.com/ru/post/889962/


All Articles