2021-01-31 09:22:15 +01:00
|
|
|
export default function (so) {
|
2021-01-16 13:44:03 +01:00
|
|
|
// Passing `false` will remove the miniscale
|
|
|
|
if (so === false) {
|
|
|
|
for (let id of [
|
2021-01-16 14:10:00 +01:00
|
|
|
'__miniscaleMetricTopLeft',
|
|
|
|
'__miniscaleMetricTopRight',
|
|
|
|
'__miniscaleMetricBottomRight',
|
|
|
|
'__miniscaleMetricBottomLeft',
|
|
|
|
'__miniscaleImperialTopLeft',
|
|
|
|
'__miniscaleImperialTopRight',
|
|
|
|
'__miniscaleImperialBottomRight',
|
|
|
|
'__miniscaleImperialBottomLeft',
|
|
|
|
'__miniscaleMetric',
|
2021-04-24 10:16:31 +02:00
|
|
|
'__miniscaleImperial',
|
2021-01-16 13:44:03 +01:00
|
|
|
])
|
|
|
|
delete this.points[id]
|
2021-01-16 14:10:00 +01:00
|
|
|
for (let id of ['__miniscaleMetric', '__miniscaleImperial']) delete this.paths[id]
|
2021-01-16 13:44:03 +01:00
|
|
|
return true
|
|
|
|
}
|
2022-01-20 23:04:14 +01:00
|
|
|
|
|
|
|
const scale = this.context.settings.scale
|
|
|
|
|
|
|
|
// Convert scale to a value between 0 and 5, inclusive.
|
|
|
|
const scaleIndex = Math.ceil(6 * Math.max(0.1, Math.min(1, this.context.settings.scale))) - 1
|
|
|
|
|
|
|
|
// Metric size in mm / display value and imperial size in mm / display value for each scale index.
|
|
|
|
const sizes = [
|
|
|
|
[10, "1cm", 25.4 * 0.375, '⅜″'],
|
|
|
|
[13, "1.3cm", 25.4 * 0.5, '½″'],
|
|
|
|
[16, "1.6cm", 25.4 * 0.625, '⅝″'],
|
|
|
|
[19, "1.9cm", 25.4 * 0.75, '¾″'],
|
|
|
|
[22, "2.2cm", 25.4 * 0.875, '⅞″'],
|
|
|
|
[25, "2.5cm", 25.4 * 1, '1″'],
|
|
|
|
]
|
|
|
|
const m = sizes[scaleIndex][0] / 2
|
|
|
|
const i = sizes[scaleIndex][2] / 2
|
|
|
|
const metricDisplaySize = sizes[scaleIndex][1]
|
|
|
|
const imperialDisplaySize = sizes[scaleIndex][3]
|
2021-01-16 13:44:03 +01:00
|
|
|
// Box points
|
2021-01-16 14:10:00 +01:00
|
|
|
this.points.__miniscaleMetricTopLeft = 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.__miniscaleMetricBottomLeft = 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.__miniscaleImperialTopLeft = 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.__miniscaleImperialBottomLeft = 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)
|
2021-01-16 13:44:03 +01:00
|
|
|
// Text anchor points
|
2022-01-20 23:04:14 +01:00
|
|
|
this.points.__miniscaleMetric = new this.Point(so.at.x, so.at.y - 2 * scale)
|
|
|
|
this.points.__miniscaleImperial = new this.Point(so.at.x, so.at.y + 8 * scale)
|
2021-01-16 13:44:03 +01:00
|
|
|
// Rotation
|
|
|
|
if (so.rotate) {
|
|
|
|
let points = [
|
2021-01-16 14:10:00 +01:00
|
|
|
'__miniscaleMetricTopLeft',
|
|
|
|
'__miniscaleMetricTopRight',
|
|
|
|
'__miniscaleMetricBottomLeft',
|
|
|
|
'__miniscaleMetricBottomRight',
|
|
|
|
'__miniscaleImperialTopLeft',
|
|
|
|
'__miniscaleImperialTopRight',
|
|
|
|
'__miniscaleImperialBottomLeft',
|
|
|
|
'__miniscaleImperialBottomRight',
|
|
|
|
'__miniscaleMetric',
|
2021-04-24 10:16:31 +02:00
|
|
|
'__miniscaleImperial',
|
2021-01-16 13:44:03 +01:00
|
|
|
]
|
|
|
|
for (let pid of points) this.points[pid] = this.points[pid].rotate(so.rotate, so.at)
|
|
|
|
for (let pid of points.slice(8)) {
|
|
|
|
this.points[pid].attributes.set(
|
|
|
|
'data-text-transform',
|
|
|
|
`rotate(${so.rotate * -1}, ${this.points[pid].x}, ${this.points[pid].y})`
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Paths
|
2021-01-16 14:10:00 +01:00
|
|
|
this.paths.__miniscaleImperial = new this.Path()
|
2021-12-22 18:18:48 +01:00
|
|
|
.attr('class', 'scalebox imperial fill-current')
|
2021-01-16 14:10:00 +01:00
|
|
|
.move(this.points.__miniscaleImperialTopLeft)
|
|
|
|
.line(this.points.__miniscaleImperialBottomLeft)
|
|
|
|
.line(this.points.__miniscaleImperialBottomRight)
|
|
|
|
.line(this.points.__miniscaleImperialTopRight)
|
2021-01-16 13:44:03 +01:00
|
|
|
.close()
|
2021-01-16 14:10:00 +01:00
|
|
|
this.paths.__miniscaleMetric = new this.Path()
|
2021-12-22 18:18:48 +01:00
|
|
|
.attr('class', 'scalebox metric fill-bg')
|
2021-01-16 14:10:00 +01:00
|
|
|
.move(this.points.__miniscaleMetricTopLeft)
|
|
|
|
.line(this.points.__miniscaleMetricBottomLeft)
|
|
|
|
.line(this.points.__miniscaleMetricBottomRight)
|
|
|
|
.line(this.points.__miniscaleMetricTopRight)
|
2021-01-16 13:44:03 +01:00
|
|
|
.close()
|
|
|
|
// Text
|
2021-01-16 14:10:00 +01:00
|
|
|
this.points.__miniscaleMetric = this.points.__miniscaleMetric
|
2022-01-20 23:04:14 +01:00
|
|
|
.attr('data-text', `${metricDisplaySize} x ${metricDisplaySize}`)
|
2021-01-16 13:44:03 +01:00
|
|
|
.attr('data-text-class', 'text-xs center')
|
2021-01-16 14:10:00 +01:00
|
|
|
this.points.__miniscaleImperial = this.points.__miniscaleImperial
|
2022-01-20 23:04:14 +01:00
|
|
|
.attr('data-text', `${imperialDisplaySize} x ${imperialDisplaySize}`)
|
2021-01-16 13:44:03 +01:00
|
|
|
.attr('data-text-class', 'text-xs center ')
|
|
|
|
}
|