aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-03-28 13:52:57 +1000
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-03-28 13:52:57 +1000
commitba2948bfad00906ffa3ba5ea7ff15ac0be517445 (patch)
tree953b7ebfef53b8a3e594632d9d2b7458028c7170 /src/modules
parent9beddac36db60c0e4097e01272b6faa04bdb1065 (diff)
downloadsvg.js-ba2948bfad00906ffa3ba5ea7ff15ac0be517445.tar.gz
svg.js-ba2948bfad00906ffa3ba5ea7ff15ac0be517445.zip
This is a big one...
### Fixed - fixed `zoom()` method of runner which was passed a wrong parameter - fixed positioning methods of `TSpan` to position them by its bounding box - fixed `flip()` method which flips correctly by center by default now and accepts correct arguments - fixed a case in `rbox()` where not always all values of the box were updated - fixed `getOrigin()` function used by `transform()` so that all origin (#1085) popssibilities specified in the docs are working - fixed positioning of text by its baseline when using `amove()` - fixed tons of typings in the svg.d.ts file ### Added - added second Parameter to `SVG(el, isHTML)` which allows to explicitely create elements in the HTML namespace (#1058) - added `unlink()` and `linker()` to hyperlinked elements to remove or access the underling `<a>` element - added `wrap()` method to `Dom` which lets you wrap an element by another one - added `orient()` method to `Marker` - added `options` parameter to `dispatch()` and `fire()` to allow for more special needs - added `newLine()` constructor to `Text` to create a tspan marked as new line (#1088) - added lots of tests in es6 format
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/core/event.js15
-rw-r--r--src/modules/core/textable.js64
-rw-r--r--src/modules/optional/sugar.js29
3 files changed, 79 insertions, 29 deletions
diff --git a/src/modules/core/event.js b/src/modules/core/event.js
index 2cf9b1e..976e13d 100644
--- a/src/modules/core/event.js
+++ b/src/modules/core/event.js
@@ -3,9 +3,9 @@ import { makeInstance } from '../../utils/adopter.js'
import { globals } from '../../utils/window.js'
let listenerId = 0
-const windowEvents = {}
+export const windowEvents = {}
-function getEvents (instance) {
+export function getEvents (instance) {
let n = instance.getEventHolder()
// We dont want to save events in global space
@@ -14,12 +14,13 @@ function getEvents (instance) {
return n.events
}
-function getEventTarget (instance) {
+export function getEventTarget (instance) {
return instance.getEventTarget()
}
-function clearEvents (instance) {
- const n = instance.getEventHolder()
+export function clearEvents (instance) {
+ let n = instance.getEventHolder()
+ if (n === globals.window) n = windowEvents
if (n.events) n.events = {}
}
@@ -120,14 +121,14 @@ export function off (node, events, listener, options) {
})
}
-export function dispatch (node, event, data) {
+export function dispatch (node, event, data, options) {
var n = getEventTarget(node)
// Dispatch event
if (event instanceof globals.window.Event) {
n.dispatchEvent(event)
} else {
- event = new globals.window.CustomEvent(event, { detail: data, cancelable: true })
+ event = new globals.window.CustomEvent(event, { detail: data, cancelable: true, ...options })
n.dispatchEvent(event)
}
return event
diff --git a/src/modules/core/textable.js b/src/modules/core/textable.js
index 55df7c6..28b13cb 100644
--- a/src/modules/core/textable.js
+++ b/src/modules/core/textable.js
@@ -17,3 +17,67 @@ export function plain (text) {
export function length () {
return this.node.getComputedTextLength()
}
+
+// Move over x-axis
+// Text is moved by its bounding box
+// text-anchor does NOT matter
+export function x (x, box = this.bbox()) {
+ if (x == null) {
+ return box.x
+ }
+
+ return this.attr('x', this.attr('x') + x - box.x)
+}
+
+// Move over y-axis
+export function y (y, box = this.bbox()) {
+ if (y == null) {
+ return box.y
+ }
+
+ return this.attr('y', this.attr('y') + y - box.y)
+}
+
+export function move (x, y, box = this.bbox()) {
+ return this.x(x, box).y(y, box)
+}
+
+// Move center over x-axis
+export function cx (x, box = this.bbox()) {
+ if (x == null) {
+ return box.cx
+ }
+
+ return this.attr('x', this.attr('x') + x - box.cx)
+}
+
+// Move center over y-axis
+export function cy (y, box = this.bbox()) {
+ if (y == null) {
+ return box.cy
+ }
+
+ return this.attr('y', this.attr('y') + y - box.cy)
+}
+
+export function center (x, y, box = this.bbox()) {
+ return this.cx(x, box).cy(y, box)
+}
+
+export function ax (x) {
+ return this.attr('x', x)
+}
+
+export function ay (y) {
+ return this.attr('y', y)
+}
+
+export function amove (x, y) {
+ return this.ax(x).ay(y)
+}
+
+// Enable / disable build mode
+export function build (build) {
+ this._build = !!build
+ return this
+}
diff --git a/src/modules/optional/sugar.js b/src/modules/optional/sugar.js
index 0da0fe4..0de2c04 100644
--- a/src/modules/optional/sugar.js
+++ b/src/modules/optional/sugar.js
@@ -87,16 +87,13 @@ registerMethods([ 'Element', 'Runner' ], {
},
// Map flip to transform
- flip: function (direction, around) {
- var directionString = typeof direction === 'string' ? direction
- : isFinite(direction) ? 'both'
- : 'both'
- var origin = (direction === 'both' && isFinite(around)) ? [ around, around ]
- : (direction === 'x') ? [ around, 0 ]
- : (direction === 'y') ? [ 0, around ]
- : isFinite(direction) ? [ direction, direction ]
- : [ 0, 0 ]
- return this.transform({ flip: directionString, origin: origin }, true)
+ flip: function (direction = 'both', origin = 'center') {
+ if ('xybothtrue'.indexOf(direction) === -1) {
+ origin = direction
+ direction = 'both'
+ }
+
+ return this.transform({ flip: direction, origin: origin }, true)
},
// Opacity
@@ -144,18 +141,6 @@ registerMethods([ 'Element', 'Runner' ], {
}
})
-registerMethods('Text', {
- ax (x) {
- return this.attr('x', x)
- },
- ay (y) {
- return this.attr('y', y)
- },
- amove (x, y) {
- return this.ax(x).ay(y)
- }
-})
-
// Add events to elements
const methods = [ 'click',
'dblclick',