-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
169 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
168 changes: 168 additions & 0 deletions
168
examples/x6-example-features/src/pages/v1/performance/shapes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import React from 'react' | ||
import { Button } from 'antd' | ||
import { joint } from '@antv/x6' | ||
import '../../index.less' | ||
import '../index.less' | ||
|
||
// Overall goals | ||
// ------------- | ||
// 1. reduce number of DOM elements | ||
// 2. avoid asking the browser for element bounding boxes as much as possible | ||
|
||
// Number of elements 0 - ? | ||
var COUNT = 500 | ||
// Async rendering true/false | ||
// true: does not block the UI | ||
var ASYNC = false | ||
|
||
const Node = joint.NodeRegistry.register('performance_node', { | ||
size: { | ||
width: 100, | ||
height: 50, | ||
}, | ||
zIndex: 2, | ||
attrs: { | ||
body: { | ||
// Using of special 'ref-like` attributes it's not generally the most | ||
// performer. In this particular case it's different though. | ||
// If the `ref` attribute is not defined all the metrics (width, height, x, y) | ||
// are taken from the model. There is no need to ask the browser for | ||
// an element bounding box. | ||
// All calculation are done just in Javascript === very fast. | ||
refWidth: '100%', | ||
refHeight: '100%', | ||
stroke: 'red', | ||
strokeWidth: 2, | ||
fill: 'lightgray', | ||
rx: 5, | ||
ry: 5, | ||
}, | ||
label: { | ||
fill: 'black', | ||
// Please see the `ref-width` & `ref-height` comment. | ||
refX: '50%', | ||
refY: '50%', | ||
// Do not use special attribute `x-alignment` when not necessary. | ||
// It calls getBBox() on the SVGText element internally. Measuring text | ||
// in the browser is usually the slowest. | ||
// `text-anchor` attribute does the same job here (works for the text elements only). | ||
textAnchor: 'middle', | ||
// Do not use special attribute `y-alignment` for text vertical positioning. See above. | ||
textVerticalAnchor: 'middle', | ||
}, | ||
}, | ||
// if markup does not change during the application life time, define it on the prototype (i.e. not in the defaults above) | ||
markup: [ | ||
{ | ||
tagName: 'rect', | ||
selector: 'body', | ||
}, | ||
{ | ||
tagName: 'text', | ||
selector: 'label', | ||
}, | ||
], | ||
}) | ||
|
||
const Edge = joint.EdgeRegistry.register('performance_edge', { | ||
zIndex: 1, | ||
attrs: { | ||
line: { | ||
connection: true, | ||
// SVG Markers are pretty fast. Let's take advantage of this. | ||
targetMarker: { | ||
type: 'path', | ||
fill: 'green', | ||
stroke: 'none', | ||
d: 'M 10 -10 0 0 10 10 z', | ||
}, | ||
}, | ||
}, | ||
markup: [ | ||
{ | ||
tagName: 'path', | ||
selector: 'line', | ||
attrs: { | ||
// Here comes SVG attributes, for which values won't change during the application life time. | ||
// These are specs SVG attributes. Do not add special attributes (e.g. targetMarker, fill: { /* gradient */ })). | ||
// These attributes are set during render, and never touched again during updates. | ||
stroke: 'green', | ||
'stroke-width': 2, | ||
}, | ||
}, | ||
], | ||
}) | ||
|
||
export default class Example extends React.Component { | ||
private container: HTMLDivElement | ||
|
||
componentDidMount() { | ||
const graph = new joint.Graph({ | ||
container: this.container, | ||
width: (COUNT / 2) * 110, | ||
height: 500, | ||
gridSize: 1, | ||
async: ASYNC, | ||
}) | ||
|
||
var node = new Node() | ||
var edge = new Edge() | ||
|
||
var cells: joint.Cell[] = [] | ||
|
||
Array.from({ length: COUNT / 2 }).forEach((_, n) => { | ||
const a = node | ||
.clone() | ||
.pos(n * 110, 100) | ||
.attr('label/text', n + 1) | ||
const b = node | ||
.clone() | ||
.pos(n * 100, 300) | ||
.attr('label/text', n + 1 + COUNT / 2) | ||
const ab = edge | ||
.clone() | ||
.setSource(a) | ||
.setTarget(b) | ||
cells.push(a, b, ab) | ||
}) | ||
|
||
const startTime = new Date().getTime() | ||
|
||
function showResult() { | ||
const duration = (new Date().getTime() - startTime) / 1000 | ||
const elem = document.getElementById('result') as HTMLElement | ||
elem.textContent = | ||
COUNT + | ||
' elements and ' + | ||
COUNT / 2 + | ||
' links rendered in ' + | ||
duration + | ||
's' | ||
} | ||
|
||
// Prefer resetCells() over `addCells()` to add elements in bulk. | ||
// SVG as oppose to HTML does not know `z-index` attribute. | ||
// The "z" coordinate is determined by the order of the sibling elements. The JointJS | ||
// paper makes sure the DOM elements are sorted based on the "z" stored on each element model. | ||
graph.model.resetCells(cells) | ||
|
||
if (ASYNC) { | ||
graph.on('render:done', showResult) | ||
} else { | ||
showResult() | ||
} | ||
} | ||
|
||
refContainer = (container: HTMLDivElement) => { | ||
this.container = container | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="x6-graph-wrap"> | ||
<div id="result">#</div> | ||
<div ref={this.refContainer} className="x6-graph" /> | ||
</div> | ||
) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.