How to use the @antv/x6.util.hasScrollbars function in @antv/x6

To help you get started, we’ve selected a few @antv/x6 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github antvis / x6 / examples / x6-example-drawio / src / pages / graph / commands / util.ts View on Github external
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,
    )
  }
}
github antvis / x6 / examples / x6-example-drawio / src / pages / graph / graph.ts View on Github external
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,
github antvis / x6 / examples / x6-example-drawio / src / pages / graph / commands / util.ts View on Github external
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
  }
}
github antvis / x6 / examples / x6-example-drawio / src / pages / graph / graph.ts View on Github external
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)
  }
github antvis / x6 / examples / x6-example-drawio / src / pages / graph / commands / util.ts View on Github external
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,
    )
  }
}
github antvis / x6 / examples / x6-example-drawio / src / pages / graph / graph.ts View on Github external
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
github antvis / x6 / examples / x6-example-drawio / src / pages / graph / view.ts View on Github external
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()
  }