@visactor/taro-vchart 0.10.0-alpha.2 → 0.11.6-alpha.1

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 @@
1
+ export * from '@visactor/vchart/build/es5';
@@ -1,14 +1,4 @@
1
- import { IChartProps, VChartEnvType } from './typings';
2
- interface IVChartProps extends IChartProps {
3
- /**
4
- * 配置环境。如果没有声明,则会通过 `Taro.getEnv()` 自动获取。
5
- * - `tt` 字节小程序。
6
- * - `lark` 飞书小程序。
7
- * - `weapp` 微信小程序
8
- * - `h5` 浏览器环境, 与`web`等价。
9
- * - `web` 浏览器环境, 与`h5`等价。
10
- */
11
- type?: VChartEnvType;
12
- }
1
+ import { IVChartProps } from './typings';
2
+ import { VChartSimple } from './simple';
13
3
  export default function VChart({ type, ...args }: IVChartProps): any;
14
- export { VChart };
4
+ export { VChart, VChartSimple };
package/lib/src/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import VChart$1, { vglobal, registerLarkEnv, registerWXEnv } from '@visactor/vchart/build/es5';
3
2
  import { View, Canvas } from '@tarojs/components';
4
3
  import Taro from '@tarojs/taro';
4
+ import { VChart as VChart$1, registerLarkEnv, registerTTEnv, registerWXEnv } from '@visactor/vchart/build/es5';
5
5
 
