Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/plugin/__snapshots__/stencil-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class="x6-widget-stencil-group-content"
>
<div
class="x6-graph"
class="x6-graph x6-graph-pannable"
style="width: 200px; height: 800px;"
>
<div
Expand Down Expand Up @@ -141,7 +141,7 @@
class="x6-widget-stencil-group-content"
>
<div
class="x6-graph"
class="x6-graph x6-graph-pannable"
style="width: 200px; height: 800px;"
>
<div
Expand Down
4 changes: 2 additions & 2 deletions __tests__/plugin/__snapshots__/stencil-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class="x6-widget-stencil-group-content"
>
<div
class="x6-graph"
class="x6-graph x6-graph-pannable"
style="width: 200px; height: 800px;"
>
<div
Expand Down Expand Up @@ -141,7 +141,7 @@
class="x6-widget-stencil-group-content"
>
<div
class="x6-graph"
class="x6-graph x6-graph-pannable"
style="width: 200px; height: 800px;"
>
<div
Expand Down
4 changes: 2 additions & 2 deletions __tests__/plugin/__snapshots__/stencil-3.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
class="x6-widget-stencil-group-content"
>
<div
class="x6-graph"
class="x6-graph x6-graph-pannable"
style="width: 200px; height: 800px;"
>
<div
Expand Down Expand Up @@ -106,7 +106,7 @@
class="x6-widget-stencil-group-content"
>
<div
class="x6-graph"
class="x6-graph x6-graph-pannable"
style="width: 200px; height: 800px;"
>
<div
Expand Down
1 change: 1 addition & 0 deletions __tests__/plugin/scroller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function createMockGraph() {
container,
view: { grid: document.createElement('div'), background: null },
grid: { update: vi.fn(), draw: vi.fn(), clear: vi.fn() }, // ✅ mock grid
panning: { pannable: true },
transform: {
getScale: () => ({ sx: 1, sy: 1 }),
resize: vi.fn(),
Expand Down
2 changes: 1 addition & 1 deletion examples/src/pages/auto-resize/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { SplitBox } from '@antv/x6-react-components'
import React from 'react'
import '@antv/x6-react-components/es/split-box/style/index.css'
import { Graph, Scroller } from '@antv/x6'
import '../index.less'
Expand Down
5 changes: 3 additions & 2 deletions examples/src/pages/minimap/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { Radio } from 'antd'
import { Graph, MiniMap, Scroller } from '@antv/x6'
import { Radio } from 'antd'
import * as React from 'react'
import { SimpleNodeView } from './simple-view'
import './index.less'

Expand All @@ -19,6 +19,7 @@ export default class Example extends React.Component {
container: this.container,
width: 600,
height: 320,
panning: false,
background: {
color: '#F2F7FA',
},
Expand Down
5 changes: 3 additions & 2 deletions examples/src/pages/plugins/scroller/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Export, Graph, MiniMap, Scroller, Selection } from '@antv/x6'
import { Button } from 'antd'
import { Graph, Export, Selection, MiniMap, Scroller } from '@antv/x6'
import React from 'react'
import '../../index.less'
import './index.less'

Expand All @@ -23,6 +23,7 @@ export class ScrollerExample extends React.Component {
grid: {
visible: true,
},
panning: false,
mousewheel: {
enabled: true,
// fixed: false,
Expand Down
6 changes: 4 additions & 2 deletions examples/src/pages/virtual-render/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useRef } from 'react'
import { Graph, Cell, Scroller } from '@antv/x6'
import { type Cell, Graph, Scroller } from '@antv/x6'
import type React from 'react'
import { useEffect, useRef } from 'react'
import '../index.less'
import './index.less'

Expand All @@ -16,6 +17,7 @@ export const VirtualRenderExample: React.FC = () => {
height: 800,
grid: true,
mousewheel: true,
panning: false,
virtual: true,
})

Expand Down
2 changes: 1 addition & 1 deletion site/docs/api/graph/graph.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ new Graph(options: Options)
| height | `number` | | 画布高度,默认使用容器高度。 | - |
| scaling | `{ min?: number, max?: number }` | | 画布的最小最大缩放级别。 | `{ min: 0.01, max: 16 }` |
| [autoResize](/tutorial/basic/graph#画布大小) | `boolean \| Element \| Document` | | 是否监听容器大小改变,并自动更新画布大小。 | `false` |
| [panning](/api/graph/panning) | `boolean \| PanningManager.Options` | | 画布是否可以拖拽平移,默认禁用。 | `false` |
| [panning](/api/graph/panning) | `boolean \| PanningManager.Options` | | 画布是否可以拖拽平移,默认启用。 | `true` |
| [mousewheel](/api/graph/mousewheel) | `boolean \| MouseWheel.Options` | | 鼠标滚轮缩放,默认禁用。 | `false` |
| [grid](/api/graph/grid) | `boolean \| number \| GridManager.Options` | | 网格,默认使用 `10px` 的网格,但不绘制网格背景。 | `false` |
| [background](/api/graph/background) | `false \| BackgroundManager.Options` | | 背景,默认不绘制背景。 | `false` |
Expand Down
4 changes: 2 additions & 2 deletions site/docs/api/graph/panning.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ redirect_from:
普通画布(未使用 `scroller` 插件)通过开启 `panning` 选项来支持拖拽平移。

:::warning{title=注意}
不要同时使用 `scroller` 和 `panning`,因为两种形式在交互上有冲突。
不要同时使用 `scroller` 和 `panning`,因为两种形式在交互上有冲突。从 2.19.0 版本开始,`panning` 配置默认值为 `true` 。
:::

```ts
const graph = new Graph({
panning: true,
panning: true, // 不传该选项时,默认值也为 true
})

// 等同于
Expand Down
3 changes: 2 additions & 1 deletion site/docs/tutorial/plugins/scroller.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ redirect_from:
:::

:::warning{title=注意}
当同时使用 `Scroller` 插件的时候请不要同时开启画布的 `panning` 配置,因为两种形式在交互上有冲突。
当同时使用 `Scroller` 插件的时候请不要同时开启画布的 `panning` 配置,因为两种形式在交互上有冲突。从 2.19.0 版本开始,`panning` 配置默认值为 `true` 。
:::

## 使用
Expand All @@ -28,6 +28,7 @@ const graph = new Graph({
background: {
color: '#F2F7FA',
},
panning: false,
})
graph.use(
new Scroller({
Expand Down
1 change: 1 addition & 0 deletions site/src/tutorial/plugins/minimap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class Example extends React.Component {
container: this.container,
width: 600,
height: 320,
panning: false,
background: {
color: '#F2F7FA',
},
Expand Down
1 change: 1 addition & 0 deletions site/src/tutorial/plugins/scroller/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default class Example extends React.Component {

const graph = new Graph({
container: this.container,
panning: false,
background: {
color: '#F2F7FA',
},
Expand Down
4 changes: 2 additions & 2 deletions src/graph/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObjectExt } from '../common'
import type { Dom, Nilable } from '../common'
import { ObjectExt } from '../common'
import { Config } from '../config'
import type { Rectangle } from '../geometry'
import type { Graph } from '../graph'
Expand Down Expand Up @@ -417,7 +417,7 @@ export namespace Options {
background: false,

panning: {
enabled: false,
enabled: true,
eventTypes: ['leftMouseDown'],
},
mousewheel: {
Expand Down
4 changes: 2 additions & 2 deletions src/model/animation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObjectExt, KeyValue, Interp, Timing } from '../common'
import { Cell } from './cell'
import { Interp, type KeyValue, ObjectExt, Timing } from '../common'
import type { Cell } from './cell'

export class Animation {
protected readonly ids: { [path: string]: number } = {}
Expand Down
1 change: 1 addition & 0 deletions src/plugin/minimap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class MiniMap extends View implements Graph.Plugin {
grid: false,
background: false,
embedding: false,
panning: false,
}

this.targetGraph = this.options.createGraph
Expand Down
6 changes: 6 additions & 0 deletions src/plugin/scroller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,12 @@ export class Scroller
this.updateClassName(true)
this.scrollerImpl.startPanning(e)
this.scrollerImpl.once('pan:stop', () => this.updateClassName(false))

if (this.graph.panning.pannable) {
console.warn(
'Detected that graph.panning and scroll panning are both enabled, which may cause unexpected behavior.',
)
}
}
}

Expand Down