on main help sign in
add error catching to graph, bump version
commit39c101cf07e053e23cb337eef62ef67e391bdc89 authorJohn Hyde <johnhydefour@gmail.com> dateSat 3 Dec 2022, 12:05 (4 years ago) parent363cd2b
4 files changed+135−105
README.md+1 desk/app/astrolabe.hoon+31−14 desk/desk.docket-0+2−2 ui/src/lib/graph.ts+101−89
README.md+1
@@ -35,6 +35,7 @@ Regardless of what you run to develop, Vite will hot-reload code changes as you
3535 2. `|mount %astrolabe` to mount it.
3636 3. Set `ASTROLABE_DESK` in `.env.local` if the path to your desk is different.
37373. Create and upload `glob-http`, if applicable (see below)
38+4. Bump the `version` in `desk.docket-0`.
38393. Install the desk
3940 1. From the `ui` folder: `npm run install:desk`
4041 2. From the distribution ship's dojo: `:treaty|unpublish %astrolabe`
desk/app/astrolabe.hoon+31−14
@@ -6,15 +6,12 @@
66 $% state-0
77 state-1
88 state-2
9+ state-3
910 ==
1011+$ state-0
1112 $: %0
1213 spa=spawned
1314 ==
14−+$ fropoints-1
15− $: fopoints=opoints :: forward ordered points
16− ropoints=opoints :: reversed ordered points, e.g. .~palnet-sampel
17− ==
1815+$ state-1
1916 $: %1
2017 fropoints-1
@@ -24,12 +21,22 @@
2421 spam=spawn-mip
2522 fropoints-1
2623 ==
24++$ state-3
25+ $: %3
26+ prev-spo=(map ship ship) :: so we know who the old sponsor was when sponsor changes
27+ spam=spawn-mip
28+ fropoints-1
29+ ==
2730::
31++$ fropoints-1
32+ $: fopoints=opoints :: forward ordered points
33+ ropoints=opoints :: reversed ordered points, e.g. .~palnet-sampel
34+ ==
2835+$ spawned (jug ship ship)
2936+$ card card:agent:gall
3037--
3138%- agent:dbug
32−=| state-2
39+=| state-3
3340=* state -
3441^- agent:gall
3542=<
@@ -49,9 +56,9 @@
4956 ^- (quip card _this)
5057 =/ old !<(versioned-state old-state)
5158 =^ cards-01 old
52− ?. ?=(?(%0 %1) -.old) `old
59+ ?. ?=(?(%0 %1 %2) -.old) `old
5360 (on-naive-state:hc get-nas:hc)
54− ?> ?=(%2 -.old)
61+ ?> ?=(%3 -.old)
5562 [cards-01 this(state old)]
5663++ on-poke on-poke:def
5764++ on-watch on-watch:def
@@ -147,17 +154,27 @@
147154 |= [child=ship nas=^state:naive]
148155 ^- _state
149156 =/ =npoint (get-npoint-from-nas child nas)
150− =. spam
151− =/ parent (^sein:title child)
152− ?: =(parent child) spam
153− ?: (is-npoint-locked npoint) spam
154− =/ pdata (pdata:smel (pmeta:smel child npoint) ~)
155− =* spo sponsor.net.npoint
156− =? spam &(has.spo !=(parent who.spo))
157+ =/ parent (^sein:title child)
158+ ?: =(parent child) state
159+ ?: (is-npoint-locked npoint) state
160+ =/ pdata (pdata:smel (pmeta:smel child npoint) ~)
161+ =* spo sponsor.net.npoint
162+ =/ spo-not-par &(has.spo !=(parent who.spo))
163+ =? state spo-not-par
164+ =/ prev (~(get by prev-spo) child)
165+ =? spam &(?=(^ prev) !=(u.prev who.spo))
166+ (~(del bi spam) u.prev child)
167+ =. prev-spo
168+ %+ ~(put by prev-spo)
169+ child
170+ who.spo
171+ =. spam
157172 %^ ~(put bi-meta spam)
158173 who.spo
159174 child
160175 pdata
176+ state
177+ =. spam
161178 %^ ~(put bi-meta spam)
162179 parent
163180 child
desk/desk.docket-0+2−2
@@ -2,9 +2,9 @@
22 info+'Your guide to the Urbit constellations'
33 color+0x1f.243c
44 image+'https://raw.githubusercontent.com/johnhyde/astrolabe/main/ui/src/assets/astrolabe-tile.svg'
5− glob-http+['https://s3.us-east-2.amazonaws.com/warkgnall.com/urbit/astrolabe/globs/glob-0v2.jtc81.6iedn.re59t.n1mo1.9e0k8.glob' 0v2.jtc81.6iedn.re59t.n1mo1.9e0k8]
5+ glob-http+['https://s3.us-east-2.amazonaws.com/warkgnall.com/urbit/astrolabe/globs/glob-0v2.9eih9.a77pv.83cmp.gc70u.ev4q7.glob' 0v2.9eih9.a77pv.83cmp.gc70u.ev4q7]
66 base+'astrolabe'
7− version+[0 3 4]
7+ version+[0 3 5]
88 website+'https://github.com/johnhyde/astrolabe'
99 license+'MIT'
1010==
ui/src/lib/graph.ts+101−89
@@ -252,105 +252,113 @@ export function populateGraph(g: Graph, chartData: ChartPoint[], bySponsor: bool
252252 if (itsYou) {
253253 g.setNodeAttribute(gPatp, 'color', colors.YOUR_GAL);
254254 }
255− g.addNode(sPatp, {
256− label: sPatp,
257− size: starSize,
258− color: itsYou ? colors.YOU : colors.GOLDT2,
259− x: starX,
260− y: starY,
261− zIndex: 8,
262− });
263− if (lastStarArm == arm) {
264− g.addEdge(sPatp, lastStarPatp, {
265− color: colors.LGREY,
266− size: 0.1,
267− zIndex: 7,
268− });
269− } else {
270− g.addEdge(sPatp, gPatp, {
271− color: colors.LGREY,
272− size: 0.2,
273− zIndex: 9,
255+ try {
256+ g.addNode(sPatp, {
257+ label: sPatp,
258+ size: starSize,
259+ color: itsYou ? colors.YOU : colors.GOLDT2,
260+ x: starX,
261+ y: starY,
262+ zIndex: 8,
274263 });
275− }
276− lastStarArm = arm;
277− lastStarPatp = sPatp;
278− if (star.sponsor) {
279− sponsorEdges.push([sPatp, star.sponsor, {
280− color: colors.GREEN,
281− size: 0.2,
282− zIndex: 11,
283− }]);
284− }
285−
286− const planets = star[subsKey] || [];
287− const numPlanets = planets.length;
288− // const maxPlanetDistance = starSize * 1.6 * 4000 * 64;
289− const maxPlanetDistance = minDistanceBetweenStars * 0.45;
290− const minPlanetDistance = maxPlanetDistance / 4;
291− const {
292− coords: planetCoords,
293− numArms: numPlanetArms,
294− minDistanceBetween: minDistanceBetweenPlanets,
295− } = arrangePointsInSpirals(numPlanets,
296− {
297− maxDistance: maxPlanetDistance,
298− minDistance: minPlanetDistance,
299− startX: starX,
300− startY: starY,
301− maxArms: 30,
302− makeSingleArmCircle: true,
303− });
304− let lastPlanetArm = null;
305− let lastPlanetPatp = null;
306− planets.forEach((planet, pi) => {
307− const pPatp = planet.patp;
308− const [planetX, planetY] = planetCoords[pi].coords;
309− const arm = planetCoords[pi].arm;
310− const planetSize = Math.sqrt(Math.min(minPlanetDistance, minDistanceBetweenPlanets)) / 1300;
311− const planetEdgeSize = planetSize / 3;
312− const itsYou = pPatp === '~' + window.ship;
313− if (itsYou) {
314− g.setNodeAttribute(sPatp, 'color', colors.YOUR_STAR);
315− g.setNodeAttribute(gPatp, 'color', colors.YOUR_GAL);
264+ if (lastStarArm == arm) {
265+ g.addEdge(sPatp, lastStarPatp, {
266+ color: colors.LGREY,
267+ size: 0.1,
268+ zIndex: 7,
269+ });
270+ } else {
271+ g.addEdge(sPatp, gPatp, {
272+ color: colors.LGREY,
273+ size: 0.2,
274+ zIndex: 9,
275+ });
276+ }
277+ lastStarArm = arm;
278+ lastStarPatp = sPatp;
279+ if (star.sponsor) {
280+ sponsorEdges.push([sPatp, star.sponsor, {
281+ color: colors.GREEN,
282+ size: 0.2,
283+ zIndex: 11,
284+ }]);
316285 }
317− try {
318− g.addNode(pPatp, {
319− label: pPatp,
320− size: planetSize,
321− color: itsYou ? colors.YOU : (planet.dominion == 'l2' ? colors.GREEN : colors.BLUE),
322− x: planetX,
323− y: planetY,
324− zIndex: 6,
286+
287+ const planets = star[subsKey] || [];
288+ const numPlanets = planets.length;
289+ // const maxPlanetDistance = starSize * 1.6 * 4000 * 64;
290+ const maxPlanetDistance = minDistanceBetweenStars * 0.45;
291+ const minPlanetDistance = maxPlanetDistance / 4;
292+ const {
293+ coords: planetCoords,
294+ numArms: numPlanetArms,
295+ minDistanceBetween: minDistanceBetweenPlanets,
296+ } = arrangePointsInSpirals(numPlanets,
297+ {
298+ maxDistance: maxPlanetDistance,
299+ minDistance: minPlanetDistance,
300+ startX: starX,
301+ startY: starY,
302+ maxArms: 30,
303+ makeSingleArmCircle: true,
325304 });
326− if (lastPlanetArm == arm) {
327− g.addEdge(pPatp, lastPlanetPatp, {
328− color: colors.DGREY,
329− size: planetEdgeSize,
330− zIndex: 5,
305+ let lastPlanetArm = null;
306+ let lastPlanetPatp = null;
307+ planets.forEach((planet, pi) => {
308+ const pPatp = planet.patp;
309+ const [planetX, planetY] = planetCoords[pi].coords;
310+ const arm = planetCoords[pi].arm;
311+ const planetSize = Math.sqrt(Math.min(minPlanetDistance, minDistanceBetweenPlanets)) / 1300;
312+ const planetEdgeSize = planetSize / 3;
313+ const itsYou = pPatp === '~' + window.ship;
314+ if (itsYou) {
315+ g.setNodeAttribute(sPatp, 'color', colors.YOUR_STAR);
316+ g.setNodeAttribute(gPatp, 'color', colors.YOUR_GAL);
317+ }
318+ try {
319+ g.addNode(pPatp, {
320+ label: pPatp,
321+ size: planetSize,
322+ color: itsYou ? colors.YOU : (planet.dominion == 'l2' ? colors.GREEN : colors.BLUE),
323+ x: planetX,
324+ y: planetY,
325+ zIndex: 6,
331326 });
332− } else {
333− if (numPlanetArms == 1) {
334− g.addEdge(pPatp, sPatp, {
327+ if (lastPlanetArm == arm) {
328+ g.addEdge(pPatp, lastPlanetPatp, {
335329 color: colors.DGREY,
336330 size: planetEdgeSize,
337331 zIndex: 5,
338332 });
333+ } else {
334+ if (numPlanetArms == 1) {
335+ g.addEdge(pPatp, sPatp, {
336+ color: colors.DGREY,
337+ size: planetEdgeSize,
338+ zIndex: 5,
339+ });
340+ }
339341 }
342+ if (planet.sponsor) {
343+ sponsorEdges.push([pPatp, planet.sponsor, {
344+ color: colors.GREEN,
345+ size: planetEdgeSize,
346+ zIndex: 11,
347+ }]);
348+ }
349+ lastPlanetArm = arm;
350+ lastPlanetPatp = pPatp;
351+ } catch (e) {
352+ let msg = `Couldn't add ${pPatp} to the graph`;
353+ console.error(msg, e);
354+ alertMe(msg + '\n' + e.message);
340355 }
341− if (planet.sponsor) {
342− sponsorEdges.push([pPatp, planet.sponsor, {
343− color: colors.GREEN,
344− size: planetEdgeSize,
345− zIndex: 11,
346− }]);
347− }
348− } catch (e) {
349− console.error(`Couldn't add ${pPatp} to the graph`, e);
350− }
351− lastPlanetArm = arm;
352− lastPlanetPatp = pPatp;
353− });
356+ });
357+ } catch (e) {
358+ let msg = `Couldn't add ${sPatp} to the graph`;
359+ console.error(msg, e);
360+ alertMe(msg + '\n' + e.message);
361+ }
354362 });
355363 });
356364 sponsorEdges.forEach(([point, sponsor, attrs]) => {
@@ -361,3 +369,7 @@ export function populateGraph(g: Graph, chartData: ChartPoint[], bySponsor: bool
361369 }
362370 return g;
363371}
372+
373+function alertMe(msg: string) {
374+ alert('Encountered an error, please tell ~midlev-mindyr: ' + msg);
375+}