@kanaries/graphic-walker 0.3.11 → 0.3.13

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.
@@ -1,4 +1,4 @@
1
- import { Config as VgConfig } from 'vega';
1
+ import { Config as VgConfig, View } from 'vega';
2
2
  import { Config as VlConfig } from 'vega-lite';
3
3
  export type DeepReadonly<T extends Record<keyof any, any>> = {
4
4
  readonly [K in keyof T]: T[K] extends Record<keyof any, any> ? DeepReadonly<T[K]> : T[K];
@@ -191,6 +191,16 @@ export declare enum ISegmentKey {
191
191
  export type IThemeKey = 'vega' | 'g2';
192
192
  export type IDarkMode = 'media' | 'light' | 'dark';
193
193
  export type VegaGlobalConfig = VgConfig | VlConfig;
194
+ export interface IVegaChartRef {
195
+ x: number;
196
+ y: number;
197
+ w: number;
198
+ h: number;
199
+ innerWidth: number;
200
+ innerHeight: number;
201
+ view: View;
202
+ canvas: HTMLCanvasElement | null;
203
+ }
194
204
  export interface IChartExportResult<T extends 'svg' | 'data-url' = 'svg' | 'data-url'> {
195
205
  mode: T;
196
206
  title: string;
@@ -201,14 +211,81 @@ export interface IChartExportResult<T extends 'svg' | 'data-url' = 'svg' | 'data
201
211
  rowIndex: number;
202
212
  width: number;
203
213
  height: number;
214
+ canvasWidth: number;
215
+ canvasHeight: number;
204
216
  data: string;
217
+ canvas(): HTMLCanvasElement | null;
205
218
  }[];
219
+ container(): HTMLDivElement | null;
206
220
  }
207
221
  interface IExportChart {
208
222
  <T extends Extract<IChartExportResult['mode'], 'svg'>>(mode?: T): Promise<IChartExportResult<T>>;
209
223
  <T extends IChartExportResult['mode']>(mode: T): Promise<IChartExportResult<T>>;
210
224
  }
225
+ export interface IChartListExportResult<T extends 'svg' | 'data-url' = 'svg' | 'data-url'> {
226
+ mode: T;
227
+ total: number;
228
+ index: number;
229
+ data: IChartExportResult<T>;
230
+ hasNext: boolean;
231
+ }
232
+ interface IExportChartList {
233
+ <T extends Extract<IChartExportResult['mode'], 'svg'>>(mode?: T): AsyncGenerator<IChartListExportResult<T>, void, unknown>;
234
+ <T extends IChartExportResult['mode']>(mode: T): AsyncGenerator<IChartListExportResult<T>, void, unknown>;
235
+ }
236
+ /**
237
+ * The status of the current chart.
238
+ * * `computing`: _GraphicWalker_ is computing the data view.
239
+ * * `rendering`: _GraphicWalker_ is rendering the chart.
240
+ * * `idle`: rendering is finished.
241
+ * * `error`: an error occurs during the process above.
242
+ */
243
+ export type IRenderStatus = 'computing' | 'rendering' | 'idle' | 'error';
211
244
  export interface IGWHandler {
245
+ /** length of the "chart" tab list */
246
+ chartCount: number;
247
+ /** current selected chart index */
248
+ chartIndex: number;
249
+ /** Switches to the specified chart */
250
+ openChart: (index: number) => void;
251
+ /**
252
+ * Returns the status of the current chart.
253
+ *
254
+ * It is computed by the following rules:
255
+ * - If _GraphicWalker_ is computing the data view, it returns `computing`.
256
+ * - If _GraphicWalker_ is rendering the chart, it returns `rendering`.
257
+ * - If rendering is finished, it returns `idle`.
258
+ * - If an error occurs during the process above, it returns `error`.
259
+ */
260
+ get renderStatus(): IRenderStatus;
261
+ /**
262
+ * Registers a callback function to listen to the status change of the current chart.
263
+ *
264
+ * @param {(renderStatus: IRenderStatus) => void} cb - the callback function
265
+ * @returns {() => void} a dispose function to remove this callback
266
+ */
267
+ onRenderStatusChange: (cb: (renderStatus: IRenderStatus) => void) => (() => void);
268
+ /**
269
+ * Exports the current chart.
270
+ *
271
+ * @param {IChartExportResult['mode']} [mode='svg'] - the export mode, either `svg` or `data-url`
272
+ */
212
273
  exportChart: IExportChart;
274
+ /**
275
+ * Exports all charts.
276
+ *
277
+ * @param {IChartExportResult['mode']} [mode='svg'] - the export mode, either `svg` or `data-url`
278
+ * @returns {AsyncGenerator<IChartListExportResult, void, unknown>} an async generator to iterate over all charts
279
+ * @example
280
+ * ```ts
281
+ * for await (const chart of gwRef.current.exportChartList()) {
282
+ * console.log(chart);
283
+ * }
284
+ * ```
285
+ */
286
+ exportChartList: IExportChartList;
287
+ }
288
+ export interface IGWHandlerInsider extends IGWHandler {
289
+ updateRenderStatus: (renderStatus: IRenderStatus) => void;
213
290
  }
214
291
  export {};
@@ -1,13 +1,5 @@
1
- import React from 'react';
2
- import type { IDarkMode, IRow, IThemeKey, DraggableFieldState, IVisualConfig } from '../interfaces';
3
- import type { IReactVegaHandler } from '../vis/react-vega';
4
- interface IPureRendererProps {
5
- name?: string;
6
- themeKey?: IThemeKey;
7
- dark?: IDarkMode;
8
- rawData?: IRow[];
9
- visualState: DraggableFieldState;
10
- visualConfig: IVisualConfig;
11
- }
12
- declare const _default: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<IPureRendererProps & React.RefAttributes<IReactVegaHandler>, "key" | keyof IPureRendererProps> & React.RefAttributes<IReactVegaHandler>>>;
1
+ /// <reference types="react" />
2
+ declare const _default: ((props: object) => JSX.Element) & {
3
+ displayName: string;
4
+ };
13
5
  export default _default;
@@ -0,0 +1,7 @@
1
+ interface IUseChartIndexControlOptions {
2
+ count: number;
3
+ index: number;
4
+ onChange: (index: number) => void;
5
+ }
6
+ export declare const useChartIndexControl: (options: IUseChartIndexControlOptions) => void;
7
+ export {};
@@ -1,10 +1,4 @@
1
- import { type ForwardedRef, type MutableRefObject } from "react";
2
- import type { View } from "vega";
1
+ import { type ForwardedRef, type MutableRefObject, RefObject } from "react";
3
2
  import type { IReactVegaHandler } from "../vis/react-vega";
4
- export declare const useVegaExportApi: (name: string | undefined, viewsRef: MutableRefObject<{
5
- x: number;
6
- y: number;
7
- w: number;
8
- h: number;
9
- view: View;
10
- }[]>, ref: ForwardedRef<IReactVegaHandler>) => void;
3
+ import type { IVegaChartRef } from "../interfaces";
4
+ export declare const useVegaExportApi: (name: string | undefined, viewsRef: MutableRefObject<IVegaChartRef[]>, ref: ForwardedRef<IReactVegaHandler>, renderTaskRefs: MutableRefObject<Promise<unknown>[]>, containerRef: RefObject<HTMLDivElement>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kanaries/graphic-walker",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "scripts": {
5
5
  "dev:front_end": "vite --host",
6
6
  "dev": "npm run dev:front_end",
@@ -38,6 +38,7 @@
38
38
  "@heroicons/react": "^2.0.8",
39
39
  "@kanaries/react-beautiful-dnd": "0.0.2",
40
40
  "@kanaries/web-data-loader": "^0.1.7",
41
+ "@tailwindcss/forms": "^0.5.4",
41
42
  "autoprefixer": "^10.3.5",
42
43
  "i18next": "^21.9.1",
43
44
  "i18next-browser-languagedetector": "^6.1.5",