@malloydata/render 0.0.210-dev241107210431 → 0.0.210-dev241111185044

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.
@@ -58,11 +58,13 @@ const config: StorybookConfig = {
58
58
  },
59
59
  },
60
60
  server: {
61
- // Disable HMR for now, as we can't seem to get malloy core nor Lit to fully support it
61
+ // Disable HMR for now, as we can't seem to get malloy core nor web component to fully support it
62
62
  hmr: false,
63
63
  },
64
64
  define: {
65
- 'process.env': {},
65
+ 'process.env': {
66
+ 'IS_STORYBOOK': true,
67
+ },
66
68
  },
67
69
  assetsInclude: ['/sb-preview/runtime.js'],
68
70
  plugins: [viteMalloyStoriesPlugin()],
package/DEVELOPING.md CHANGED
@@ -75,6 +75,44 @@ Renderers are applied based on tags parsed on an Explore or Field. This is done
75
75
  1. Update the `shouldRenderAs` function that looks at the field tags and returns an enum for your renderer type
76
76
  2. Update the switch statement in the `applyRenderer` function to add a case for your new renderer. Your case statement should update the `renderValue` variable using your renderer.
77
77
 
78
+ ## Adding component CSS
79
+
80
+ The renderer is shipped as webcomponent, and any stylesheets should be appended to the ShadowDOM root instead of to the document. A utility is provided for doing this like so:
81
+
82
+ ```typescript
83
+ // in file my-component.ts
84
+
85
+ // import your stylesheet as a string
86
+ import myCss from "./style.css?raw";
87
+
88
+ export function MyComponent() {
89
+ // Add your imported CSS to the ShadowRoot
90
+ const config = useConfig();
91
+ config.addCSSToShadowRoot(myCSS);
92
+
93
+ // Use your classes in your markup
94
+ return <div class="my-component-class">hello world</div>
95
+ }
96
+ ```
97
+
98
+ There are certain cases where you may need to append CSS to the document; for example, when rendering a tooltip or modal that is attached to the DOM outside of the web component. You can add this document CSS like so:
99
+
100
+ ```typescript
101
+ // in file my-component.ts
102
+
103
+ // import your stylesheet as a string
104
+ import myCss from "./style.css?raw";
105
+
106
+ export function MyComponent() {
107
+ // Add your imported CSS to the document
108
+ const config = useConfig();
109
+ config.addCSSToDocument(myCSS);
110
+
111
+ // Use your classes in your markup
112
+ return <div class="my-component-class">hello world</div>
113
+ }
114
+ ```
115
+
78
116
  ## Renderer Metadata
79
117
 
80
118
  Some of the renderers, especially charts, benefit from having metadata about the data table being rendered. This can include attributes like the min and max values in a numeric column, the number of rows in a nested table, etc. This metadata is derived in `src/component/render-result-metadata.ts`. The `getResultMetadata` function is used to create the `RenderResultMetadata` object. This object is shared throughout our SolidJS component tree using the Context api. To access the metadata, use the `useResultContext()` method in a component.
@@ -118,10 +156,18 @@ For examples of how to use brushIn data and export brushOut data, see the bar ch
118
156
 
119
157
  ## Debugging tips
120
158
 
121
- TODO
159
+ In the Storybook, hovering any of the new charts will show a debug icon in the top right. Clicking the debug icon will open that chart with a text editor of the spec and a signal and data inspector. This UI can be used to see what is happening under the hood with the Vega chart, and allow you to experiment with changing the spec.
122
160
 
123
- - signal logging
124
- - vega introspection
161
+ You can also use the signal logger utility to log signal changes. This can be done in `chart.tsx` or `vega-chart.tsx` like so:
162
+
163
+ ```typescript
164
+ import {signalLogger} from './vega-utils';
165
+
166
+ // Somewhere in component code where View is accessible, create logger and log some signals
167
+ const logger = signalLogger(view, optionalId); // Optional string id which will be logged as well
168
+
169
+ logger('signalA', 'signalB'); // Logs any value changes to signalA or signalB
170
+ ```
125
171
 
126
172
  ## Generating builds
127
173
 
@@ -0,0 +1,6 @@
1
+ import { ChartProps } from './chart';
2
+ type ChartDevToolProps = {
3
+ onClose: () => void;
4
+ } & ChartProps;
5
+ export default function ChartDevTool(props: ChartDevToolProps): import("solid-js").JSX.Element;
6
+ export {};
@@ -1,7 +1,13 @@
1
+ /// <reference path="../../../src/vega.d.ts" />
1
2
  import { Explore, ExploreField, QueryData } from '@malloydata/malloy';
2
3
  import { RenderResultMetadata } from '../types';
3
- export declare function Chart(props: {
4
+ import { Runtime, View } from 'vega';
5
+ export type ChartProps = {
4
6
  field: Explore | ExploreField;
5
7
  data: QueryData;
6
8
  metadata: RenderResultMetadata;
7
- }): import("solid-js").JSX.Element;
9
+ devMode?: boolean;
10
+ runtime?: Runtime;
11
+ onView?: (view: View) => void;
12
+ };
13
+ export declare function Chart(props: ChartProps): import("solid-js").JSX.Element;
@@ -0,0 +1 @@
1
+ export declare function DebugIcon(): import("solid-js").JSX.Element;
@@ -1,12 +1,14 @@
1
+ /// <reference path="../../src/vega.d.ts" />
1
2
  import { Explore, ExploreField, Field, Tag } from '@malloydata/malloy';
