Skip to content

Commit 89779a3

Browse files
Increased graph size
1 parent e1b048e commit 89779a3

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

src/main/scala/demo/components/toplevel.scala

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package demo.components
22

3+
import scala.scalajs.js
34
import japgolly.scalajs.react._
45
import japgolly.scalajs.react.vdom.all._
56

@@ -52,29 +53,16 @@ object toplevel {
5253
),
5354
labels = List("2009", "2010", "2011", "2012")
5455
)
55-
val family = Family(
56-
characters = List(
57-
Character("pippo"),
58-
Character("pluto"),
59-
Character("paperino"),
60-
Character("qui"),
61-
Character("quo"),
62-
Character("qua"),
63-
Character("nonna papera"),
64-
Character("ciccio")
65-
),
66-
links = List(
67-
Link(start = "pippo", end = "quo", weight = 10),
68-
Link(start = "pippo", end = "qua", weight = 30),
69-
Link(start = "pluto", end = "nonna papera", weight = 10),
70-
Link(start = "pluto", end = "qui", weight = 10),
71-
Link(start = "pluto", end = "quo", weight = 10),
72-
Link(start = "paperino", end = "ciccio", weight = 100),
73-
Link(start = "qui", end = "ciccio", weight = 20),
74-
Link(start = "quo", end = "ciccio", weight = 10),
75-
Link(start = "qua", end = "nonna papera", weight = 30)
76-
)
77-
)
56+
def randomGraph(n: Int, density: Double) = {
57+
val characters = (1 to n) map { x => Character(x.toString) }
58+
val links = characters.combinations(2) filter { _ =>
59+
js.Math.random() < density
60+
} map { case Vector(Character(a), Character(b)) =>
61+
Link(a, b, 3 + 5 * js.Math.random())
62+
}
63+
64+
Family(characters = characters.toList, links = links.toList)
65+
}
7866

7967
val TopLevel = ReactComponentB[Unit]("Top level component")
8068
.render(_ =>
@@ -109,7 +97,7 @@ object toplevel {
10997
id = Some("graph"),
11098
title = "Graph Chart",
11199
text = "A preliminary example of force-directed graph."
112-
), GraphChart(family))
100+
), GraphChart(randomGraph(30, 0.15)))
113101
)
114102
)
115103
)

0 commit comments

Comments
 (0)