File: strokePercent.html

package info (click to toggle)
node-zrender 5.4.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,588 kB
  • sloc: javascript: 1,259; makefile: 2
file content (126 lines) | stat: -rw-r--r-- 3,150 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="https://cdn.jsdelivr.net/npm/dat.gui@0.7.6/build/dat.gui.js"></script>
    <script src="../dist/zrender.js"></script>
    <script src="lib/config.js"></script>
</head>
<body>
    <style>
        html, body, #main {
            width: 100%;
            height: 100%;
            margin: 0;
        }
    </style>
    <div id="main"></div>
    <script type="text/javascript">
        const zr = zrender.init(document.getElementById('main'), {
            renderer: window.__ZRENDER__DEFAULT__RENDERER__
        });

        const shapes = [
        {
            ctor: zrender.Circle,
            label: 'Circle',
            shape: {
                r: 100
            }
        }, {
            ctor: zrender.Rect,
            label: 'Rect',
            shape: {
                width: 100,
                height: 100
            }
        },
        {
            ctor: zrender.Sector,
            label: 'Sector',
            shape: {
                startAngle: 1,
                endAngle: 5,
                r0: 50,
                r: 100
            }
        },
        {
            ctor: zrender.Polyline,
            label: 'Polyline',
            shape: {
                points: [[50, 50], [200, 10], [100, 200], [50, 150], [10, 70]]
            }
        },
        {
            ctor: zrender.Polyline,
            label: 'Smoothed Polyline',
            shape: {
                points: [[50, 50], [200, 10], [100, 200], [50, 150], [10, 70]],
                smooth: 0.5
            }
        }];

        const els = [];

        let x = 20;
        let y = 20;

        shapes.forEach(function (shapeDef) {
            const el = new shapeDef.ctor({
                shape: shapeDef.shape,
                style: {
                    fill: 'none',
                    stroke: '#000',
                    lineWidth: 5
                },
                textContent: new zrender.Text({
                    style: {
                        text: shapeDef.label,
                        fill: '#000'
                    }
                }),
                textConfig: {
                    position: 'inside'
                }
            });

            const rect = el.getBoundingRect();
            el.x = -rect.x + x;
            el.y = -rect.y + y;

            x += rect.width + 20;

            els.push(el);
            zr.add(el);
        });

        function update() {
            els.forEach(function (el) {
                el.setStyle({
                    strokePercent: config.percent
                })
            });
        }

        const config = {
            percent: 0,
            animatePercent: true
        };

        const gui = new dat.GUI();
        gui.add(config, 'percent', 0, 1).onChange(update);
        gui.add(config, 'animatePercent');

        setInterval(function () {
            if (config.animatePercent) {
                config.percent = (config.percent + 0.01) % 1;
                gui.updateDisplay();
                update();
            }
        }, 20);

        update();
    </script>
</body>
</html>