1
0
Fork 0

feat(core): Added path.addText and path.setText methods

Also added a parameter to path.reverse to make it a deep clone.
This commit is contained in:
Joost De Cock 2022-09-27 18:22:56 +02:00
parent ba2eef45ff
commit 3cb5384df5
3 changed files with 34 additions and 4 deletions

View file

@ -67,6 +67,20 @@ Path.prototype.addClass = function (className = false) {
return this
}
/**
* A chainable way to add text to a Path
*
* @param {string} text - The text to add to the Path
* @param {string} className - The CSS classes to apply to the text
* @return {Path} this - The Path instance
*/
Path.prototype.addText = function (text = '', className = false) {
this.attributes.add('data-text', text)
if (className) this.attributes.add('data-text-class', className)
return this
}
/**
* Returns the SVG pathstring for this path
*
@ -536,7 +550,7 @@ Path.prototype.offset = function (distance) {
*
* @return {object} reverse - A Path instance that is the reversed version of this Path
*/
Path.prototype.reverse = function () {
Path.prototype.reverse = function (cloneAttributes = false) {
let sections = []
let current
let closed = false
@ -555,6 +569,7 @@ Path.prototype.reverse = function () {
let rev = new Path().__withLog(this.log).move(current)
for (let section of sections.reverse()) rev.ops.push(section.ops[1])
if (closed) rev.close()
if (cloneAttributes) rev.attributes = this.attributes.clone()
return rev
}
@ -613,6 +628,19 @@ Path.prototype.setHidden = function (hidden = false) {
return this
}
/**
* A chainable way to set text on a Path
*
* @param {string} text - The text to add to the Path
* @param {string} className - The CSS classes to apply to the text
* @return {Path} this - The Path instance
*/
Path.prototype.setText = function (text = '', className = false) {
this.attributes.set('data-text', text)
if (className) this.attributes.set('data-text-class', className)
return this
}
/**
* Returns a point that lies at distance along this Path
*

View file

@ -149,8 +149,9 @@ Pattern.prototype.draft = function () {
this.setStores[set].log.error(
`Unable to draft pattern part __${partName}__. Part.draft() is not callable`
)
this.parts[set][partName].hidden =
this.parts[set][partName].hidden === true ? true : !this.__wants(partName, set)
// FIXME: THis won't work not that this is immutable
// But is it still needed?
// this.parts[set][partName].hidden === true ? true : !this.__wants(partName, set)
} else {
this.setStores[set].log.debug(
`Part \`${partName}\` is not needed. Skipping draft and setting hidden to \`true\``

View file

@ -50,6 +50,7 @@ Point.prototype.addText = function (text = '', className = false) {
return this.__check()
}
/**
* Returns the angle between this Point and that Point
*
@ -202,7 +203,7 @@ Point.prototype.setCircle = function (radius = false, className = false) {
}
/**
* A chainable way to add text to a Point
* A chainable way to set text on a Point
*
* @param {string} text - The text to add to the Point
* @param {string} className - The CSS classes to apply to the text