Skip to content

Commit ecacd5a

Browse files
committed
add sample code for webinar-25
1 parent 55bf087 commit ecacd5a

File tree

10 files changed

+374
-0
lines changed

10 files changed

+374
-0
lines changed

demos/webinar-25/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# VSDX Template Demo
2+
3+
This demo shows how to use an existing VSDX file as a template.
4+
5+
## Things to try
6+
7+
- Press ![export](./public/download-16.svg) to export the diagram.

demos/webinar-25/index.html

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
7+
8+
<!-- ////////////////////////////////////////////////////////////////////////
9+
// @license
10+
// This demo file is part of the VSDX Export for yFiles for HTML.
11+
// Copyright (c) by yWorks GmbH, Vor dem Kreuzberg 28,
12+
// 72070 Tuebingen, Germany. All rights reserved.
13+
//
14+
// yFiles demo files exhibit VSDX Export for yFiles for HTML functionalities.
15+
// Any redistribution of demo files in source code or binary form, with
16+
// or without modification, is not permitted.
17+
//
18+
// Owners of a valid software license for a VSDX Export for yFiles for HTML
19+
// version that this demo is shipped with are allowed to use the demo
20+
// source code as basis for their own VSDX Export for yFiles for HTML
21+
// powered applications. Use of such programs is
22+
// governed by the rights
23+
// and conditions as set out in the VSDX Export for yFiles for HTML
24+
// license agreement.
25+
//
26+
// THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED
27+
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28+
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
29+
// NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
31+
// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36+
//
37+
////////////////////////////////////////////////////////////////////////-->
38+
39+
<title>VSDX Template Demo [VSDX Export for yFiles for HTML]</title>
40+
41+
</head>
42+
43+
<body class="demo-has-left">
44+
<aside class="demo-sidebar demo-left demo-description">
45+
<div class="demo-sidebar-content">
46+
<h1>VSDX Template Demo</h1>
47+
<div>
48+
<p>This demo shows how to use an existing VSDX file as a template.</p>
49+
<h2>Things to try</h2>
50+
<ul>
51+
<li>
52+
Press <img src="./public/download-16.svg" alt="export" /> to export the diagram.
53+
</li>
54+
</ul>
55+
</div>
56+
</div>
57+
</aside>
58+
59+
<div class="demo-content">
60+
<div class="demo-toolbar">
61+
<button
62+
data-command="ExportToVisio"
63+
title="Export To VSDX"
64+
class="demo-icon-export demo-toolbar-button"
65+
></button>
66+
67+
<span class="demo-separator"></span>
68+
69+
<button data-command="ZoomIn" class="demo-icon-yIconZoomIn demo-toolbar-button"></button>
70+
<button
71+
data-command="ZoomOriginal"
72+
class="demo-icon-yIconZoomOriginal demo-toolbar-button"
73+
></button>
74+
<button data-command="ZoomOut" class="demo-icon-yIconZoomOut demo-toolbar-button"></button>
75+
<button
76+
data-command="FitContent"
77+
class="demo-icon-yIconZoomFit demo-toolbar-button"
78+
></button>
79+
</div>
80+
81+
<div>
82+
<div id="graphComponent"></div>
83+
</div>
84+
85+
<div id="loadingIndicator">Exporting...</div>
86+
</div>
87+
88+
<script type="module" src="/src/VsdxTemplateDemo.ts"></script>
89+
<script nomodule></script>
90+
</body>
91+
</html>