6
6
  /*! *****************************************************************************
7
7
  Copyright (c) Microsoft Corporation.
@@ -45,8 +45,11 @@ class WebChart extends React.Component {
45
45
  super(props);
46
46
  }
47
47
  componentDidMount() {
48
- const { onChartInit, onChartReady, mode } = this.props;
49
- this.vchart = new VChart$1(this.props.spec, Object.assign({ dom: `${this.props.canvasId}`, mode }, this.props.options));
48
+ const { onChartInit, onChartReady, mode, chartConstructor } = this.props;
49
+ if (!chartConstructor) {
50
+ console.error('chartConstructor not found');
51
+ }
52
+ this.vchart = new chartConstructor(this.props.spec, Object.assign({ dom: `${this.props.canvasId}`, mode }, this.props.options));
50
53
  onChartInit && onChartInit(this.vchart);
51
54
  this.vchart
52
55
  .renderAsync()
@@ -77,10 +80,10 @@ class WebChart extends React.Component {
77
80
  }
78
81
  }
79
82
 
80
- // @ts-ignore
81
83
  class TTCanvas {
82
84
  constructor(props) {
83
- const { dpr, events, spec, options, domref, mode, onChartInit, onChartReady, onChartUpdate } = props;
85
+ const { chartConstructor, dpr, events, spec, options, domref, mode, onChartInit, onChartReady, onChartUpdate } = props;
86
+ this.chartConstructor = chartConstructor;
84
87
  this.domref = domref;
85
88
  this.mode = mode || 'miniApp';
86
89
  this.dpr = dpr;
@@ -101,7 +104,7 @@ class TTCanvas {
101
104
  }
102
105
  init() {
103
106
  const domref = this.domref;
104
- this.chartInstance = new VChart$1(Object.assign({ width: domref.width, height: domref.height }, this.spec), Object.assign({ mode: this.mode,
107
+ this.chartInstance = new this.chartConstructor(Object.assign({ width: domref.width, height: domref.height }, this.spec), Object.assign({ mode: this.mode,
105
108
  // 跨端参数
106
109
  modeParams: {
107
110
  domref,
@@ -176,6 +179,9 @@ const style_container = {
176
179
  class GeneralChart extends React.Component {
177
180
  componentDidMount() {
178
181
  return __awaiter(this, void 0, void 0, function* () {
182
+ if (!this.props.chartConstructor) {
183
+ console.error('props.chartConstructor is not found');
184
+ }
179
185
  if (!this.props.spec || !this.props.canvasId) {
180
186
  if (!this.props.spec)
181
187
  console.warn('props.spec are not found');
@@ -244,17 +250,28 @@ class GeneralChart extends React.Component {
244
250
  console.error(`未找到 #${this.props.canvasId} 组件`);
245
251
  return;
246
252
  }
247
- if (this.props.mode === 'wx') {
248
- // 微信小程序环境特殊处理
253
+ if (this.props.mode === 'wx' || this.props.mode === 'tt') {
254
+ // 微信小程序和TT小程序环境特殊处理
249
255
  const canvasIdLists = [
250
256
  `${this.props.canvasId}_draw_canvas`,
251
257
  `${this.props.canvasId}_tooltip_canvas`,
252
258
  `${this.props.canvasId}_hidden_canvas`
253
259
  ];
254
- yield vglobal.setEnv('wx', { domref, force: true, canvasIdLists, freeCanvasIdx: 2, component: undefined });
260
+ const { chartConstructor } = this.props;
261
+ const { vglobal } = chartConstructor;
262
+ if (vglobal) {
263
+ yield vglobal.setEnv(this.props.mode, {
264
+ domref,
265
+ force: true,
266
+ canvasIdLists,
267
+ freeCanvasIdx: 2,
268
+ component: undefined
269
+ });
270
+ }
255
271
  }
256
272
  domref.id = this.props.canvasId;
257
273
  this.ttCanvas = new TTCanvas({
274
+ chartConstructor: this.props.chartConstructor,
258
275
  dpr: dpr,
259
276
  domref,
260
277
  spec: this.props.spec,
@@ -288,27 +305,25 @@ class GeneralChart extends React.Component {
288
305
  }
289
306
  };
290
307
  const { canvasId, style = {} } = this.props;
308
+ const type = this.props.mode === 'wx' || this.props.mode === 'tt' ? '2d' : undefined;
291
309
  return (React.createElement(View, { key: canvasId, style: Object.assign(Object.assign(Object.assign({}, style_container), style), { padding: 0 }) },
292
- React.createElement(Canvas, { type: this.props.mode === 'wx' ? '2d' : undefined, style: Object.assign({}, style_cs_tooltip_canvas), id: `${canvasId}_tooltip_canvas`, canvasId: `${canvasId}_tooltip_canvas` }),
293
- React.createElement(Canvas, { type: this.props.mode === 'wx' ? '2d' : undefined, onTouchStart: handleEvent, onTouchMove: handleEvent, onTouchEnd: handleEvent, style: style_cs_canvas, id: `${canvasId}_draw_canvas`, canvasId: `${canvasId}_draw_canvas` }),
294
- React.createElement(Canvas, { type: this.props.mode === 'wx' ? '2d' : undefined, style: Object.assign(Object.assign({}, style_cs_canvas), style_cs_canvas_hidden), id: `${canvasId}_hidden_canvas`, canvasId: `${canvasId}_hidden_canvas` })));
310
+ React.createElement(Canvas, { type: type, style: Object.assign({}, style_cs_tooltip_canvas), id: `${canvasId}_tooltip_canvas`, canvasId: `${canvasId}_tooltip_canvas` }),
311
+ React.createElement(Canvas, { type: type, onTouchStart: handleEvent, onTouchMove: handleEvent, onTouchEnd: handleEvent, style: style_cs_canvas, id: `${canvasId}_draw_canvas`, canvasId: `${canvasId}_draw_canvas` }),
312
+ React.createElement(Canvas, { type: type, style: Object.assign(Object.assign({}, style_cs_canvas), style_cs_canvas_hidden), id: `${canvasId}_hidden_canvas`, canvasId: `${canvasId}_hidden_canvas` })));
295
313
  }
296
314
  }
297
315
 
298
- function VChart(_a) {
316
+ function VChartSimple(_a) {
299
317
  var { type } = _a, args = __rest(_a, ["type"]);
300
318
  const env = (type !== null && type !== void 0 ? type : Taro.getEnv()).toLocaleLowerCase();
301
319
  const strategies = {
302
320
  lark: () => {
303
- registerLarkEnv();
304
321
  return React.createElement(GeneralChart, Object.assign({}, args, { mode: "miniApp" }));
305
322
  },
306
323
  tt: () => {
307
- registerLarkEnv();
308
- return React.createElement(GeneralChart, Object.assign({}, args, { mode: "miniApp" }));
324
+ return React.createElement(GeneralChart, Object.assign({}, args, { mode: "tt" }));
309
325
  },
310
326
  weapp: () => {
311
- registerWXEnv();
312
327
  return React.createElement(GeneralChart, Object.assign({}, args, { mode: "wx" }));
313
328
  },
314
329
  web: () => {
@@ -325,4 +340,36 @@ function VChart(_a) {
325
340
  return React.createElement(GeneralChart, Object.assign({}, args));
326
341
  }
327
342
 
328
- export { VChart, VChart as default };
343
+ function VChart(_a) {
344
+ var { type } = _a, args = __rest(_a, ["type"]);
345
+ const env = (type !== null && type !== void 0 ? type : Taro.getEnv()).toLocaleLowerCase();
346
+ // @ts-ignore
347
+ const props = Object.assign({ chartConstructor: VChart$1 }, args);
348
+ const strategies = {
349
+ lark: () => {
350
+ registerLarkEnv();
351
+ return React.createElement(GeneralChart, Object.assign({}, props, { mode: "miniApp" }));
352
+ },
353
+ tt: () => {
354
+ registerTTEnv();
355
+ return React.createElement(GeneralChart, Object.assign({}, props, { mode: "tt" }));
356
+ },
357
+ weapp: () => {
358
+ registerWXEnv();
359
+ return React.createElement(GeneralChart, Object.assign({}, props, { mode: "wx" }));
360
+ },
361
+ web: () => {
362
+ return React.createElement(WebChart, Object.assign({}, props));
363
+ },
364
+ h5: () => {
365
+ return React.createElement(WebChart, Object.assign({}, props, { mode: "mobile-browser" }));
366
+ }
367
+ };
368
+ if (env && strategies[env] !== undefined) {
369
+ return strategies[env].call();
370
+ }
371
+ console.warn(`暂不支持 ${env} 环境`);
372
+ return React.createElement(GeneralChart, Object.assign({}, props));
373
+ }
374
+
375
+ export { VChart, VChartSimple, VChart as default };
@@ -0,0 +1,2 @@
1
+ import { IVChartProps } from './typings';
2
+ export declare function VChartSimple({ type, ...args }: IVChartProps): any;
@@ -1,8 +1,13 @@
1
1
  import { CSSProperties } from 'react';
2
2
  import { IOptions } from './IOptions';
3
- import { IVChart, ISpec } from './IVChart';
3
+ import { IVChart, ISpec, IVChartConstructor } from './IVChart';
4
4
  import { IEvent } from './IEvent';
5
+ import { VChartEnvType } from './VChartEnvType';
5
6
  interface IChartProps {
7
+ /**
8
+ * 图表构造函数,必须
9
+ */
10
+ chartConstructor: IVChartConstructor;
6
11
  /**
7
12
  * 图表 id, 必确唯一
8
13
  */
