feat(plugin-dimension): New rmad macro
This commit is contained in:
parent
c1a8943f23
commit
309aebaecd
1 changed files with 14 additions and 4 deletions
|
@ -1,6 +1,8 @@
|
||||||
import markers from './lib/markers'
|
import markers from './lib/markers'
|
||||||
import { version, name } from '../package.json'
|
import { version, name } from '../package.json'
|
||||||
|
|
||||||
|
const prefix = '__paperless'
|
||||||
|
|
||||||
function drawDimension(from, to, so, self) {
|
function drawDimension(from, to, so, self) {
|
||||||
let dimension = new self.Path()
|
let dimension = new self.Path()
|
||||||
.move(from)
|
.move(from)
|
||||||
|
@ -75,21 +77,21 @@ export default {
|
||||||
macros: {
|
macros: {
|
||||||
// horizontal
|
// horizontal
|
||||||
hd: function (so) {
|
hd: function (so) {
|
||||||
let id = so.id || this.getId()
|
let id = so.id || this.getId(prefix)
|
||||||
let from = hleader(so, 'from', this, id + '_ls')
|
let from = hleader(so, 'from', this, id + '_ls')
|
||||||
let to = hleader(so, 'to', this, id + '_le')
|
let to = hleader(so, 'to', this, id + '_le')
|
||||||
this.paths[id] = drawDimension(from, to, so, this)
|
this.paths[id] = drawDimension(from, to, so, this)
|
||||||
},
|
},
|
||||||
// vertical
|
// vertical
|
||||||
vd: function (so) {
|
vd: function (so) {
|
||||||
let id = so.id || this.getId()
|
let id = so.id || this.getId(prefix)
|
||||||
let from = vleader(so, 'from', this, id + '_ls')
|
let from = vleader(so, 'from', this, id + '_ls')
|
||||||
let to = vleader(so, 'to', this, id + '_le')
|
let to = vleader(so, 'to', this, id + '_le')
|
||||||
this.paths[id] = drawDimension(from, to, so, this)
|
this.paths[id] = drawDimension(from, to, so, this)
|
||||||
},
|
},
|
||||||
// linear
|
// linear
|
||||||
ld: function (so) {
|
ld: function (so) {
|
||||||
let id = so.id || this.getId()
|
let id = so.id || this.getId(prefix)
|
||||||
let from = lleader(so, 'from', this, id + '_ls')
|
let from = lleader(so, 'from', this, id + '_ls')
|
||||||
let to = lleader(so, 'to', this, id + '_le')
|
let to = lleader(so, 'to', this, id + '_le')
|
||||||
this.paths[id] = drawDimension(from, to, so, this)
|
this.paths[id] = drawDimension(from, to, so, this)
|
||||||
|
@ -103,7 +105,7 @@ export default {
|
||||||
.attr('marker-end', 'url(#dimensionTo)')
|
.attr('marker-end', 'url(#dimensionTo)')
|
||||||
.attr('data-text', so.text || this.units(so.path.length()))
|
.attr('data-text', so.text || this.units(so.path.length()))
|
||||||
.attr('data-text-class', 'fill-mark center')
|
.attr('data-text-class', 'fill-mark center')
|
||||||
let id = so.id || this.getId()
|
let id = so.id || this.getId(prefix)
|
||||||
drawLeader(this, so.path.start(), dimension.start(), id + '_ls')
|
drawLeader(this, so.path.start(), dimension.start(), id + '_ls')
|
||||||
drawLeader(this, so.path.end(), dimension.end(), id + '_le')
|
drawLeader(this, so.path.end(), dimension.end(), id + '_le')
|
||||||
this.paths[id] = dimension
|
this.paths[id] = dimension
|
||||||
|
@ -120,6 +122,14 @@ export default {
|
||||||
if (this.paths[`${id}_le`]) delete this.paths[`${id}_le`]
|
if (this.paths[`${id}_le`]) delete this.paths[`${id}_le`]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// Remove all dimensions (with standard prefix)
|
||||||
|
rmad: function (so) {
|
||||||
|
for (let type of ['paths', 'points']) {
|
||||||
|
for (let id in this[type]) {
|
||||||
|
if (id.slice(0, prefix.length) === prefix) delete this[type][id]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue