@malloydata/render 0.0.94 → 0.0.95-dev231024220124

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.
@@ -0,0 +1,46 @@
1
+ import {join, dirname} from 'path';
2
+ import {mergeConfig} from 'vite';
3
+ import {StorybookConfig} from '@storybook/html-vite';
4
+
5
+ /**
6
+ * This function is used to resolve the absolute path of a package.
7
+ * It is needed in projects that use Yarn PnP or are set up within a monorepo.
8
+ */
9
+ function getAbsolutePath(value) {
10
+ return dirname(require.resolve(join(value, 'package.json')));
11
+ }
12
+
13
+ const config: StorybookConfig = {
14
+ 'stories': ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
15
+ staticDirs: ['../src/stories/static'],
16
+ 'addons': [
17
+ getAbsolutePath('@storybook/addon-links'),
18
+ getAbsolutePath('@storybook/addon-essentials'),
19
+ getAbsolutePath('@storybook/addon-interactions'),
20
+ ],
21
+ 'framework': {
22
+ 'name': '@storybook/html-vite',
23
+ 'options': {},
24
+ },
25
+ 'docs': {
26
+ 'autodocs': 'tag',
27
+ },
28
+ async viteFinal(config, {configType}) {
29
+ if (configType === 'DEVELOPMENT') {
30
+ // Your development configuration goes here
31
+ }
32
+ if (configType === 'PRODUCTION') {
33
+ // Your production configuration goes here.
34
+ }
35
+ const finalConfig = mergeConfig(config, {
36
+ resolve: {
37
+ preserveSymlinks: true,
38
+ },
39
+ define: {
40
+ 'process.env': {},
41
+ },
42
+ });
43
+ return finalConfig;
44
+ },
45
+ };
46
+ export default config;
@@ -0,0 +1,33 @@
1
+ import {DuckDBWASMConnection} from '@malloydata/db-duckdb/wasm';
2
+ import {Preview} from '@storybook/html';
3
+ import registeredData from './registered_data.json';
4
+
5
+ async function createConnection() {
6
+ const connection = new DuckDBWASMConnection('duckdb');
7
+ await connection.connecting;
8
+ for (let tableName of registeredData) {
9
+ const fullTableName = `data/${tableName}`;
10
+ await connection.registerRemoteTable(
11
+ fullTableName,
12
+ new window.URL(fullTableName, window.location.href).toString()
13
+ );
14
+ }
15
+ return connection;
16
+ }
17
+
18
+ const preview: Preview = {
19
+ parameters: {
20
+ actions: {argTypesRegex: '^on[A-Z].*'},
21
+ controls: {
22
+ matchers: {
23
+ color: /(background|color)$/i,
24
+ date: /Date$/i,
25
+ },
26
+ },
27
+ },
28
+ globals: {
29
+ connection: createConnection(),
30
+ },
31
+ };
32
+
33
+ export default preview;
@@ -0,0 +1 @@
1
+ ["products.parquet"]
package/README.md CHANGED
@@ -5,3 +5,15 @@ Malloy is an experimental language for describing data relationships and transfo
5
5
  ## This package
6
6
 
