| author | Tomas Zeman <tomas@functionals.cz> |
| Wed, 28 Aug 2019 21:14:32 +0200 | |
| changeset 1 | b9c54a82f3db |
| permissions | -rw-r--r-- |
|
1
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
1 |
/* |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
2 |
* Copyright 2019 Tomas Zeman <tomas@functionals.cz>, <tzeman@volny.cz> |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
3 |
* |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
5 |
* you may not use this file except in compliance with the License. |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
6 |
* You may obtain a copy of the License at |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
7 |
* |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
9 |
* |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
13 |
* See the License for the specific language governing permissions and |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
14 |
* limitations under the License. |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
15 |
*/ |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
16 |
package cz.functionals.visjs |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
17 |
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
18 |
import org.scalajs.dom.Node |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
19 |
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
20 |
import scala.scalajs.js |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
21 |
import scala.scalajs.js.JSConverters._ |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
22 |
import scala.scalajs.js.annotation.JSGlobal |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
23 |
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
24 |
@js.native |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
25 |
@JSGlobal("vis.Network")
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
26 |
class Network(container: Node, data: NetworkData, options: NetworkOptions) |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
27 |
extends js.Object {
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
28 |
def destroy(): Unit = js.native |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
29 |
//def on(eventName: String, callback: js.Function1[js.Any, Unit]): Unit = js.native |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
30 |
def on[Ev](eventName: String, callback: js.Function1[Ev, Unit]): Unit = js.native |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
31 |
def setData(data: NetworkData): Unit = js.native |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
32 |
} |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
33 |
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
34 |
class NetworkOptions( |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
35 |
val physics: js.Object = new js.Object(), // must be defined |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
36 |
val interaction: Interaction = new Interaction() |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
37 |
) extends js.Object |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
38 |
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
39 |
/* |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
40 |
https://visjs.org/docs/network/#options |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
41 |
var options = {
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
42 |
autoResize: true, |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
43 |
height: '100%', |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
44 |
width: '100%' |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
45 |
locale: 'en', |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
46 |
locales: locales, |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
47 |
clickToUse: false, |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
48 |
configure: {...}, // defined in the configure module.
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
49 |
edges: {...}, // defined in the edges module.
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
50 |
nodes: {...}, // defined in the nodes module.
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
51 |
groups: {...}, // defined in the groups module.
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
52 |
layout: {...}, // defined in the layout module.
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
53 |
interaction: {...}, // defined in the interaction module.
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
54 |
manipulation: {...}, // defined in the manipulation module.
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
55 |
physics: {...}, // defined in the physics module.
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
56 |
} |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
57 |
*/ |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
58 |
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
59 |
trait NetworkData extends js.Object |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
60 |
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
61 |
object NetworkData {
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
62 |
def apply(nodes: Seq[GraphNode], edges: Seq[GraphEdge]): NetworkData = |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
63 |
apply(new DataSet(nodes.toJSArray), new DataSet(edges.toJSArray)) |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
64 |
|
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
65 |
def apply(nodes: DataSet[GraphNode], edges: DataSet[GraphEdge]): NetworkData = |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
66 |
js.Dynamic.literal(nodes = nodes, edges = edges).asInstanceOf[NetworkData] |
|
b9c54a82f3db
Base classes: DataSet, Network & at al., Graph2d
Tomas Zeman <tomas@functionals.cz>
parents:
diff
changeset
|
67 |
} |