demos/webinar-25/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@yfiles/webinar-25-demo",
3+
"version": "3.0.0",
4+
"author": "yWorks GmbH <yfileshtml@yworks.com>",
5+
"license": "https://www.yworks.com/products/yfiles-for-html/sla",
6+
"private": true,
7+
"type": "module",
8+
"scripts": {
9+
"dev": "vite",
10+
"build": "vite build",
11+
"preview": "vite preview"
12+
},
13+
"devDependencies": {
14+
"typescript": "~5.8.3",
15+
"vite": "^6.2.5"
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Loading
35.3 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Loading

demos/webinar-25/public/ylogo.svg

Lines changed: 12 additions & 0 deletions
Loading
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/**
2+
* @license This demo file is part of the VSDX Export for yFiles for HTML. Copyright (c)
3+
* by yWorks GmbH, Vor dem Kreuzberg 28, 72070 Tuebingen, Germany. All rights reserved.
4+
*
5+
* YFiles demo files exhibit VSDX Export for yFiles for HTML functionalities. Any redistribution of
6+
* demo files in source code or binary form, with or without modification, is not permitted.
7+
*
8+
* Owners of a valid software license for a VSDX Export for yFiles for HTML version that this demo
9+
* is shipped with are allowed to use the demo source code as basis for their own VSDX Export for
10+
* yFiles for HTML powered applications. Use of such programs is governed by the rights and
11+
* conditions as set out in the VSDX Export for yFiles for HTML license agreement.
12+
*
13+
* THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15+
* DISCLAIMED. IN NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
17+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
18+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
20+
* THE POSSIBILITY OF SUCH DAMAGE.
21+
*/
22+
23+
import '@yfiles/yfiles/yfiles.css'
24+
import '@yfiles/demo-resources/style/demo.css'
25+
26+
import {
27+
Command,
28+
GraphComponent,
29+
GraphViewerInputMode,
30+
type IGraph,
31+
ImageNodeStyle,
32+
INode,
33+
Insets,
34+
License,
35+
PolylineEdgeStyle,
36+
} from '@yfiles/yfiles'
37+
import {
38+
bindAction,
39+
bindCommand,
40+
showApp,
41+
showLoadingIndicator,
42+
} from '@yfiles/demo-resources/demo-ui/demo-app'
43+
import { initDemoStyles } from '@yfiles/demo-resources/demo-ui/demo-styles'
44+
import licenseData from '../../license.json'
45+
import {
46+
AutoRoutingStyleProcessingStep,
47+
EdgePathProcessingStep,
48+
MasterProviderBase,
49+
MasterProviderContext,
50+
NodeLayoutProcessingStep,
51+
NodePortLocationProcessingStep,
52+
PolylineEdgeProvider,
53+
PortConnectionProcessingStep,
54+
type ShapeStyleConfiguration,
55+
VoidPortProvider,
56+
VsdxExportConfiguration,
57+
VsdxIO,
58+
} from '@yfiles/vsdx-export'
59+
import saveBlob from '@yfiles/demo-resources/save-blob'
60+
61+
let graphComponent: GraphComponent = null!
62+
63+
License.value = licenseData
64+
// initialize the GraphComponent and GraphOverviewComponent
65+
graphComponent = new GraphComponent('graphComponent')
66+
67+
// bind toolbar commands
68+
initializeUI()
69+
70+
// Assign the default demo styles
71+
initDemoStyles(graphComponent.graph)
72+
73+
// load the first graph
74+
createSampleGraph(graphComponent.graph)
75+
76+
// create the input mode
77+
graphComponent.inputMode = new GraphViewerInputMode()
78+
79+
void graphComponent.fitGraphBounds()
80+
81+
showApp(graphComponent)
82+
83+
async function runExport(): Promise<void> {
84+
const fileName = 'Diagram.vsdx'
85+
86+
// load the template file
87+
const template = await fetch('/template.vstx').then((r) => r.blob())
88+
const vsdxIO = await VsdxIO.fromBlob(template)
89+
90+
// create a configuration
91+
const config = VsdxExportConfiguration.createEmpty()
92+
93+
class ComputerStencilMasterProvider extends MasterProviderBase {
94+
node(
95+
node: INode,
96+
context: MasterProviderContext,
97+
): Promise<ShapeStyleConfiguration | null> | ShapeStyleConfiguration | null {
98+
const computerMaster = context.masters.find((master) => master.nameId.name === 'Computer')
99+
return computerMaster ? { master: computerMaster } : null
100+
}
101+
}
102+
103+
config.margins = new Insets(200)
104+
config.evaluateFormulas = true
105+
106+
config.masterProviders.push(new PolylineEdgeProvider())
107+
config.masterProviders.push(new VoidPortProvider())
108+
config.masterProviders.push(new ComputerStencilMasterProvider())
109+
110+
config.shapeProcessingSteps.push(new NodeLayoutProcessingStep())
111+
config.shapeProcessingSteps.push(new NodePortLocationProcessingStep())
112+
config.shapeProcessingSteps.push(new EdgePathProcessingStep())
113+
config.shapeProcessingSteps.push(new PortConnectionProcessingStep())
114+
config.shapeProcessingSteps.push(new AutoRoutingStyleProcessingStep())
115+
116+
// add the yFiles diagram
117+
const page = vsdxIO.vsdxPackage.pages.get(1)
118+
await vsdxIO.addGraph(graphComponent!, config, page)
119+
120+
// save the created VSDX file
121+
const blob = await vsdxIO.writeBlob(config)
122+
saveBlob(blob, fileName)
123+
}
124+
125+
/**
126+
* Registers commands for the toolbar buttons.
127+
*/
128+
function initializeUI(): void {
129+
bindAction("button[data-command='ExportToVisio']", async () => {
130+
await showLoadingIndicator(true)
131+
132+
setTimeout(async () => {
133+
await runExport()
134+
await showLoadingIndicator(false)
135+
})
136+
})
137+
138+
bindCommand("button[data-command='ZoomIn']", Command.INCREASE_ZOOM, graphComponent)
139+
bindCommand("button[data-command='ZoomOut']", Command.DECREASE_ZOOM, graphComponent)
140+
bindCommand("button[data-command='FitContent']", Command.FIT_GRAPH_BOUNDS, graphComponent)
141+
bindCommand("button[data-command='ZoomOriginal']", Command.ZOOM, graphComponent, 1.0)
142+
}
143+
144+
/**
145+
* Creates the sample graph
146+
*/
147+
function createSampleGraph(graph: IGraph): void {
148+
graph.edgeDefaults.style = new PolylineEdgeStyle()
149+
graph.nodeDefaults.style = new ImageNodeStyle('/workstation.svg')
150+
const n1 = graph.createNodeAt({ location: [0, 0] })
151+
const n2 = graph.createNodeAt({ location: [-50, 100] })
152+
const n3 = graph.createNodeAt({ location: [50, 100] })
153+
graph.createEdge({ source: n1, target: n2 })
154+
graph.createEdge({ source: n2, target: n3 })
155+
graph.createEdge({ source: n3, target: n1 })
156+
}

demos/webinar-25/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["ES2022", "dom", "dom.iterable"],
4+
"module": "es2022",
5+
"target": "es2022",
6+
"strict": true,
7+
"esModuleInterop": true,
8+
"skipLibCheck": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"moduleResolution": "node",
11+
"verbatimModuleSyntax": true,
12+
"resolveJsonModule": true,
13+
"noEmit": true
14+
},
15+
"include": ["src"]
16+
}

