Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function fitTwoPages(graph: Graph, padding: Point = new Point()) {
if (!graph.pageVisible) {
// this.get('pageView').funct()
}
const fmt = graph.pageFormat
const ps = graph.pageScale
const cw = graph.container.clientWidth - 10
const ch = graph.container.clientHeight - 10
const scale =
Math.floor(20 * Math.min(cw / (2 * fmt.width) / ps, ch / fmt.height / ps)) /
20
graph.zoomTo(scale)
if (util.hasScrollbars(graph.container)) {
graph.container.scrollTop = Math.min(
padding.y,
(graph.container.scrollHeight - graph.container.clientHeight) / 2,
)
graph.container.scrollLeft = Math.min(
padding.x,
(graph.container.scrollWidth - graph.container.clientWidth) / 2,
)
}
}
resetScrollbars() {
const container = this.container
if (this.pageVisible && util.hasScrollbars(container)) {
const padding = this.getPagePadding()
container.scrollLeft = Math.floor(
Math.min(
padding[0],
(container.scrollWidth - container.clientWidth) / 2,
),
)
container.scrollTop = padding[1]
// Scrolls graph to visible area
const bounds = this.getGraphBounds()
if (bounds.width > 0 && bounds.height > 0) {
if (bounds.x > container.scrollLeft + container.clientWidth * 0.9) {
container.scrollLeft = Math.min(
bounds.x + bounds.width - container.clientWidth,
bounds.x - 10,
export function fitPage(graph: Graph, padding: Point = new Point()) {
if (!graph.pageVisible) {
// this.get('pageView').funct()
}
const fmt = graph.pageFormat
const ps = graph.pageScale
const cw = graph.container.clientWidth - 10
const ch = graph.container.clientHeight - 10
const scale =
Math.floor(20 * Math.min(cw / fmt.width / ps, ch / fmt.height / ps)) / 20
graph.zoomTo(scale)
if (util.hasScrollbars(graph.container)) {
graph.container.scrollTop = padding.y * graph.view.scale - 1
graph.container.scrollLeft =
Math.min(
padding.x * graph.view.scale,
(graph.container.scrollWidth - graph.container.clientWidth) / 2,
) - 1
}
}
if (this.cursorPosition != null) {
dx = this.container.offsetWidth / 2 - this.cursorPosition.x + offset.x
dy = this.container.offsetHeight / 2 - this.cursorPosition.y + offset.y
}
var prev = this.view.scale
this.zoom(this.cumulativeZoomFactor)
var s = this.view.scale
if (s != prev) {
// if (resize != null) {
// ui.chromelessResize(false, null, dx * (this.cumulativeZoomFactor - 1),
// dy * (this.cumulativeZoomFactor - 1))
// }
if (util.hasScrollbars(this.container) && (dx != 0 || dy != 0)) {
this.container.scrollLeft -= dx * (this.cumulativeZoomFactor - 1)
this.container.scrollTop -= dy * (this.cumulativeZoomFactor - 1)
}
}
this.cumulativeZoomFactor = 1
this.wheelZoomTimer = null
}, this.wheelZoomDelay)
}
export function fitPageWidth(graph: Graph, padding: Point = new Point()) {
if (!graph.pageVisible) {
// this.get('pageView').funct()
}
const fmt = graph.pageFormat
const ps = graph.pageScale
const cw = graph.container.clientWidth - 10
const scale = Math.floor((20 * cw) / fmt.width / ps) / 20
graph.zoomTo(scale)
if (util.hasScrollbars(graph.container)) {
graph.container.scrollLeft = Math.min(
padding.x * graph.view.scale,
(graph.container.scrollWidth - graph.container.clientWidth) / 2,
)
}
}
sizeDidChange() {
if (this.container && util.hasScrollbars(this.container)) {
const size = this.getPageSize()
const pages = this.getPageLayout()
const padding = this.getPagePadding()
const minw = Math.ceil(2 * padding[0] + pages.width * size.width)
const minh = Math.ceil(2 * padding[1] + pages.height * size.height)
const min = this.minGraphSize
if (min == null || min.width != minw || min.height != minh) {
this.minGraphSize = { width: minw, height: minh }
}
const dx = padding[0] - pages.x * size.width
const dy = padding[1] - pages.y * size.height
const s = this.view.scale
validate() {
if (this.graph.container && util.hasScrollbars(this.graph.container)) {
const size = this.graph.getPageSize()
const padding = this.graph.getPagePadding()
this.translate.x = padding[0] - (this.x0 || 0) * size.width
this.translate.y = padding[1] - (this.y0 || 0) * size.height
}
super.validate()
}