@uwdata/mosaic-spec 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, UW Interactive Data Lab
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # mosaic-spec
2
+
3
+ Declarative specification of Mosaic-powered applications as JSON or YAML files. This package provides a parser and code generation framework for reading specifications in a JSON format and generating live Mosaic visualizations and dashboards using the [vgplot](https://github.com/uwdata/mosaic/tree/main/packages/vgplot) API.
4
+
5
+ ## Usage
6
+
7
+ To parse a specification and generate round-trip JSON output (`.toJSON()`), JavaScript module code (`astToESM`), or a live web application (`astToDOM`):
8
+
9
+ ```js
10
+ import { parseSpec, astToDOM, astToESM } from '@uwdata/mosaic-spec';
11
+
12
+ // declarative specification in JSON format
13
+ const spec = {
14
+ plot: [
15
+ {
16
+ mark: 'lineY',
17
+ data: { from: 'table' },
18
+ x: 'date',
19
+ y: 'value'
20
+ }
21
+ ],
22
+ width: 640,
23
+ height: 200
24
+ };
25
+
26
+ // parse specification to internal AST (abstract syntax tree)
27
+ const ast = parseSpec(spec);
28
+
29
+ // serialize back to a normalized JSON format
30
+ const json = ast.toJSON();
31
+
32
+ // generate ESM (ECMAScript Module) code
33
+ const code = astToESM(ast);
34
+
35
+ // instantiate a running application
36
+ // assumes standard browser facilities in globabl variable `window`
37
+ const {
38
+ element, // root DOM element of the application
39
+ params // Map of all named Params and Selections
40
+ } = await astToDOM(ast);
41
+
42
+ // add application to current web page
43
+ document.body.appendChild(element);
44
+ ```
45
+
46
+ To parse specifications in YAML format, import the `yaml` library and use it to parse input specification files:
47
+
48
+ ```js
49
+ import { parseSpec } from '@uwdata/mosaic-spec';
50
+ import { parse } from 'yaml';
51
+
52
+ const yaml = /* load yaml file file */;
53
+ const spec = parse(yaml); // parse yaml to JS objects
54
+
55
+ // parse specification to internal AST (abstract syntax tree)
56
+ const ast = parseSpec(spec);
57
+ ```