2022-02-20 18:46:21 +01:00
|
|
|
const name = 'Pages Plugin'
|
|
|
|
const version = '1.0.0'
|
2022-08-16 00:33:35 -05:00
|
|
|
export const sizes = {
|
2022-10-28 15:03:04 -05:00
|
|
|
a4: [210, 297],
|
|
|
|
a3: [297, 420],
|
|
|
|
a2: [420, 594],
|
|
|
|
a1: [594, 841],
|
|
|
|
a0: [841, 1188],
|
|
|
|
letter: [215.9, 279.4],
|
|
|
|
tabloid: [279.4, 431.8],
|
2022-02-20 18:46:21 +01:00
|
|
|
}
|
|
|
|
|
2022-08-24 18:15:03 -05:00
|
|
|
/** get a letter to represent an index less than 26*/
|
2022-08-17 00:34:25 -05:00
|
|
|
const indexLetter = (i) => String.fromCharCode('A'.charCodeAt(0) + i - 1)
|
|
|
|
|
2022-08-24 18:15:03 -05:00
|
|
|
/** get a string of letters to represent an index */
|
|
|
|
const indexStr = (i) => {
|
|
|
|
let index = i % 26
|
|
|
|
let quotient = i / 26
|
|
|
|
let result
|
|
|
|
|
2022-10-28 15:03:04 -05:00
|
|
|
if (i <= 26) {
|
|
|
|
return indexLetter(i)
|
|
|
|
} //Number is within single digit bounds of our encoding letter alphabet
|
2022-08-24 18:15:03 -05:00
|
|
|
|
|
|
|
if (quotient >= 1) {
|
2022-10-28 15:03:04 -05:00
|
|
|
//This number was bigger than the alphabet, recursively perform this function until we're done
|
|
|
|
if (index === 0) {
|
|
|
|
quotient--
|
|
|
|
} //Accounts for the edge case of the last letter in the dictionary string
|
|
|
|
result = indexStr(quotient)
|
2022-08-24 18:15:03 -05:00
|
|
|
}
|
|
|
|
|
2022-10-28 15:03:04 -05:00
|
|
|
if (index === 0) {
|
|
|
|
index = 26
|
|
|
|
} //Accounts for the edge case of the final letter; avoids getting an empty string
|
2022-08-24 18:15:03 -05:00
|
|
|
|
|
|
|
return result + indexLetter(index)
|
|
|
|
}
|
2022-08-17 13:11:22 -05:00
|
|
|
/**
|
|
|
|
* A plugin to add printer pages
|
|
|
|
* */
|
2022-10-28 15:03:04 -05:00
|
|
|
export const pagesPlugin = ({ size = 'a4', ...settings }) => {
|
2022-08-22 14:57:44 +01:00
|
|
|
const ls = settings.orientation === 'landscape'
|
2022-08-21 10:26:35 +01:00
|
|
|
let sheetHeight = sizes[size][ls ? 0 : 1]
|
|
|
|
let sheetWidth = sizes[size][ls ? 1 : 0]
|
2022-08-22 14:57:44 +01:00
|
|
|
sheetWidth -= settings.margin * 2
|
|
|
|
sheetHeight -= settings.margin * 2
|
|
|
|
|
2022-10-28 15:03:04 -05:00
|
|
|
return basePlugin({ ...settings, sheetWidth, sheetHeight })
|
2022-08-16 00:33:35 -05:00
|
|
|
}
|
|
|
|
|
2022-12-12 10:14:28 -06:00
|
|
|
/** check if there is anything to render on the given section of the svg so that we can skip empty pages */
|
2022-11-14 14:02:11 -06:00
|
|
|
const doScanForBlanks = (stacks, layout, x, y, w, h) => {
|
2022-08-21 10:26:35 +01:00
|
|
|
let hasContent = false
|
2022-11-14 14:02:11 -06:00
|
|
|
for (var s in stacks) {
|
|
|
|
let stack = stacks[s]
|
2022-08-21 10:26:35 +01:00
|
|
|
|
|
|
|
// get the position of the part
|
2022-11-14 14:02:11 -06:00
|
|
|
let stackLayout = layout.stacks[s]
|
|
|
|
if (!stackLayout) continue
|
2022-08-21 10:26:35 +01:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
let stackMinX = stackLayout.tl?.x || stackLayout.move.x + stack.topLeft.x
|
|
|
|
let stackMinY = stackLayout.tl?.y || stackLayout.move.y + stack.topLeft.y
|
|
|
|
let stackMaxX = stackLayout.br?.x || stackMinX + stack.width
|
|
|
|
let stackMaxY = stackLayout.br?.y || stackMinY + stack.height
|
|
|
|
|
|
|
|
// check if the stack overlaps the page extents
|
2022-08-21 10:26:35 +01:00
|
|
|
if (
|
2022-11-14 14:02:11 -06:00
|
|
|
// if the left of the stack is further left than the right end of the page
|
|
|
|
stackMinX < x + w &&
|
|
|
|
// and the top of the stack is above the bottom of the page
|
|
|
|
stackMinY < y + h &&
|
|
|
|
// and the right of the stack is further right than the left of the page
|
|
|
|
stackMaxX > x &&
|
|
|
|
// and the bottom of the stack is below the top to the page
|
|
|
|
stackMaxY > y
|
2022-10-28 15:03:04 -05:00
|
|
|
) {
|
2022-11-14 14:02:11 -06:00
|
|
|
// the stack has content inside the page
|
2022-10-28 15:03:04 -05:00
|
|
|
hasContent = true
|
2022-08-21 10:26:35 +01:00
|
|
|
// so we stop looking
|
2022-10-28 15:03:04 -05:00
|
|
|
break
|
2022-08-21 10:26:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hasContent
|
|
|
|
}
|
2022-10-28 15:03:04 -05:00
|
|
|
|
2022-08-17 13:11:22 -05:00
|
|
|
/**
|
|
|
|
* The base plugin for adding a layout helper part like pages or fabric
|
|
|
|
* sheetWidth: the width of the helper part
|
|
|
|
* sheetHeight: the height of the helper part
|
|
|
|
* boundary: should the helper part calculate its boundary?
|
|
|
|
* responsiveColumns: should the part make more columns if the pattern exceed its width? (for pages you want this, for fabric you don't)
|
|
|
|
* printStyle: hould the pages be rendered for printing or for screen viewing?
|
|
|
|
* */
|
|
|
|
const basePlugin = ({
|
|
|
|
sheetWidth,
|
|
|
|
sheetHeight,
|
2022-11-14 16:53:31 -06:00
|
|
|
// boundary = false,
|
2022-10-28 15:03:04 -05:00
|
|
|
partName = 'pages',
|
|
|
|
responsiveColumns = true,
|
|
|
|
printStyle = false,
|
|
|
|
scanForBlanks = true,
|
|
|
|
renderBlanks = true,
|
|
|
|
setPatternSize = false,
|
2022-08-17 13:11:22 -05:00
|
|
|
}) => ({
|
2022-02-20 18:46:21 +01:00
|
|
|
name,
|
|
|
|
version,
|
|
|
|
hooks: {
|
2022-11-14 14:02:11 -06:00
|
|
|
preLayout: function (pattern) {
|
2022-10-28 15:03:04 -05:00
|
|
|
// Add part
|
|
|
|
pattern.addPart({
|
|
|
|
name: partName,
|
|
|
|
draft: (shorthand) => {
|
2022-11-14 14:02:11 -06:00
|
|
|
const layoutData = shorthand.store.get('layoutData')
|
2022-12-12 10:14:28 -06:00
|
|
|
// only actually draft the part if layout data has been set
|
2022-11-14 14:02:11 -06:00
|
|
|
if (layoutData) {
|
|
|
|
shorthand.macro('addPages', layoutData, shorthand)
|
|
|
|
shorthand.part.unhide()
|
|
|
|
} else {
|
|
|
|
shorthand.part.hide()
|
|
|
|
}
|
2022-10-28 15:03:04 -05:00
|
|
|
return shorthand.part
|
|
|
|
},
|
|
|
|
})
|
2022-12-12 10:14:28 -06:00
|
|
|
|
|
|
|
// Re-calculate the pattern's config
|
2022-10-28 15:03:04 -05:00
|
|
|
pattern.getConfig()
|
2022-12-12 10:14:28 -06:00
|
|
|
// create the part so that a stack gets made for it during packing
|
|
|
|
// but don't draft it so that it doesn't have a size
|
2022-11-14 14:02:11 -06:00
|
|
|
pattern.createPartForSet(partName, pattern.activeSet)
|
|
|
|
},
|
|
|
|
postLayout: function (pattern) {
|
|
|
|
let { height, width, stacks } = pattern
|
|
|
|
if (!responsiveColumns) width = sheetWidth
|
2022-12-12 10:14:28 -06:00
|
|
|
// get the layout
|
2022-10-28 15:03:04 -05:00
|
|
|
const layout =
|
2022-11-14 14:02:11 -06:00
|
|
|
typeof pattern.settings[0].layout === 'object'
|
|
|
|
? pattern.settings[0].layout
|
|
|
|
: pattern.autoLayout
|
|
|
|
|
2022-12-12 10:14:28 -06:00
|
|
|
// if the layout doesn't start at 0,0 we want to account for that in our height and width
|
2022-11-14 14:02:11 -06:00
|
|
|
if (layout?.topLeft) {
|
|
|
|
height += layout.topLeft.y
|
|
|
|
responsiveColumns && (width += layout.topLeft.x)
|
|
|
|
}
|
|
|
|
|
2022-12-12 10:14:28 -06:00
|
|
|
// store the layout data so the part can use it during drafting
|
2022-11-14 14:02:11 -06:00
|
|
|
pattern.setStores[pattern.activeSet].set('layoutData', {
|
|
|
|
size: [sheetHeight, sheetWidth],
|
|
|
|
height,
|
|
|
|
width,
|
|
|
|
layout,
|
|
|
|
stacks,
|
|
|
|
})
|
2022-12-12 10:14:28 -06:00
|
|
|
|
|
|
|
// draft the part
|
2022-11-14 14:02:11 -06:00
|
|
|
pattern.draftPartForSet(partName, pattern.activeSet)
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2022-12-12 10:14:28 -06:00
|
|
|
// if the pattern size is supposed to be re-set to the full width and height of all pages, do that
|
2022-08-21 10:26:35 +01:00
|
|
|
if (setPatternSize) {
|
2022-11-14 14:02:11 -06:00
|
|
|
const generatedPageData = pattern.setStores[pattern.activeSet].get('pages')
|
|
|
|
pattern.width = sheetWidth * generatedPageData.cols
|
|
|
|
pattern.height = sheetHeight * generatedPageData.rows
|
2022-08-21 10:26:35 +01:00
|
|
|
}
|
2022-10-28 15:03:04 -05:00
|
|
|
},
|
2022-12-13 08:39:16 -06:00
|
|
|
preRender: function (svg) {
|
|
|
|
const pattern = svg.pattern
|
|
|
|
const only = pattern.settings[pattern.activeStack || 0].only
|
|
|
|
// add the layout part to the include list if there is one so that it gets rendered
|
|
|
|
if (Array.isArray(only) && !only.includes(partName)) {
|
|
|
|
pattern.settings[pattern.activeStack || 0].only.push(partName)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
postRender: function (svg) {
|
|
|
|
const pattern = svg.pattern
|
|
|
|
const only = pattern.settings[pattern.activeStack || 0].only
|
|
|
|
// remove the layout part from the include list if there is one so that we don't pollute the settings
|
|
|
|
if (Array.isArray(only) && only.includes(partName)) {
|
|
|
|
pattern.settings[pattern.activeStack || 0].only.splice(only.indexOf(partName), 1)
|
|
|
|
}
|
|
|
|
},
|
2022-02-20 18:46:21 +01:00
|
|
|
},
|
2022-11-14 14:02:11 -06:00
|
|
|
macros: {
|
|
|
|
/** draft the pages */
|
|
|
|
addPages: function (so, shorthand) {
|
|
|
|
const [h, w] = so.size
|
|
|
|
const cols = Math.ceil(so.width / w)
|
|
|
|
const rows = Math.ceil(so.height / h)
|
2022-11-14 16:37:21 -06:00
|
|
|
const { points, Point, paths, Path, part, macro, store } = shorthand
|
2022-11-14 14:02:11 -06:00
|
|
|
let count = 0
|
|
|
|
let withContent = {}
|
2022-11-14 16:37:21 -06:00
|
|
|
part.topLeft = so.layout.topLeft || { x: 0, y: 0 }
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
// get the layout from the pattern
|
|
|
|
const { layout } = so
|
|
|
|
for (let row = 0; row < rows; row++) {
|
|
|
|
let y = row * h
|
|
|
|
withContent[row] = {}
|
|
|
|
for (let col = 0; col < cols; col++) {
|
|
|
|
let x = col * w
|
|
|
|
let hasContent = true
|
|
|
|
if (scanForBlanks && layout) {
|
|
|
|
hasContent = doScanForBlanks(so.stacks, layout, x, y, w, h)
|
|
|
|
}
|
|
|
|
withContent[row][col] = hasContent
|
|
|
|
if (!renderBlanks && !hasContent) continue
|
|
|
|
if (hasContent) count++
|
|
|
|
const pageName = `_pages__row${row}-col${col}`
|
|
|
|
points[`${pageName}-tl`] = new Point(x, y)
|
|
|
|
points[`${pageName}-tr`] = new Point(x + w, y)
|
|
|
|
points[`${pageName}-br`] = new Point(x + w, y + h)
|
|
|
|
points[`${pageName}-bl`] = new Point(x, y + h)
|
|
|
|
points[`${pageName}-circle`] = new Point(x + w / 2, y + h / 2)
|
|
|
|
.setCircle(56, 'stroke-4xl muted fabric')
|
|
|
|
.attr('data-circle-id', `${pageName}-circle`)
|
|
|
|
points[`${pageName}-text`] = new Point(x + w / 2, y + h / 2)
|
|
|
|
.setText(
|
|
|
|
`${indexStr(col + 1)}${row + 1}`,
|
|
|
|
'text-4xl center baseline-center bold muted fill-fabric'
|
|
|
|
)
|
|
|
|
.attr('data-text-id', `${pageName}-text`)
|
2022-03-06 18:54:30 +01:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
paths[pageName] = new Path()
|
|
|
|
.attr('id', pageName)
|
|
|
|
.move(points[`${pageName}-tl`])
|
|
|
|
.line(points[`${pageName}-bl`])
|
|
|
|
.line(points[`${pageName}-br`])
|
|
|
|
.line(points[`${pageName}-tr`])
|
|
|
|
.close()
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
if (col === cols - 1 && row === rows - 1) {
|
|
|
|
const br = points[`${pageName}-br`]
|
2022-11-14 16:37:21 -06:00
|
|
|
part.width = br.x
|
|
|
|
part.height = br.y
|
|
|
|
part.bottomRight = { x: br.x, y: br.y }
|
2022-11-14 14:02:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!printStyle) {
|
|
|
|
paths[pageName]
|
|
|
|
.attr('class', 'fill-fabric')
|
|
|
|
.attr(
|
|
|
|
'style',
|
|
|
|
`stroke-opacity: 0; fill-opacity: ${(col + row) % 2 === 0 ? 0.03 : 0.09};`
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
paths[pageName].attr('class', 'interfacing stroke-xs')
|
|
|
|
// add markers and rulers
|
2022-11-14 16:37:21 -06:00
|
|
|
macro('addPageMarkers', { row, col, pageName, withContent }, shorthand)
|
|
|
|
macro('addRuler', { xAxis: true, pageName }, shorthand)
|
|
|
|
macro('addRuler', { xAxis: false, pageName }, shorthand)
|
2022-11-14 14:02:11 -06:00
|
|
|
}
|
2022-10-28 15:03:04 -05:00
|
|
|
}
|
|
|
|
}
|
2022-11-14 14:02:11 -06:00
|
|
|
// Store page count in part
|
2022-11-14 16:37:21 -06:00
|
|
|
store.set(partName, { cols, rows, count, withContent, width: w, height: h })
|
2022-11-14 14:02:11 -06:00
|
|
|
},
|
|
|
|
/** add a ruler to the top left corner of the page */
|
|
|
|
addRuler({ xAxis, pageName }, shorthand) {
|
|
|
|
const { points, paths, Path } = shorthand
|
|
|
|
const isMetric = this.context.settings.units === 'metric'
|
2023-02-06 18:07:23 -08:00
|
|
|
// not so arbitrary number of units for the ruler
|
|
|
|
const rulerLength = isMetric ? 10 : 2
|
2022-11-14 14:02:11 -06:00
|
|
|
// distance to the end of the ruler
|
|
|
|
const endPointDist = [(isMetric ? 10 : 25.4) * rulerLength, 0]
|
2022-08-17 13:11:22 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
const axisName = xAxis ? 'x' : 'y'
|
|
|
|
const rulerName = `${pageName}-${axisName}`
|
|
|
|
// start by making an endpoint for the ruler based on the axis
|
|
|
|
const endPoint = [endPointDist[xAxis ? 0 : 1], endPointDist[xAxis ? 1 : 0]]
|
|
|
|
points[`${rulerName}-ruler-end`] = points[`${pageName}-tl`].translate(
|
|
|
|
endPoint[0],
|
|
|
|
endPoint[1]
|
|
|
|
)
|
|
|
|
// also make a tick for the end of the ruler
|
|
|
|
points[`${rulerName}-ruler-tick`] = points[`${rulerName}-ruler-end`]
|
|
|
|
.translate(xAxis ? 0 : 3, xAxis ? 3 : 0)
|
|
|
|
// add a label to it
|
2023-02-02 10:40:08 -06:00
|
|
|
.attr('data-text', rulerLength + (isMetric ? 'cm' : '"'))
|
2022-11-14 14:02:11 -06:00
|
|
|
// space the text properly from the end of the line
|
|
|
|
.attr('data-text-class', 'fill-interfacing baseline-center' + (xAxis ? ' center' : ''))
|
|
|
|
.attr(`data-text-d${xAxis ? 'y' : 'x'}`, xAxis ? 5 : 3)
|
|
|
|
// give the text an explicit id in case we need to hide it later
|
|
|
|
.attr('data-text-id', `${rulerName}-ruler-text`)
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
// start the path
|
|
|
|
paths[`${rulerName}-ruler`] = new Path()
|
|
|
|
.move(points[`${pageName}-tl`])
|
|
|
|
// give it an explicit id in case we need to hide it later
|
|
|
|
.attr('id', `${rulerName}-ruler`)
|
|
|
|
.attr('class', 'interfacing stroke-xs')
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
// get the distance between the smaller ticks on the rule
|
|
|
|
const division = (isMetric ? 0.1 : 0.125) / rulerLength
|
|
|
|
// we're going to go by fraction, so we want to do this up to 1
|
|
|
|
for (var d = division; d < 1; d += division) {
|
|
|
|
// make a start point
|
|
|
|
points[`${rulerName}-ruler-${d}-end`] = points[`${pageName}-tl`].shiftFractionTowards(
|
|
|
|
points[`${rulerName}-ruler-end`],
|
|
|
|
d
|
|
|
|
)
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
// base tick size on whether this is a major interval or a minor one
|
|
|
|
let tick = 1
|
|
|
|
// if this tick indicates a whole unit, extra long
|
|
|
|
if (d.toFixed(3) % (1 / rulerLength) === 0) tick = 3
|
|
|
|
// if this tick indicates half a unit, long
|
|
|
|
else if (d.toFixed(3) % (0.5 / rulerLength) === 0) tick = 2
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
// make a point for the end of the tick
|
|
|
|
points[`${rulerName}-ruler-${d}-tick`] = points[`${rulerName}-ruler-${d}-end`].translate(
|
|
|
|
xAxis ? 0 : tick,
|
|
|
|
xAxis ? tick : 0
|
|
|
|
)
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
// add the whole set to the ruler path
|
|
|
|
paths[`${rulerName}-ruler`]
|
|
|
|
.line(points[`${rulerName}-ruler-${d}-end`])
|
|
|
|
.line(points[`${rulerName}-ruler-${d}-tick`])
|
|
|
|
.line(points[`${rulerName}-ruler-${d}-end`])
|
|
|
|
}
|
2022-10-28 15:03:04 -05:00
|
|
|
|
2022-11-14 14:02:11 -06:00
|
|
|
// add the end
|
|
|
|
paths[`${rulerName}-ruler`]
|
|
|
|
.line(points[`${rulerName}-ruler-end`])
|
|
|
|
.line(points[`${rulerName}-ruler-tick`])
|
|
|
|
},
|
|
|
|
/** add page markers to the given page */
|
|
|
|
addPageMarkers({ row, col, pageName, withContent }, shorthand) {
|
|
|
|
const { macro, points } = shorthand
|
|
|
|
// these markers are placed on the top and left of the page,
|
|
|
|
// so skip markers for the top row or leftmost column
|
|
|
|
if (row !== 0 && withContent[row - 1][col])
|
|
|
|
macro('addPageMarker', {
|
2023-02-02 10:40:08 -06:00
|
|
|
along: [points[`${pageName}-tr`], points[`${pageName}-tl`]],
|
|
|
|
label: [`${row}`, `${row + 1}`],
|
2022-11-14 14:02:11 -06:00
|
|
|
isRow: true,
|
|
|
|
pageName,
|
|
|
|
})
|
|
|
|
if (col !== 0 && withContent[row][col - 1])
|
|
|
|
macro('addPageMarker', {
|
|
|
|
along: [points[`${pageName}-tl`], points[`${pageName}-bl`]],
|
2023-02-02 10:40:08 -06:00
|
|
|
label: [indexStr(col), indexStr(col + 1)],
|
2022-11-14 14:02:11 -06:00
|
|
|
isRow: false,
|
|
|
|
pageName,
|
|
|
|
})
|
|
|
|
},
|
2023-02-02 10:40:08 -06:00
|
|
|
/** add a page marker for either the row or the column, to aid with alignment and orientation */
|
2022-11-14 14:02:11 -06:00
|
|
|
addPageMarker({ along, label, isRow, pageName }) {
|
2023-02-02 10:40:08 -06:00
|
|
|
const { points, paths, Path, scale } = this.shorthand()
|
2022-11-14 14:02:11 -06:00
|
|
|
const markerName = `${pageName}-${isRow ? 'row' : 'col'}-marker`
|
2022-08-17 13:11:22 -05:00
|
|
|
|
2023-02-02 10:40:08 -06:00
|
|
|
// x and y distances between corners. one will always be 0, which is helpful
|
|
|
|
const xDist = along[0].dx(along[1])
|
|
|
|
const yDist = along[0].dy(along[1])
|
|
|
|
|
|
|
|
// size of the x mark should be impacted by the scale setting
|
|
|
|
const markSize = 4 * scale
|
|
|
|
|
|
|
|
// make one at 25% and one at 75%
|
|
|
|
for (var d = 25; d < 100; d += 50) {
|
|
|
|
// get points to make an x at d% along the edge
|
|
|
|
const dName = `${markerName}-${d}`
|
|
|
|
const centerName = `${dName}-center`
|
|
|
|
points[centerName] = along[0].translate((xDist * d) / 100, (yDist * d) / 100)
|
|
|
|
points[`${dName}-tr`] = points[centerName].translate(-markSize, markSize)
|
|
|
|
points[`${dName}-tl`] = points[centerName].translate(-markSize, -markSize)
|
|
|
|
points[`${dName}-br`] = points[centerName].translate(markSize, markSize)
|
|
|
|
points[`${dName}-bl`] = points[centerName].translate(markSize, -markSize)
|
|
|
|
|
|
|
|
// make a path for the x
|
|
|
|
paths[`${dName}`] = new Path()
|
|
|
|
.move(points[`${dName}-tr`])
|
|
|
|
.line(points[`${dName}-bl`])
|
|
|
|
.move(points[`${dName}-tl`])
|
|
|
|
.line(points[`${dName}-br`])
|
|
|
|
.attr('class', 'interfacing stroke-xs')
|
|
|
|
// give it an explicit ID in case we need to hide it later
|
|
|
|
.attr('id', dName)
|
|
|
|
|
|
|
|
// add directional labels
|
|
|
|
let angle = along[0].angle(along[1]) - 90
|
|
|
|
for (var i = 0; i < 2; i++) {
|
|
|
|
points[`${dName}-label-${i + 1}`] = points[centerName]
|
|
|
|
.shift(angle, markSize)
|
|
|
|
.setText(label[i], 'text-xs center baseline-center fill-interfacing')
|
|
|
|
// give it an explicit ID in case we need to hide it later
|
|
|
|
.attr('data-text-id', `${dName}-text-${i + 1}`)
|
|
|
|
// rotate for the next one
|
|
|
|
angle += 180
|
|
|
|
}
|
|
|
|
}
|
2022-11-14 14:02:11 -06:00
|
|
|
},
|
2022-10-28 15:03:04 -05:00
|
|
|
},
|
2022-11-14 14:02:11 -06:00
|
|
|
})
|