dont quite Chart.js properly yet
[letz.git] / src / lib / pi / Con.svelte
blob7bbb600b70351a3ca08220368d25108a6227b9a1
1 <script lang="ts">
2         import { slide } from 'svelte/transition'
3         import { quintOut } from 'svelte/easing';
4     import {onMount, afterUpdate, onDestroy, getContext} from 'svelte'
5     import {sex,now}  from '$lib/Y/Pic'
6     import {o_}  from '$lib/St'
7     import {sip_wiree, reConstruct}  from '$lib/Co'
8     import Coning from '$lib/Coning.svelte';
9     // < look into https://github.com/kaisermann/svelte-loadable to name these at runtime
10     import Cont from '$lib/pi/Cont.svelte';
11     import Conz from '$lib/pi/Conz.svelte';
12     import Dir from '$lib/pi/Dir.svelte';
13     import Rec from '$lib/pi/Rec.svelte';
14     import Kom from '$lib/pi/Kom.svelte';
15     import Chart from '$lib/ui/Chart.svelte';
16     let pis = {Cont, Conz, Dir, Rec,Kom}
17     // our instructions: (-Con/(-Cont|-Conz))**
18     export let C
19     let boost = C.c.boost || 0
20     
21     // only changes when we are sent an update specifically
22     let update:number
23     sip_wiree(C, v => {
24         C = v
25         update = C.c.version
26     })
28     // TODO not sure how to get boost into the toCon process
29     function boosting (e, negate=false) {
30         negate = e.ctrlKey || negate
31         boost += negate ? -1 : 1
32         C.c.boost = boost
33         // try again here
34         //  saves having to click ring() at the top
35         //   however: we dont reiterate the source data from the top,
36         //    so often opening Dir** and looking at the D** generated
37         //     require ring() to get the most unfolded D**
38         reCon(e)
39     }
40     
42     // label from above (key into here - Cont%Ct is the s.t on the inside)
43     let t
44     let sip
45     let quee
46     function upto() {
47         t = C.t
48         quee = update || '='
49         sip = C.c.ip.join('.')
50         C.y.boosting = boosting
51     }
52     $: upto(C,boost)
54     onMount(() => {
55         //if (sip == '1.2.1.2.2') debugger
56     });
57     
58     // track space, maybe
59     // the div|space that wraps everything in Con
60     let wrapper
61     // Con update version?
62     let update_num = 0
63     let spam = {C,update_num:0,N:[]}
64     let geometricating = C.t == 'treeh 16'
65     
66     afterUpdate(() => {
67         let oldness = now() - spam.asat
68         if (!oldness) return
69         spam.asat = now()
70         let version = spam.update_num++
71         if (!geometricating) return
72         let geo = wrapper.getBoundingClientRect().toJSON()
73         let ge = sex({},geo,'width,height,top,left')
74         ge.time = version
75         // ge.now = now()
76         // ge.C = C
77         // console.log("Geometry "+version+": "+C.t,ge)
78         spam.N.push(ge)
79         spam.update && spam.update()
80         // spam = spam
81     })
82     
84     // refreshing the process, when children want to adjust things
85     function reCon (e) {
86         C = reConstruct(C)
87     }
88     // < this wants overlaying|geo via a parent
89     let datadump
90     
91     // avoid stating this twice (as Con.t and Cont%Ct)
92     let no_label = false
93     if (C.sc.avoid_restating_Ct) {
94         no_label = true
95     }
96     let duration = 0
97     if (C.sc.animal) {
98         duration = 90
99     }
100 </script>
102 <div bind:this={wrapper}>
103 {#if geometricating}
104     <Chart {spam} vers={spam.update_num}/> 
105 {/if}
107 {#if !no_label}<span style="color:deepskyblue" on:pointerdown={(e) => boosting(e)}>{t}</span>{/if}
108 {#if boost} <span style="color:blueviolet" on:pointerdown={(e) => boosting(e,'negate')}>+{boost}</span>{/if}
109 {#if C.c.unwired} <span style="color:red">!wired</span>{/if}
111 <!-- <c_sip style="font-size:70%" on:pointerdown={(e) => datadump = 1}> {sip} </c_sip> -->
112 {#if datadump}
113     <!-- data dump (leaving the mind our Con** is from) -->
114     <Coning C={C.c.s} noC />
115 {/if}
116 <!-- <revision style="color:darkcyan; text-decoration:underline">{quee}</revision> -->
119 {#each o_(C) as n (n.t)}
120     <span transition:slide={{ duration, easing: quintOut }}
121         style="display:inline-block; vertical-align: middle; border:2px solid gainsboro; border-right:none; padding: 0 3px; margin: 0 3px; border-radius: 3px;">
122         <svelte:component on:reCon="{reCon}" this={pis[n.c.pi]} C={n}/>
123     </span>
124 {/each}
125 </div>