module:ViewBox(left, top, width, height)

ViewBox provides an api for oprerating with the viewBox argument of the DOM element.

new module:ViewBox(left, top, width, height)

Initialize viewBox

Parameters:
Name Type Description
left number

distance of the left edge of the viewbox from document's y axis in SVG pixels

top number

distance of the top edge of the viewbox from the document's x axis in SVG pixels

width number

width of the viewbox in SVG pixels

height number

height of the viewbox in SVG pixels

Members

height

get the height of the viewbox with the current zoom applied

left

get the horizontal distance from the y axis of the document with zoom and shift value applied

leftShift :number

amount of horizontal shift of the document

maxZoom :number

The maximum amount of zoom on the viewbox

minZoom :number

The minimum amount of zoom on the viewbox

real :object

ViewBox attributes before applying zoom and shift

realZoom :number

Amount of zoom on the viewbox, always between this.minZoom and this.maxZoom

str

get the computed viewbox values as a string in the correct format that can be used in the viewBox attribute of the SVG element

top

get the vertical distance from the x axis of the document with zoom and shift value applied

topShift :number

amount of vertical shift of the document

width

get the width of the viewbox with the current zoom applied

zoom

get the amount of zoom on the viewbox

zoom

set the amount of zoom on the viewbox

Methods

move(left, top)

apply viewbox movement and take the zoom into account

Parameters:
Name Type Description
left number

horizontal movement

top number

vertical movement

newDimensions(width, height)

update the dimensions of the viewbox (used on window resize)

Parameters:
Name Type Description
width Number

new width of the viewbox in SVG pixels

height Number

new height of the viewbox in SVG pixels

transformEvent(event) → {jquery.MouseEvent}

transform pageX and pageY parameters of the jquery event to match the zoom and shift of the viewbox

Parameters:
Name Type Description
event jquery.MouseEvent

original event

Returns:
jquery.MouseEvent -

the same event but with transformed pageX and pageY members

transformX(x) → {number}

transform horizontal units to the scale and shift of the editor

Parameters:
Name Type Description
x number

original horizontal value

Returns:
number -

transformed horizontal value

transformY(y) → {number}

transform vertical units to the scale and shift of the editor

Parameters:
Name Type Description
y number

original vertical value

Returns:
number -

transformed vertical value