7
7
  This package provides a simple mechanism to render charts based on results from using the `malloydata/malloy` library. See [here](https://github.com/malloydata/malloy/blob/main/packages/malloy/README.md) for additional information.
8
+
9
+ ## Developing locally with Storybook
10
+
11
+ Run `npm run storybook` to launch a Storybook app in your browser. This app will hot reload as you make changes to the renderer source.
12
+
13
+ Stories are written in the `src/stories` directory. To add more data and Malloy files for your stories to consume, you must:
14
+
15
+ - put .malloy files in `src/stories/static`
16
+ - put data files in `src/stories/static/data`
17
+ - register data files be loaded into the DuckDB WASM connection by adding the file name to `.storybook/registered_data.json`
18
+
19
+ [Take a look at the Basic story as an example.](./src/stories/basic.stories.ts)
package/dist/drill.js CHANGED
@@ -102,7 +102,7 @@ function getDrillFilters(data) {
102
102
  exports.getDrillFilters = getDrillFilters;
103
103
  function getDrillQuery(data) {
104
104
  const { formattedFilters, source } = getDrillFilters(data);
105
- let ret = `query: ${(source === null || source === void 0 ? void 0 : source.name) || '"unable to compute source"'} `;
105
+ let ret = `run: ${(source === null || source === void 0 ? void 0 : source.name) || '"unable to compute source"'} `;
106
106
  if (formattedFilters.length) {
107
107
  ret += `{ \n where: \n ${formattedFilters.join(',\n ')}\n \n}\n`;
108
108
  }
@@ -37,13 +37,13 @@ class HTMLImageRenderer {
37
37
  ? (0, utils_1.createNullElement)(this.document)
38
38
  : this.document.createElement('img');
39
39
  const { tag } = data.field.tagParse();
40
- const width = tag.numeric('image', 'width');
41
- const height = tag.numeric('image', 'height');
40
+ const width = tag.text('image', 'width');
41
+ const height = tag.text('image', 'height');
42
42
  // Both image and null placeholder get matching size
43
43
  if (width)
44
- element.style.width = `${width}px`;
44
+ element.style.width = width;
45
45
  if (height)
46
- element.style.height = `${height}px`;
46
+ element.style.height = height;
47
47
  // Image specific props
48
48
  if (!data.isNull()) {
49
49
  const alt = tag.text('image', 'alt');
@@ -0,0 +1,25 @@
1
+ declare const _default: {
2
+ title: string;
3
+ render: ({ source, view }: {
4
+ source: any;
5
+ view: any;
6
+ }, { globals: { connection } }: {
7
+ globals: {
8
+ connection: any;
9
+ };
10
+ }) => HTMLDivElement;
11
+ argTypes: {};
12
+ };
13
+ export default _default;
14
+ export declare const ProductsTable: {
15
+ args: {
16
+ source: string;
17
+ view: string;
18
+ };
19
+ };
20
+ export declare const ProductsBar: {
21
+ args: {
22
+ source: string;
23
+ view: string;
24
+ };
25
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ProductsBar = exports.ProductsTable = void 0;
7
+ const basic_malloy_raw_1 = __importDefault(require("./static/basic.malloy?raw"));
8
+ const render_malloy_1 = require("./render-malloy");
9
+ exports.default = {
10
+ title: 'Malloy/Basic',
11
+ render: ({ source, view }, { globals: { connection } }) => {
12
+ return (0, render_malloy_1.renderMalloy)({ script: basic_malloy_raw_1.default, source, view, connection });
13
+ },
14
+ argTypes: {},
15
+ };
16
+ exports.ProductsTable = {
17
+ args: {
18
+ source: 'products',
19
+ view: '{ select: * }',
20
+ },
21
+ };
22
+ exports.ProductsBar = {
23
+ args: {
24
+ source: 'products',
25
+ view: 'category_bar',
26
+ },
27
+ };
28
+ //# sourceMappingURL=basic.stories.js.map
@@ -0,0 +1,9 @@
1
+ import { DuckDBWASMConnection } from '@malloydata/db-duckdb/wasm';
2
+ type RenderOptions = {
3
+ script: string;
4
+ source: string;
5
+ view: string;
6
+ connection: Promise<DuckDBWASMConnection>;
7
+ };
8
+ export declare function renderMalloy(options: RenderOptions): HTMLDivElement;
9
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderMalloy = void 0;
4
+ const malloy_1 = require("@malloydata/malloy");
5
+ const html_1 = require("../html");
6
+ async function runAndRender({ script, source, view, connection }) {
7
+ const conn = await connection;
8
+ const runtime = new malloy_1.SingleConnectionRuntime(conn);
9
+ const model = runtime.loadModel(script);
10
+ const runner = model.loadQuery(`run: ${source} -> ${view}`);
11
+ const viewer = new html_1.HTMLView(document);
12
+ const result = await runner.run();
13
+ return await viewer.render(result, { dataStyles: {} });
14
+ }
15
+ function renderMalloy(options) {
16
+ const div = document.createElement('div');
17
+ runAndRender(options).then(el => div.replaceChildren(el));
18
+ return div;
19
+ }
20
+ exports.renderMalloy = renderMalloy;
21
+ //# sourceMappingURL=render-malloy.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/render",
3
- "version": "0.0.94",
3
+ "version": "0.0.95-dev231024220124",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,10 +18,12 @@
18
18
  "test": "jest --config=../../jest.config.js",
19
19
  "build": "tsc --build",
20
20
  "clean": "tsc --build --clean",
21
- "prepublishOnly": "npm run build"
21
+ "prepublishOnly": "npm run build",
22
+ "storybook": "storybook dev -p 6006",
23
+ "build-storybook": "storybook build"
22
24
  },
23
25
  "dependencies": {
24
- "@malloydata/malloy": "^0.0.94",
26
+ "@malloydata/malloy": "^0.0.95-dev231024220124",
25
27
  "@types/luxon": "^2.4.0",
26
28
  "lodash": "^4.17.20",
27
29
  "luxon": "^2.4.0",
@@ -29,5 +31,15 @@
29
31
  "us-atlas": "^3.0.0",
30
32
  "vega": "^5.21.0",
31
33
  "vega-lite": "^5.2.0"
34
+ },
35
+ "devDependencies": {
36
+ "@storybook/addon-essentials": "^7.5.0",
37
+ "@storybook/addon-interactions": "^7.5.0",
38
+ "@storybook/addon-links": "^7.5.0",
39
+ "@storybook/blocks": "^7.5.0",
40
+ "@storybook/html": "^7.5.0",
41
+ "@storybook/html-vite": "^7.5.0",
42
+ "@storybook/testing-library": "^0.2.2",
43
+ "storybook": "^7.5.0"
32
44
  }
33
45
  }