File size: 1,593 Bytes
f68bbbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import ipyreact
from traitlets import List, Any
import numpy as np

class TldrawSineWidget(ipyreact.ReactWidget):
    points = List(List(Any())).tag(sync=True)
    _esm = """
    import { TDShapeType, Tldraw } from "@tldraw/tldraw";
    import * as React from "react";

    export default function App({ points }) {

        const [app, setApp] = React.useState()

        const handleMount = React.useCallback((app: Tldraw) => {
            setApp(app)
        }, []);

        React.useEffect(() => {
            if (app) {
            app.createShapes({
                type: "draw",
                id: "draw1",
                color: 'red',
                points: points,
            });
            }
        }, [points, app])

        return (
            <div
            style={{
                position: "relative",
                width: "800px",
                height: "350px",
            }}
            >
            <Tldraw onMount={handleMount} onChange={e => console.log("hii")} />
            </div>
        );
}

    """

import solara
import numpy as np

float_value = solara.reactive(0)

@solara.component
def Page():
    stretchx = 50
    x = np.arange(0,4*np.pi*stretchx , 2)
    y = 130*np.sin(x*1/stretchx+float_value.value)+150

    points = np.column_stack((x, y)).tolist()
    TldrawSineWidget.element(points=points)
    solara.Markdown(f"**Float value**: {float_value.value}")
    solara.FloatSlider("Some float", value=float_value, min=0, max=4*np.pi, step=0.1)

    with solara.Row():
        solara.Button("Reset", on_click=lambda: float_value.set(0))
Page()