File: test-scalefactor.html

package info (click to toggle)
node-vega-embed 6.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,016 kB
  • sloc: javascript: 50; sh: 8; makefile: 5
file content (58 lines) | stat: -rw-r--r-- 1,559 bytes parent folder | download
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
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Vega-Embed for Vega-Lite</title>

    <script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
    <script src="https://cdn.jsdelivr.net/npm/vega-lite@5"></script>
    <script src="build/vega-embed.js"></script>
  </head>

  <body>
    <div id="vis"></div>
    <script>
      async function run() {
        // const scaleFactor = 5;
        // or
        // const scaleFactor = { svg: 2, png: 5 };
        // or
        // const scaleFactor = { svg: 2 };
        // or
        const scaleFactor = { png: 5 };

        const spec = {
          $schema: "https://vega.github.io/schema/vega-lite/v5.json",
          data: {
            values: [
              { a: "A", b: 28 },
              { a: "B", b: 55 },
              { a: "C", b: 43 },
              { a: "D", b: 91 },
              { a: "E", b: 81 },
              { a: "F", b: 53 },
              { a: "G", b: 19 },
              { a: "H", b: 87 },
              { a: "I", b: 52 },
            ],
          },
          mark: "bar",
          encoding: {
            x: { field: "a", type: "nominal" },
            y: { field: "b", type: "quantitative" },
            tooltip: { field: "b", type: "quantitative" },
          },
        };

        const result = await vegaEmbed("#vis", spec, {
          scaleFactor,
          tooltip: { theme: "dark" },
        });

        console.log(result);
      }
      run();
    </script>
  </body>
</html>