1
0
Fork 0

chore(plugin-scalebox): Make sure scalebox and miniscale can coexist

Also took my name of the patterns
This commit is contained in:
Joost De Cock 2021-01-16 14:10:00 +01:00
parent 650b7931ab
commit eccf8f58b7
2 changed files with 47 additions and 53 deletions

View file

@ -2,52 +2,48 @@ export default function(so) {
// Passing `false` will remove the miniscale // Passing `false` will remove the miniscale
if (so === false) { if (so === false) {
for (let id of [ for (let id of [
'__scaleboxMetricTopLeft', '__miniscaleMetricTopLeft',
'__scaleboxMetricTopRight', '__miniscaleMetricTopRight',
'__scaleboxMetricBottomRight', '__miniscaleMetricBottomRight',
'__scaleboxMetricBottomLeft', '__miniscaleMetricBottomLeft',
'__scaleboxImperialTopLeft', '__miniscaleImperialTopLeft',
'__scaleboxImperialTopRight', '__miniscaleImperialTopRight',
'__scaleboxImperialBottomRight', '__miniscaleImperialBottomRight',
'__scaleboxImperialBottomLeft', '__miniscaleImperialBottomLeft',
'__scaleboxLead', '__miniscaleMetric',
'__scaleboxTitle', '__miniscaleImperial'
'__scaleboxText',
'__scaleboxLink',
'__scaleboxMetric',
'__scaleboxImperial'
]) ])
delete this.points[id] delete this.points[id]
for (let id of ['__scaleboxMetric', '__scaleboxImperial']) delete this.paths[id] for (let id of ['__miniscaleMetric', '__miniscaleImperial']) delete this.paths[id]
return true return true
} }
const m = 12.5 const m = 12.5
const i = 12.7 const i = 12.7
// Box points // Box points
this.points.__scaleboxMetricTopLeft = new this.Point(so.at.x - m, so.at.y - m) this.points.__miniscaleMetricTopLeft = new this.Point(so.at.x - m, so.at.y - m)
this.points.__scaleboxMetricTopRight = new this.Point(so.at.x + m, so.at.y - m) this.points.__miniscaleMetricTopRight = new this.Point(so.at.x + m, so.at.y - m)
this.points.__scaleboxMetricBottomLeft = new this.Point(so.at.x - m, so.at.y + m) this.points.__miniscaleMetricBottomLeft = new this.Point(so.at.x - m, so.at.y + m)
this.points.__scaleboxMetricBottomRight = new this.Point(so.at.x + m, so.at.y + m) this.points.__miniscaleMetricBottomRight = new this.Point(so.at.x + m, so.at.y + m)
this.points.__scaleboxImperialTopLeft = new this.Point(so.at.x - i, so.at.y - i) this.points.__miniscaleImperialTopLeft = new this.Point(so.at.x - i, so.at.y - i)
this.points.__scaleboxImperialTopRight = new this.Point(so.at.x + i, so.at.y - i) this.points.__miniscaleImperialTopRight = new this.Point(so.at.x + i, so.at.y - i)
this.points.__scaleboxImperialBottomLeft = new this.Point(so.at.x - i, so.at.y + i) this.points.__miniscaleImperialBottomLeft = new this.Point(so.at.x - i, so.at.y + i)
this.points.__scaleboxImperialBottomRight = new this.Point(so.at.x + i, so.at.y + i) this.points.__miniscaleImperialBottomRight = new this.Point(so.at.x + i, so.at.y + i)
// Text anchor points // Text anchor points
this.points.__scaleboxMetric = new this.Point(so.at.x, so.at.y - 2) this.points.__miniscaleMetric = new this.Point(so.at.x, so.at.y - 2)
this.points.__scaleboxImperial = new this.Point(so.at.x, so.at.y + 8) this.points.__miniscaleImperial = new this.Point(so.at.x, so.at.y + 8)
// Rotation // Rotation
if (so.rotate) { if (so.rotate) {
let points = [ let points = [
'__scaleboxMetricTopLeft', '__miniscaleMetricTopLeft',
'__scaleboxMetricTopRight', '__miniscaleMetricTopRight',
'__scaleboxMetricBottomLeft', '__miniscaleMetricBottomLeft',
'__scaleboxMetricBottomRight', '__miniscaleMetricBottomRight',
'__scaleboxImperialTopLeft', '__miniscaleImperialTopLeft',
'__scaleboxImperialTopRight', '__miniscaleImperialTopRight',
'__scaleboxImperialBottomLeft', '__miniscaleImperialBottomLeft',
'__scaleboxImperialBottomRight', '__miniscaleImperialBottomRight',
'__scaleboxMetric', '__miniscaleMetric',
'__scaleboxImperial' '__miniscaleImperial'
] ]
for (let pid of points) this.points[pid] = this.points[pid].rotate(so.rotate, so.at) for (let pid of points) this.points[pid] = this.points[pid].rotate(so.rotate, so.at)
for (let pid of points.slice(8)) { for (let pid of points.slice(8)) {
@ -58,25 +54,25 @@ export default function(so) {
} }
} }
// Paths // Paths
this.paths.__scaleboxImperial = new this.Path() this.paths.__miniscaleImperial = new this.Path()
.attr('class', 'scalebox imperial') .attr('class', 'scalebox imperial')
.move(this.points.__scaleboxImperialTopLeft) .move(this.points.__miniscaleImperialTopLeft)
.line(this.points.__scaleboxImperialBottomLeft) .line(this.points.__miniscaleImperialBottomLeft)
.line(this.points.__scaleboxImperialBottomRight) .line(this.points.__miniscaleImperialBottomRight)
.line(this.points.__scaleboxImperialTopRight) .line(this.points.__miniscaleImperialTopRight)
.close() .close()
this.paths.__scaleboxMetric = new this.Path() this.paths.__miniscaleMetric = new this.Path()
.attr('class', 'scalebox metric') .attr('class', 'scalebox metric')
.move(this.points.__scaleboxMetricTopLeft) .move(this.points.__miniscaleMetricTopLeft)
.line(this.points.__scaleboxMetricBottomLeft) .line(this.points.__miniscaleMetricBottomLeft)
.line(this.points.__scaleboxMetricBottomRight) .line(this.points.__miniscaleMetricBottomRight)
.line(this.points.__scaleboxMetricTopRight) .line(this.points.__miniscaleMetricTopRight)
.close() .close()
// Text // Text
this.points.__scaleboxMetric = this.points.__scaleboxMetric this.points.__miniscaleMetric = this.points.__miniscaleMetric
.attr('data-text', '2.5cm x 2.5cm') .attr('data-text', '2.5cm x 2.5cm')
.attr('data-text-class', 'text-xs center') .attr('data-text-class', 'text-xs center')
this.points.__scaleboxImperial = this.points.__scaleboxImperial this.points.__miniscaleImperial = this.points.__miniscaleImperial
.attr('data-text', '1" x 1"') .attr('data-text', '1" x 1"')
.attr('data-text-class', 'text-xs center ') .attr('data-text-class', 'text-xs center ')
} }