3
+ import { AlignValue, TextBaselineValue } from 'vega';
2
4
  import { RenderResultMetadata } from './types';
3
5
  export type ChartLayoutSettings = {
4
6
  plotWidth: number;
5
7
  plotHeight: number;
6
8
  xAxis: {
7
9
  labelAngle: number;
8
- labelAlign?: string;
9
- labelBaseline?: string;
10
+ labelAlign?: AlignValue;
11
+ labelBaseline?: TextBaselineValue;
10
12
  labelLimit: number;
11
13
  height: number;
12
14
  titleSize: number;
@@ -1,5 +1,4 @@
1
1
  import { DataArray } from '@malloydata/malloy';
2
- import './dashboard.css';
3
2
  export declare function Dashboard(props: {
4
3
  data: DataArray;
5
4
  scrollEl?: HTMLElement;
@@ -1,2 +1,2 @@
1
1
  import { AtomicField, DataColumn } from '@malloydata/malloy';
2
- export declare function renderLink(f: AtomicField, data: DataColumn): import("solid-js").JSX.Element | "∅";
2
+ export declare function renderLink(f: AtomicField, data: DataColumn): "∅" | import("solid-js").JSX.Element;
@@ -1,2 +1,2 @@
1
1
  import { RendererProps } from './apply-renderer';
2
- export declare function renderList(props: RendererProps): import("solid-js").JSX.Element | "∅";
2
+ export declare function renderList(props: RendererProps): "∅" | import("solid-js").JSX.Element;
@@ -13,6 +13,9 @@ export type MalloyRenderProps = {
13
13
  export declare const useConfig: () => {
14
14
  onClick?: ((payload: MalloyClickEventPayload) => void) | undefined;
15
15
  vegaConfigOverride?: VegaConfigHandler | undefined;
16
+ element: ICustomElement;
17
+ addCSSToShadowRoot: (css: string) => void;
18
+ addCSSToDocument: (id: string, css: string) => void;
16
19
  };
17
20
  export declare function MalloyRender(props: MalloyRenderProps, { element }: ComponentOptions): import("solid-js").JSX.Element;
18
21
  export declare function MalloyRenderInner(props: {
@@ -1,6 +1,5 @@
1
1
  import { Component } from 'solid-js';
2
2
  import { DataArrayOrRecord } from '@malloydata/malloy';
3
- import './table.css';
4
3
  declare const MalloyTable: Component<{
5
4
  data: DataArrayOrRecord;
6
5
  rowLimit?: number;
@@ -1,12 +1,20 @@
1
1
  /// <reference path="../../src/vega.d.ts" />
2
2
  import { DataColumn, DataRecord, Explore, Field, QueryData, QueryDataRow, Tag } from '@malloydata/malloy';
3
- import { Item, Runtime, View } from 'vega';
3
+ import { Item, Runtime, Spec, View } from 'vega';
4
4
  import { JSX } from 'solid-js';
5
5
  import { ResultStore } from './result-store/result-store';
6
- export type VegaSpec = any;
6
+ export type VegaSignalRef = {
7
+ signal: string;
8
+ };
9
+ export type VegaPadding = {
10
+ top?: number;
11
+ left?: number;
12
+ right?: number;
13
+ bottom?: number;
14
+ };
7
15
  export type MalloyDataToChartDataHandler = (field: Explore, data: QueryData) => unknown[];
8
16
  export type VegaChartProps = {
9
- spec: VegaSpec;
17
+ spec: Spec;
10
18
  plotWidth: number;
11
19
  plotHeight: number;
12
20
  totalWidth: number;
@@ -1,3 +1,5 @@
1
+ /// <reference path="../../../src/vega.d.ts" />
2
+ import { Axis, GroupMark, RectMark } from 'vega';
1
3
  import { ChartLayoutSettings } from '../chart-layout-settings';
2
4
  type MeasureAxisOptions = {
3
5
  type: 'y';
@@ -11,8 +13,8 @@ type MeasureAxisOptions = {
11
13
  axisSettings: ChartLayoutSettings['yAxis'];
12
14
  };
13
15
  export declare function createMeasureAxis({ type, title, tickCount, labelLimit, fieldPath, showBrushes, axisSettings, }: MeasureAxisOptions): {
14
- axis: any;
15
- interactiveMarks: any[];
16
+ axis: Axis;
17
+ interactiveMarks: (GroupMark | RectMark)[];
16
18
  interactiveSignals: never[];
17
19
  brushMeasureEvents: {
18
20
  events: string;
@@ -1,5 +1,6 @@
1
+ /// <reference path="../../src/vega.d.ts" />
1
2
  import * as lite from 'vega-lite';
2
- import { VegaSpec } from '../component/types';
3
+ import { Config } from 'vega';
3
4
  export type DataStyles = {
4
5
  [fieldName: string]: RenderDef;
5
6
  };
@@ -159,7 +160,7 @@ export interface ChartRenderOptions extends DataRenderOptions {
159
160
  color?: string;
160
161
  shape?: string;
161
162
  };
162
- vegaConfigOverride?: VegaSpec;
163
+ vegaConfigOverride?: Config;
163
164
  }
164
165
  export interface CartesianChartRenderOptions extends ChartRenderOptions {
165
166
  chart?: {