@@ -42,4 +47,15 @@ interface IChartProps {
42
47
  */
43
48
  onChartUpdate?: (chart: IVChart) => void;
44
49
  }
45
- export { IChartProps };
50
+ interface IVChartProps extends IChartProps {
51
+ /**
52
+ * 配置环境。如果没有声明,则会通过 `Taro.getEnv()` 自动获取。
53
+ * - `tt` 字节小程序。
54
+ * - `lark` 飞书小程序。
55
+ * - `weapp` 微信小程序
56
+ * - `h5` 浏览器环境, 与`web`等价。
57
+ * - `web` 浏览器环境, 与`h5`等价。
58
+ */
59
+ type?: VChartEnvType;
60
+ }
61
+ export { IChartProps, IVChartProps };
@@ -1,2 +1,2 @@
1
- import { IVChart, ISpec, RenderMode } from '@visactor/vchart';
2
- export { IVChart, ISpec, RenderMode };
1
+ import type { IVChart, ISpec, RenderMode, IVChartConstructor } from '@visactor/vchart';
2
+ export { IVChart, ISpec, RenderMode, IVChartConstructor };
@@ -1,5 +1,5 @@
1
- export { IChartProps } from './IChartProps';
2
- export { IVChart, RenderMode } from './IVChart';
1
+ export { IChartProps, IVChartProps } from './IChartProps';
2
+ export { IVChart, IVChartConstructor, RenderMode } from './IVChart';
3
3
  export { IEvent } from './IEvent';
4
4
  export { IOptions } from './IOptions';
5
5
  export { IDomRef } from './IDomRef';
@@ -1,5 +1,6 @@
1
- import { IEvent, IOptions, IVChart, IChartProps, IDomRef } from '../../typings';
1
+ import type { IEvent, IOptions, IVChart, IChartProps, IDomRef, IVChartConstructor } from '../../typings';
2
2
  export interface IProps {
3
+ chartConstructor: IVChartConstructor;
3
4
  dpr: number;
4
5
  domref: IDomRef;
5
6
  mode?: string;
@@ -18,6 +19,7 @@ interface ITTCanvas {
18
19
  release: () => void;
19
20
  }
20
21
  export declare class TTCanvas implements ITTCanvas {
22
+ private chartConstructor;
21
23
  private dpr;
22
24
  private domref;
23
25
  private mode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/taro-vchart",
3
- "version": "0.10.0-alpha.2",
3
+ "version": "0.11.6-alpha.1",
4
4
  "description": "Taro VChart 图表组件",
5
5
  "sideEffects": false,
6
6
  "main": "lib/src/index.js",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
- "@visactor/vchart": "0.10.0-alpha.2"
34
+ "@visactor/vchart": "0.11.6-alpha.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@rushstack/eslint-patch": "~1.1.4",
@@ -71,6 +71,7 @@
71
71
  "rollup-plugin-import-css": "^3.0.2",
72
72
  "stylelint": "9.3.0",
73
73
  "tslib": "2.3.1",
74
+ "rimraf": "3.0.2",
74
75
  "@internal/eslint-config": "0.0.1",
75
76
  "@internal/ts-config": "0.0.1"
76
77
  },
@@ -79,7 +80,7 @@
79
80
  "registry": "https://registry.npmjs.org/"
80
81
  },
81
82
  "scripts": {
82
- "build": "rm -rf lib && rollup -c --bundleConfigAsCjs",
83
+ "build": "rimraf lib && rollup -c --bundleConfigAsCjs",
83
84
  "build:tt": "taro build --type tt",
84
85
  "build:lark": "taro build --type lark",
85
86
  "build:h5": "taro build --type h5",