View file

@ -33,8 +33,8 @@ export default function(so) {
// Text anchor points // Text anchor points
this.points.__scaleboxLead = new this.Point(so.at.x - 45, so.at.y - 15) this.points.__scaleboxLead = new this.Point(so.at.x - 45, so.at.y - 15)
this.points.__scaleboxTitle = this.points.__scaleboxLead.shift(-90, 10) this.points.__scaleboxTitle = this.points.__scaleboxLead.shift(-90, 10)
this.points.__scaleboxText = this.points.__scaleboxTitle.shift(-90, 8) this.points.__scaleboxText = this.points.__scaleboxTitle.shift(-90, 12)
this.points.__scaleboxLink = this.points.__scaleboxText.shift(-90, 8) this.points.__scaleboxLink = this.points.__scaleboxText.shift(-90, 5)
this.points.__scaleboxMetric = new this.Point(so.at.x, so.at.y + 20) this.points.__scaleboxMetric = new this.Point(so.at.x, so.at.y + 20)
this.points.__scaleboxImperial = new this.Point(so.at.x, so.at.y + 24) this.points.__scaleboxImperial = new this.Point(so.at.x, so.at.y + 24)
// Rotation // Rotation
@ -80,7 +80,7 @@ export default function(so) {
.close() .close()
// Lead // Lead
this.points.__scaleboxLead = this.points.__scaleboxLead this.points.__scaleboxLead = this.points.__scaleboxLead
.attr('data-text', so.lead || 'freesewing') .attr('data-text', so.lead || 'FreeSewing')
.attr('data-text-class', 'text-sm') .attr('data-text-class', 'text-sm')
// Title // Title
if (so.title) this.points.__scaleboxTitle.attributes.set('data-text', so.title) if (so.title) this.points.__scaleboxTitle.attributes.set('data-text', so.title)
@ -95,9 +95,7 @@ export default function(so) {
this.points.__scaleboxText.attr('data-text', so.text) this.points.__scaleboxText.attr('data-text', so.text)
} else { } else {
this.points.__scaleboxText this.points.__scaleboxText
.attr('data-text', 'freesewingIsMadeByJoostDeCockAndContributors') .attr('data-text', 'supportFreesewingBecomeAPatron')
.attr('data-text', '\n')
.attr('data-text', 'withTheFinancialSupportOfOurPatrons')
this.points.__scaleboxLink = this.points.__scaleboxLink this.points.__scaleboxLink = this.points.__scaleboxLink
.attr('data-text', 'freesewing.org/patrons/join') .attr('data-text', 'freesewing.org/patrons/join')
.attr('data-text-class', 'text-xs fill-note') .attr('data-text-class', 'text-xs fill-note')