diagram-gost/src/modules/OutlineModule.ts

57 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-01-29 00:04:11 +03:00
import { Element } from 'diagram-js/lib/model/Types'
import { Outline } from 'diagram-js/lib/features/outline/OutlineProvider'
2025-01-18 05:56:20 +03:00
2025-01-29 00:04:11 +03:00
import { attr as svgAttr, create as svgCreate } from 'tiny-svg'
2025-01-29 00:04:11 +03:00
import Styles from 'diagram-js/lib/draw/Styles'
2025-01-29 00:04:11 +03:00
function CustomOutlineProvider(this: any, outline: Outline, styles: Styles) {
this._styles = styles
outline.registerProvider(this)
}
2025-01-29 00:04:11 +03:00
CustomOutlineProvider.$inject = ['outline', 'styles']
2025-01-29 00:04:11 +03:00
//CustomOutlineProvider.prototype.getOutline = function(element:Element) {
// if (element.type === 'mechanism') {
// const outline = svgCreate('circle');
//
// svgAttr(outline , {
// x: `${element.x}`,
// y: `${element.y}`,
// cx: element.width / 2,
// cy: element.height / 2,
// r: 60,
// fill: "none",
// });
// return outline;
// }
//}
2025-01-29 00:04:11 +03:00
CustomOutlineProvider.prototype.updateOutline = function (
element: Element,
outline: Outline
) {
if (element.type === 'mechanism') {
outline = svgCreate('rect')
svgAttr(outline, {
x: `${element.x}`,
y: `${element.y}`,
cx: element.width / 2,
cy: element.height / 2,
2025-01-29 00:04:11 +03:00
r: 60,
fill: 'none',
})
}
2025-01-29 00:04:11 +03:00
return false
}
2025-01-29 00:04:11 +03:00
import Ouline from 'diagram-js/lib/features/outline' // idk why it's called such way
2025-01-18 05:56:20 +03:00
export default {
__init__: ['outlineProvider'],
2025-01-29 00:04:11 +03:00
__depends__: [Ouline],
outlineProvider: ['type', CustomOutlineProvider],
}