Skip to content

Commit

Permalink
fix: graph examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Jun 1, 2020
1 parent f80942a commit 23fb270
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
13 changes: 7 additions & 6 deletions examples/x6-example-features/src/pages/graph/attribute-card.tsx
Expand Up @@ -16,37 +16,38 @@ export class AttributeCard extends React.Component<

onWidthChanged = (width: number) => {
this.setState({ width }, () => {
this.props.onSizeChange(this.state.width, this.state.height)
console.log(width)
this.props.onSizeChange(width, this.state.height)
})
}

onHeightChanged = (height: number) => {
this.setState({ height }, () => {
this.props.onSizeChange(this.state.width, this.state.height)
this.props.onSizeChange(this.state.width, height)
})
}

onOriginXChanged = (originX: number) => {
this.setState({ originX }, () => {
this.props.onOriginChange(this.state.originX, this.state.originY)
this.props.onOriginChange(originX, this.state.originY)
})
}

onOriginYChanged = (originY: number) => {
this.setState({ originY }, () => {
this.props.onOriginChange(this.state.originX, this.state.originY)
this.props.onOriginChange(this.state.originX, originY)
})
}

onScaleXChanged = (scaleX: number) => {
this.setState({ scaleX }, () => {
this.props.onScaleChange(this.state.scaleX, this.state.scaleY)
this.props.onScaleChange(scaleX, this.state.scaleY)
})
}

onScaleYChanged = (scaleY: number) => {
this.setState({ scaleY }, () => {
this.props.onScaleChange(this.state.scaleX, this.state.scaleY)
this.props.onScaleChange(this.state.scaleX, scaleY)
})
}

Expand Down
2 changes: 1 addition & 1 deletion examples/x6-example-features/src/pages/graph/effect.ts
Expand Up @@ -3,7 +3,7 @@ import { FitToContentCard } from './fit-card'
import { ScaleContentToFitCard } from './scale-card'

export function createEffect(graph: Graph) {
const vSvg = Dom.createVector(graph.svgElem)
const vSvg = Dom.createVector(graph.view.svg)
const vVertical = Dom.createVector('path').attr('d', 'M -10000 -1 L 10000 -1')
const vHorizontal = Dom.createVector('path').attr(
'd',
Expand Down
22 changes: 12 additions & 10 deletions examples/x6-example-features/src/pages/graph/index.tsx
Expand Up @@ -37,8 +37,10 @@ export default class Example extends React.Component<
container: this.container,
width: 600,
height: 400,
gridSize: 10,
defaultConnectionPoint: { name: 'anchor' },
grid: { visible: true },
connecting: {
connectionPoint: 'anchor',
},
})

render(this.graph)
Expand All @@ -51,8 +53,8 @@ export default class Example extends React.Component<
...prevState.attrs,
width: options.width,
height: options.height,
originX: options.origin.x,
originY: options.origin.y,
originX: options.x,
originY: options.y,
},
}))

Expand Down Expand Up @@ -106,14 +108,14 @@ export default class Example extends React.Component<
this.container = container
}

onBackgroundChanged = (res: Graph.BackgroundOptions) => {
this.graph.drawBackground(res)
onBackgroundChanged = (
options: Graph.BackgroundManager.BackgroundOptions,
) => {
this.graph.drawBackground(options)
}

onGridChanged = (options: Grid.NativeItem) => {
console.log(options)
this.graph.setGrid(options)
this.graph.drawGrid()
onGridChanged = (options: Graph.GridManager.NativeItem) => {
this.graph.drawGrid(options)
}

onGridSizeChanged = (size: number) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/x6-example-features/src/pages/hull/index.tsx
Expand Up @@ -52,7 +52,7 @@ export default class Example extends React.Component {
'stroke-width': 3,
})

Dom.createVector(graph.drawPane).prepend(boundary)
Dom.createVector(graph.view.stage).prepend(boundary)

return boundary
}
Expand Down
4 changes: 2 additions & 2 deletions packages/x6/src/definition/grid/index.ts
Expand Up @@ -92,12 +92,12 @@ export namespace Grid {
export type NativeNames = keyof Presets

export interface NativeItem<T extends NativeNames = NativeNames> {
type: T
name: T
args?: OptionsMap[T]
}

export interface ManaualItem {
type: Exclude<string, NativeNames>
name: Exclude<string, NativeNames>
args?: KeyValue
}
}
8 changes: 4 additions & 4 deletions packages/x6/src/graph/grid.ts
Expand Up @@ -141,8 +141,8 @@ export class GridManager extends Base {
return []
}

const type = (options as GridDefinition.NativeItem).type
if (type == null) {
const name = (options as GridDefinition.NativeItem).name
if (name == null) {
return [
{
...GridDefinition.presets.dot,
Expand All @@ -151,7 +151,7 @@ export class GridManager extends Base {
]
}

const items = GridDefinition.registry.get(type)
const items = GridDefinition.registry.get(name)
if (items) {
let args = options.args || []
if (!Array.isArray(args)) {
Expand All @@ -163,7 +163,7 @@ export class GridManager extends Base {
: [{ ...items, ...args[0] }]
}

return GridDefinition.registry.onNotFound(type)
return GridDefinition.registry.onNotFound(name)
}

@Base.dispose()
Expand Down

0 comments on commit 23fb270

Please sign in to comment.