demos/webinar-25/vite.config.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license This demo file is part of the VSDX Export for yFiles for HTML. Copyright (c)
3+
* by yWorks GmbH, Vor dem Kreuzberg 28, 72070 Tuebingen, Germany. All rights reserved.
4+
*
5+
* YFiles demo files exhibit VSDX Export for yFiles for HTML functionalities. Any redistribution of
6+
* demo files in source code or binary form, with or without modification, is not permitted.
7+
*
8+
* Owners of a valid software license for a VSDX Export for yFiles for HTML version that this demo
9+
* is shipped with are allowed to use the demo source code as basis for their own VSDX Export for
10+
* yFiles for HTML powered applications. Use of such programs is governed by the rights and
11+
* conditions as set out in the VSDX Export for yFiles for HTML license agreement.
12+
*
13+
* THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
14+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15+
* DISCLAIMED. IN NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
17+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
18+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
20+
* THE POSSIBILITY OF SUCH DAMAGE.
21+
*/
22+
23+
import { defineConfig, searchForWorkspaceRoot } from 'vite'
24+
25+
export default defineConfig({
26+
// We use a relative base path to be able to load different demos from the same IDE project
27+
base: './',
28+
server: {
29+
fs: {
30+
allow: [searchForWorkspaceRoot(process.cwd()), '../../resources/icons'],
31+
},
32+
},
33+
assetsInclude: ['**/*.vsdx'],
34+
})

0 commit comments

Comments
 (0)