/*! * Copyright (c) 2023, 2024, Oracle and/or its affiliates. */ /** * @file * * Extended joint.ui.PaperScroller with additional functionality and/or overrides. * * PaperScroller wraps the Paper and enables panning, etc. */ const { ui } = joint; export default class PaperScroller extends ui.PaperScroller { scrollToLink(link, opt = {}) { const { ratio = 0, animation } = opt; const { paper } = this.options; const { _sx: sx, _sy: sy } = this; const view = link.findView(paper); const point = view.getPointAtRatio(ratio); const scrollPoint = point.scale(sx, sy); return this.scroll(scrollPoint.x, scrollPoint.y, { animation }); } // Override to account for padding isElementVisible(element, opt = {}) { const { padding = 0, strict = false } = opt; this.checkElement(element, 'isElementVisible'); const bbox = element.getBBox(); if (strict) { // keep the padding independent on the zoom level bbox.inflate(padding / this.zoom()); return !!this.getVisibleArea().containsRect(bbox); } else { return !!this.getVisibleArea().intersect(bbox); } } // Override to account for padding isPointVisible(point, opt = {}) { const { padding = 0 } = opt; const visArea = this.getVisibleArea(); if (padding) { // keep the padding independent on the zoom level visArea.inflate(-padding / this.zoom()); } return visArea.containsPoint(point); } startAutoResizePaper() { const { options } = this; const { paper, autoResizePaper } = options; if (!autoResizePaper) { options.autoResizePaper = true; this.listenTo(paper, 'render:done', this.onPaperRenderDone); this.adjustPaper(); } } stopAutoResizePaper() { const { options } = this; const { paper, autoResizePaper } = options; if (autoResizePaper) { options.autoResizePaper = false; this.stopListening(paper, 'render:done', this.onPaperRenderDone); } } }