-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_with_pyscript.html
162 lines (139 loc) · 5.81 KB
/
index_with_pyscript.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<html>
<head>
<title>Weierstrass point calculator</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://harryrichman.github.io/main.css"/>
<script src="weierstrass.js"></script>
<style>
#force-graph {
width: 600px;
border: 1px solid;
/* border-color: black; */
}
label {
display: block;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="https://unpkg.com/[email protected]/dist/force-graph.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/d3-force.min.js"></script>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<py-config>
packages = [
"matplotlib",
"networkx",
"numpy",
]
</py-config>
<script type="py">
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
# create Frucht graph
g = nx.frucht_graph()
# set positions and draw
pos = nx.spring_layout(g, seed=52)
fig1, ax1 = plt.subplots()
nx.draw(g, pos, ax=ax1)
ax1.set_title('Hello! I am the Frucht graph')
display(fig1, target="mpl-graph")
</script>
</head>
<body>
<div class="text">
<h1>Weierstrass points on graphs</h1>
<p>
A graph, or network, is a configuration of vertices and edges.
On a fixed graph, we can place chips around on vertices and play the "chip-firing game."
This has connections to constructions on algebraic curves.
</p>
<section>
<!-- force-graph example -->
<div id="force-graph"></div>
<script>
const frucht_data = {
"nodes": [
{"id": 1, "group": 1},
{"id": 2, "group": 1},
{"id": 3, "group": 1},
{"id": 4, "group": 1},
{"id": 5, "group": 1},
{"id": 6, "group": 1},
{"id": 7, "group": 1},
{"id": 8, "group": 2},
{"id": 9, "group": 2},
{"id": 10, "group": 2},
{"id": 11, "group": 2},
{"id": 12, "group": 6}
],
"links": [
{"source": 1, "target": 2, "id": "1-2", value: 10, "id2": 0},
{"source": 2, "target": 3, "id": "2-3", value: 10, "id2": 2},
{"source": 3, "target": 4, "id": "3-4", value: 10, "id2": 3},
{"source": 4, "target": 5, "id": "4-5", value: 10, "id2": 4},
{"source": 5, "target": 6, "id": "5-6", value: 10, "id2": 5},
{"source": 6, "target": 7, "id": "6-7", value: 10, "id2": 6},
{"source": 7, "target": 1, "id": "7-1", value: 10, "id2": 7},
{"source": 1, "target": 8, "id": "1-8", value: 1},
{"source": 2, "target": 8, "id": "2-8", value: 1},
{"source": 3, "target": 9, "id": "3-9", value: 1},
{"source": 4, "target": 9, "id": "4-9", value: 1},
{"source": 5, "target": 10, "id": "1-2", value: 1},
{"source": 6, "target": 10, "id": "1-2", value: 1},
{"source": 7, "target": 11, "id": "1-2", value: 1},
{"source": 8, "target": 11, "id": "1-2", value: 1},
{"source": 9, "target": 12, "id": "1-2", value: 1},
{"source": 10, "target": 12, "id": "1-2", value: 1},
{"source": 11, "target": 12, "id": "1-2", value: 1}
]
};
// fetch('../datasets/miserables.json').then(res => res.json()).then(data => {
const Graph = ForceGraph()
(document.getElementById('force-graph'))
.width(600)
.height(400)
.nodeLabel('id')
.nodeAutoColorBy('group')
.linkCurvature(d => - d.value / 30)
.linkDirectionalParticles(1) // d => 1 + d.value / 3)
.linkDirectionalParticleSpeed(d => d.value * 0.001)
// .d3Force(
// 'charge',
// d3.forceManyBody(frucht_data.nodes)
// // .id((link) => link.id2)
// .strength(-30))
// .d3Force('charge')
.d3Force(
'link',
d3.forceLink(frucht_data)
.id((link) => link.id2)
.distance(link => 3 * link.value))
.graphData(frucht_data);
// });
</script>
</section>
<!-- P8 interactive standard form -->
<div class="interactive">
Enter an adjacency matrix of a connected graph.
<p>
<label for="P8-input-V">Enter vertices of \(G\)</label></br>
<input id="P8-input-V" type="text" class="interactive-input" size="50" value="1, 2, 3, 4, 5, 6, 7, 8">
</p>
<div>
<label for="P8-input-E">Enter edges of \(G\)</label>
<textarea id="P8-input-E" class="interactive-input" rows="5" cols="50"
>(1, 2), (2, 3), (1, 4), (4, 3), (1, 5), (3, 7), (5, 6), (6, 7), (5, 8), (8, 7)
</textarea>
</div>
<button id="P8-submit" class="py-button" type="submit" py-click="p8()">Submit data</button>
<div id="P8-output" class="interactive-output hidden"></div>
</div>
<section>
<div id="mpl-graph">
</div>
</section>
</body>
</html>