Skip to content

Commit c799fcd

Browse files
committed
yFiles for HTML 3.0.0.4 demos
1 parent 3a26719 commit c799fcd

File tree

2,871 files changed

+173256
-56999
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,871 files changed

+173256
-56999
lines changed

demos/.prettierignore

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
**/build/
2-
**/dist/
3-
**/node_modules/
4-
**/.angular/
5-
**/.next/
1+
build/
2+
dist/
3+
node_modules/
4+
.angular/
5+
.next/
6+
package-lock.json
7+
npm-shrinkwrap.json
68
/application-features/webgl-rendering/resources/*.json
79
/showcase/large-graphs/resources/*.json
810
/internal/webgl-performance-tests/resources/*.json
911
/showcase/tree-of-life/resources/TreeOfLifeData.json
1012
/starter-kits/**
1113
/view/large-graphs/resources/*.json
12-
/view/rendering-optimizations/resources/*.json
1314
/view/webgl-label-fading/resources/*.json

demos/README.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
<p class="first-paragraph">
103103
The
104104
<a href="https://www.yfiles.com/the-yfiles-sdk/web/yfiles-for-html"
105-
>yFiles for HTML 3.0.0.3</a
105+
>yFiles for HTML 3.0.0.4</a
106106
>
107107
demo applications are available in both JavaScript and TypeScript.
108108
<span class="js-only"
@@ -350,8 +350,8 @@ <h5 class="accordion-title">
350350
<template id="demo-header-template">
351351
<div class="demo-header hidden" id="{{identifier}}-demo-header">{{title}} Demos</div>
352352
</template>
353-
<script src="resources/readme-demo-data.js"></script>
354-
<script src="resources/readme-demo-support.js" async></script>
353+
<script src="./demo-app/readme-demo-data.js"></script>
354+
<script src="./demo-app/readme-demo-support.js" async></script>
355355
<script src="../doc/resources/readme-style.js"></script>
356356
</body>
357357
</html>

demos/README.md

Lines changed: 18 additions & 11 deletions
Large diffs are not rendered by default.

demos/analysis/clustering/ClusteringDemo.js

Lines changed: 60 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@
2828
***************************************************************************/
2929
import {
3030
BiconnectedComponentClustering,
31-
BiconnectedComponentClusteringResult,
3231
EdgeBetweennessClustering,
33-
EdgeBetweennessClusteringResult,
3432
EdgePathLabelModel,
3533
EdgeSides,
3634
GraphBuilder,
@@ -40,38 +38,28 @@ import {
4038
HierarchicalClustering,
4139
HierarchicalClusteringLinkage,
4240
HierarchicalClusteringResult,
43-
IEdge,
44-
IGraph,
45-
INode,
46-
IRectangle,
47-
IRenderTreeElement,
48-
IVisualCreator,
4941
KMeansClustering,
50-
KMeansClusteringResult,
5142
KMeansDistanceMetric,
5243
LabelPropagationClustering,
53-
LabelPropagationClusteringResult,
5444
LabelStyle,
5545
License,
5646
LouvainModularityClustering,
57-
LouvainModularityClusteringResult,
5847
NodeStyleIndicatorRenderer,
59-
PolylineEdgeStyle,
6048
Rect,
6149
ShapeNodeShape
6250
} from '@yfiles/yfiles'
6351

64-
import * as ClusteringData from './resources/ClusteringData'
6552
import { VoronoiDiagram } from './VoronoiDiagram'
6653
import { PolygonVisual, VoronoiVisual } from './DemoVisuals'
6754
import { DendrogramComponent } from './DendrogramSupport'
68-
import { createDemoEdgeStyle, createDemoShapeNodeStyle } from '@yfiles/demo-resources/demo-styles'
69-
import { fetchLicense } from '@yfiles/demo-resources/fetch-license'
70-
import { addNavigationButtons, finishLoading } from '@yfiles/demo-resources/demo-page'
55+
import { createDemoEdgeStyle, createDemoShapeNodeStyle } from '@yfiles/demo-app/demo-styles'
56+
import licenseData from '../../../lib/license.json'
57+
import { addNavigationButtons, finishLoading } from '@yfiles/demo-app/demo-page'
58+
import { edgeBetweennessData } from './data/edge-betweenness-data'
59+
import { biconnectedComponentsData } from './data/biconnected-components-data'
60+
import { kMeansData } from './data/k-means-data'
61+
import { hierarchicalData } from './data/hierarchical-data'
7162

72-
/**
73-
* The {@link GraphComponent} which contains the {@link IGraph}.
74-
*/
7563
let graphComponent
7664

7765
/**
@@ -80,14 +68,14 @@ let graphComponent
8068
let dendrogramComponent
8169

8270
/**
83-
* The canvas object for the cluster visual
71+
* The render tree element for the cluster visual
8472
*/
85-
let clusterVisualObject
73+
let clusterVisualElement
8674

8775
/**
88-
* The canvas object for the k-means centroids visual
76+
* The render tree element for the k-means centroids visual
8977
*/
90-
let kMeansCentroidObject
78+
let kMeansCentroidElement
9179

9280
/**
9381
* The style for the directed edges
@@ -110,7 +98,7 @@ let busy = false
11098
let selectedAlgorithm
11199

112100
async function run() {
113-
License.value = await fetchLicense()
101+
License.value = licenseData
114102

115103
graphComponent = new GraphComponent('graphComponent')
116104
// initialize the default styles
@@ -184,16 +172,10 @@ function configureUserInteraction(graphComponent) {
184172
// when an edge is created, run the algorithm again except for the k-means and hierarchical
185173
// because these two are independent of the edges of the graph
186174
mode.createEdgeInputMode.addEventListener('edge-created', async (evt) => {
187-
if (
188-
selectedAlgorithm === ClusteringAlgorithm.EDGE_BETWEENNESS &&
189-
document.querySelector(`#directed`).checked
190-
) {
175+
if (selectedAlgorithm === 'edge-betweenness' && document.querySelector(`#directed`).checked) {
191176
graphComponent.graph.setStyle(evt.item, directedEdgeStyle)
192177
}
193-
if (
194-
selectedAlgorithm != ClusteringAlgorithm.kMEANS &&
195-
selectedAlgorithm != ClusteringAlgorithm.HIERARCHICAL
196-
) {
178+
if (selectedAlgorithm != 'k-means' && selectedAlgorithm != 'hierarchical') {
197179
await runAlgorithm()
198180
}
199181
})
@@ -208,10 +190,7 @@ function configureUserInteraction(graphComponent) {
208190

209191
// when a node is dragged, run the algorithm if this is HIERARCHICAL clustering or kMEANS
210192
const onDragFinished = async () => {
211-
if (
212-
selectedAlgorithm === ClusteringAlgorithm.HIERARCHICAL ||
213-
selectedAlgorithm === ClusteringAlgorithm.kMEANS
214-
) {
193+
if (selectedAlgorithm === 'hierarchical' || selectedAlgorithm === 'k-means') {
215194
await runAlgorithm()
216195
}
217196
}
@@ -222,11 +201,11 @@ function configureUserInteraction(graphComponent) {
222201
mode.itemHoverInputMode.hoverItems = GraphItemTypes.NODE
223202
mode.itemHoverInputMode.addEventListener('hovered-item-changed', (evt) => {
224203
// if a node is hovered and the algorithm is HIERARCHICAL clustering, hover the corresponding dendrogram node
225-
if (selectedAlgorithm === ClusteringAlgorithm.HIERARCHICAL) {
204+
if (selectedAlgorithm === 'hierarchical') {
226205
const node = evt.item
227206
const highlights = graphComponent.highlights
228207
highlights.clear()
229-
if (node && result) {
208+
if (node && result instanceof HierarchicalClusteringResult) {
230209
highlights.add(node)
231210
dendrogramComponent.updateHighlight(result.getDendrogramNode(node))
232211
} else {
@@ -269,27 +248,27 @@ async function runAlgorithm() {
269248
if (graphComponent.graph.nodes.size > 0) {
270249
switch (selectedAlgorithm) {
271250
default:
272-
case ClusteringAlgorithm.EDGE_BETWEENNESS:
251+
case 'edge-betweenness':
273252
runEdgeBetweennessClustering()
274253
break
275-
case ClusteringAlgorithm.kMEANS:
254+
case 'k-means':
276255
runKMeansClustering()
277256
break
278-
case ClusteringAlgorithm.HIERARCHICAL:
257+
case 'hierarchical':
279258
await runHierarchicalClustering()
280259
break
281-
case ClusteringAlgorithm.BICONNECTED_COMPONENTS:
260+
case 'biconnected-components':
282261
runBiconnectedComponentsClustering()
283262
break
284-
case ClusteringAlgorithm.LOUVAIN_MODULARITY:
263+
case 'louvain-modularity':
285264
runLouvainModularityClustering()
286265
break
287-
case ClusteringAlgorithm.LABEL_PROPAGATION:
266+
case 'label-propagation':
288267
runLabelPropagationClustering()
289268
break
290269
}
291270
} else {
292-
if (selectedAlgorithm === ClusteringAlgorithm.HIERARCHICAL) {
271+
if (selectedAlgorithm === 'hierarchical') {
293272
dendrogramComponent.clearDendrogram()
294273
}
295274
}
@@ -453,7 +432,7 @@ function visualizeClusteringResult() {
453432
// biconnected components returns -1 as cluster id when only one node is present.
454433
// We change the clusterId manually here, as otherwise we'll get an exception in
455434
// DemoVisuals.PolygonVisual#createVisual
456-
if (clusterId === -1 && selectedAlgorithm === ClusteringAlgorithm.BICONNECTED_COMPONENTS) {
435+
if (clusterId === -1 && selectedAlgorithm === 'biconnected-components') {
457436
clusterId = 0
458437
}
459438
let clusterNodesCoordinates = clustering.get(clusterId)
@@ -464,19 +443,19 @@ function visualizeClusteringResult() {
464443
clusterNodesCoordinates.push(node.layout)
465444
})
466445

467-
if (!clusterVisualObject) {
446+
if (!clusterVisualElement) {
468447
let clusterVisual
469448

470449
switch (selectedAlgorithm) {
471450
default:
472-
case ClusteringAlgorithm.EDGE_BETWEENNESS:
473-
case ClusteringAlgorithm.BICONNECTED_COMPONENTS: {
451+
case 'edge-betweenness':
452+
case 'biconnected-components': {
474453
// create a polygonal visual that encloses the nodes that belong to the same cluster
475454
const clusters = { number: clustering.size, clustering, centroids: [] }
476455
clusterVisual = new PolygonVisual(false, clusters)
477456
break
478457
}
479-
case ClusteringAlgorithm.kMEANS: {
458+
case 'k-means': {
480459
const centroids = result.centroids
481460
if (clustering.size >= 3 && graphComponent.contentBounds) {
482461
// create a voronoi diagram
@@ -495,11 +474,11 @@ function visualizeClusteringResult() {
495474
}
496475

497476
// add the visual to the graphComponent's background group
498-
clusterVisualObject = graphComponent.renderTree.createElement(
477+
clusterVisualElement = graphComponent.renderTree.createElement(
499478
graphComponent.renderTree.backgroundGroup,
500479
clusterVisual
501480
)
502-
clusterVisualObject.toBack()
481+
clusterVisualElement.toBack()
503482
}
504483

505484
// invalidate the graphComponent
@@ -511,34 +490,45 @@ function visualizeClusteringResult() {
511490
*/
512491
async function onAlgorithmChanged() {
513492
const algorithmsComboBox = document.querySelector(`#algorithms`)
514-
selectedAlgorithm = algorithmsComboBox.selectedIndex
515-
516-
// determine the file name that will be used for loading the graph
517-
const fileName = algorithmsComboBox.value
493+
selectedAlgorithm = algorithmsComboBox.value
518494

519495
// Adjusts the window appearance. This method is required since when the selected clustering algorithm is
520496
// HIERARCHICAL, the window has to be split to visualize the dendrogram.
521-
const showDendrogram = selectedAlgorithm === ClusteringAlgorithm.HIERARCHICAL
497+
const showDendrogram = selectedAlgorithm === 'hierarchical'
522498
dendrogramComponent.toggleVisibility(showDendrogram)
523499
await graphComponent.fitGraphBounds(10)
524500

525501
// load the graph and run the algorithm
526-
await loadGraph(ClusteringData[fileName])
502+
await loadGraph(selectedAlgorithm)
527503
await runAlgorithm()
528504
}
529505

506+
function getData(name) {
507+
switch (name) {
508+
case 'biconnected-components':
509+
case 'label-propagation':
510+
case 'louvain-modularity':
511+
return biconnectedComponentsData
512+
case 'edge-betweenness':
513+
return edgeBetweennessData
514+
case 'hierarchical':
515+
return hierarchicalData
516+
case 'k-means':
517+
return kMeansData
518+
}
519+
}
520+
530521
/**
531522
* Loads the sample graphs from a JSON file.
532-
* @param sampleData The data samples
533523
*/
534-
async function loadGraph(sampleData) {
524+
async function loadGraph(name) {
535525
// remove all previous visuals
536526
removeClusterVisuals()
537527

538528
const graph = graphComponent.graph
539529
graph.clear()
540530

541-
const isEdgeBetweenness = selectedAlgorithm === ClusteringAlgorithm.EDGE_BETWEENNESS
531+
const isEdgeBetweenness = selectedAlgorithm === 'edge-betweenness'
542532
const styleFactory =
543533
isEdgeBetweenness && document.querySelector(`#directed`).checked
544534
? () => directedEdgeStyle
@@ -550,19 +540,20 @@ async function loadGraph(sampleData) {
550540
: () => undefined // tell GraphBuilder not to create any labels
551541

552542
// initialize a graph builder to parse the graph from the JSON file
543+
const data = getData(name)
553544
const builder = new GraphBuilder({
554545
graph: graph,
555546
nodes: [
556547
{
557-
data: sampleData.nodes,
548+
data: data.nodes,
558549
id: 'id',
559550
layout: (data) => new Rect(data.x, data.y, data.w, data.h),
560551
labels: ['label']
561552
}
562553
],
563554
edges: [
564555
{
565-
data: sampleData.edges,
556+
data: data.edges,
566557
sourceId: 'source',
567558
targetId: 'target',
568559
style: styleFactory,
@@ -687,14 +678,14 @@ function initializeUI() {
687678
* Remove all present cluster visuals.
688679
*/
689680
function removeClusterVisuals() {
690-
if (clusterVisualObject) {
691-
graphComponent.renderTree.remove(clusterVisualObject)
692-
clusterVisualObject = null
681+
if (clusterVisualElement) {
682+
graphComponent.renderTree.remove(clusterVisualElement)
683+
clusterVisualElement = null
693684
}
694685

695-
if (kMeansCentroidObject) {
696-
graphComponent.renderTree.remove(kMeansCentroidObject)
697-
kMeansCentroidObject = null
686+
if (kMeansCentroidElement) {
687+
graphComponent.renderTree.remove(kMeansCentroidElement)
688+
kMeansCentroidElement = null
698689
}
699690
}
700691

@@ -744,15 +735,4 @@ function updateInformationPanel(panelId) {
744735
document.querySelector(`#${panelId}`).style.display = 'inline-block'
745736
}
746737

747-
var ClusteringAlgorithm
748-
;(function (ClusteringAlgorithm) {
749-
ClusteringAlgorithm[(ClusteringAlgorithm['EDGE_BETWEENNESS'] = 0)] = 'EDGE_BETWEENNESS'
750-
ClusteringAlgorithm[(ClusteringAlgorithm['kMEANS'] = 1)] = 'kMEANS'
751-
ClusteringAlgorithm[(ClusteringAlgorithm['HIERARCHICAL'] = 2)] = 'HIERARCHICAL'
752-
ClusteringAlgorithm[(ClusteringAlgorithm['BICONNECTED_COMPONENTS'] = 3)] =
753-
'BICONNECTED_COMPONENTS'
754-
ClusteringAlgorithm[(ClusteringAlgorithm['LOUVAIN_MODULARITY'] = 4)] = 'LOUVAIN_MODULARITY'
755-
ClusteringAlgorithm[(ClusteringAlgorithm['LABEL_PROPAGATION'] = 5)] = 'LABEL_PROPAGATION'
756-
})(ClusteringAlgorithm || (ClusteringAlgorithm = {}))
757-
758738
run().then(finishLoading)

0 commit comments

Comments
 (0)