@visactor/taro-vchart 1.5.3 → 1.5.4

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/README.md CHANGED
@@ -10,10 +10,11 @@ VChart 基于 [Taro](https://docs.taro.zone/docs/) 封装的图表组件。
10
10
 
11
11
  ## 支持环境
12
12
 
13
- 目前组件支持的环境有:**字节小程序**('tt'),**飞书小程序**('lark'),**浏览器**('h5', 'web')。
13
+ 目前组件支持的环境有:**微信小程序**('weapp'),**字节小程序**('tt'),**飞书小程序**('lark'),**浏览器**('h5', 'web')。
14
14
 
15
15
  以上环境通过 `type` 属性进行声明,`type` 属性值及对应环境如下:
16
16
 
17
+ - `weapp` 微信小程序。
17
18
  - `tt` 字节小程序。
18
19
  - `lark` 飞书小程序。
19
20
  - `h5` 浏览器环境, 与`web`等价。
@@ -319,6 +320,10 @@ $ rush run -p @visactor/vchart -s build:es5
319
320
 
320
321
  # 运行 lark 小程序
321
322
  $ rush run -p @visactor/taro-vchart -s dev:lark
323
+
324
+
325
+ # 运行微信小程序
326
+ $ rush run -p @visactor/taro-vchart -s dev:wx
322
327
  ```
323
328
 
324
- 然后使用飞书开发者工具导入 `packages/taro-vchart/dist/lark` 目录即可。
329
+ 然后使用飞书开发者工具导入 `packages/taro-vchart/dist/lark` 或者 `packages/taro-vchart/dist/weapp` 目录即可。
@@ -1,15 +1,20 @@
1
1
  import React from 'react';
2
2
  import { TTCanvas } from '../../utils';
3
- import { IChartProps, IDomRef } from '../../typings';
4
- export declare class GeneralChart extends React.Component<IChartProps> {
3
+ import { IChartProps, IDomRef, RenderMode } from '../../typings';
4
+ export interface GeneralChartProps extends IChartProps {
5
+ /**
6
+ * vchart 的环境参数
7
+ */
8
+ mode?: RenderMode;
9
+ }
10
+ export declare class GeneralChart extends React.Component<GeneralChartProps> {
5
11
  ttCanvas: TTCanvas;
6
- constructor(props: IChartProps);
7
12
  componentDidMount(): Promise<void>;
8
- componentDidUpdate(prevProps: IChartProps): void;
13
+ componentDidUpdate(prevProps: GeneralChartProps): void;
9
14
  componentWillUnmount(): void;
10
15
  init({ domref, dpr }: {
11
16
  domref: IDomRef;
12
17
  dpr: number;
13
- }): void;
18
+ }): Promise<void>;
14
19
  render(): React.JSX.Element;
15
20
  }
@@ -4,6 +4,7 @@ interface IVChartProps extends IChartProps {
4
4
  * 配置环境。如果没有声明,则会通过 `Taro.getEnv()` 自动获取。
5
5
  * - `tt` 字节小程序。
6
6
  * - `lark` 飞书小程序。
7
+ * - `weapp` 微信小程序
7
8
  * - `h5` 浏览器环境, 与`web`等价。
8
9
  * - `web` 浏览器环境, 与`h5`等价。
9
10
  */
package/lib/src/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import VChart$1 from '@visactor/vchart/build/es5';
2
+ import VChart$1, { vglobal } from '@visactor/vchart/build/es5';
3
3
  import { View, Canvas } from '@tarojs/components';
4
4
  import Taro from '@tarojs/taro';
5
5
 
@@ -174,9 +174,6 @@ const style_container = {
174
174
  };
175
175
 
176
176
  class GeneralChart extends React.Component {
177
- constructor(props) {
178
- super(props);
179
- }
180
177
  componentDidMount() {
181
178
  return __awaiter(this, void 0, void 0, function* () {
182
179
  if (!this.props.spec || !this.props.canvasId) {
@@ -242,34 +239,46 @@ class GeneralChart extends React.Component {
242
239
  this.ttCanvas && this.ttCanvas.release();
243
240
  }
244
241
  init({ domref, dpr = 2 }) {
245
- if (!domref) {
246
- console.error(`未找到 #${this.props.canvasId} 组件`);
247
- return;
248
- }
249
- domref.id = this.props.canvasId;
250
- this.ttCanvas = new TTCanvas({
251
- dpr: dpr,
252
- domref,
253
- spec: this.props.spec,
254
- events: this.props.events,
255
- options: this.props.options,
256
- onChartInit: (chart) => {
257
- var _a;
258
- ((_a = this.props) === null || _a === void 0 ? void 0 : _a.onChartInit) && this.props.onChartInit(chart);
259
- },
260
- onChartReady: (chart) => {
261
- var _a;
262
- ((_a = this.props) === null || _a === void 0 ? void 0 : _a.onChartReady) && this.props.onChartReady(chart);
263
- },
264
- onChartUpdate: (chart) => {
265
- var _a;
266
- ((_a = this.props) === null || _a === void 0 ? void 0 : _a.onChartUpdate) && this.props.onChartUpdate(chart);
242
+ return __awaiter(this, void 0, void 0, function* () {
243
+ if (!domref) {
244
+ console.error(`未找到 #${this.props.canvasId} 组件`);
245
+ return;
246
+ }
247
+ if (this.props.mode === 'wx') {
248
+ // 微信小程序环境特殊处理
249
+ const canvasIdLists = [
250
+ `${this.props.canvasId}_draw_canvas`,
251
+ `${this.props.canvasId}_tooltip_canvas`,
252
+ `${this.props.canvasId}_hidden_canvas`
253
+ ];
254
+ yield vglobal.setEnv('wx', { domref, force: true, canvasIdLists, freeCanvasIdx: 2, component: undefined });
267
255
  }
256
+ domref.id = this.props.canvasId;
257
+ this.ttCanvas = new TTCanvas({
258
+ dpr: dpr,
259
+ domref,
260
+ spec: this.props.spec,
261
+ events: this.props.events,
262
+ options: this.props.options,
263
+ mode: this.props.mode,
264
+ onChartInit: (chart) => {
265
+ var _a;
266
+ ((_a = this.props) === null || _a === void 0 ? void 0 : _a.onChartInit) && this.props.onChartInit(chart);
267
+ },
268
+ onChartReady: (chart) => {
269
+ var _a;
270
+ ((_a = this.props) === null || _a === void 0 ? void 0 : _a.onChartReady) && this.props.onChartReady(chart);
271
+ },
272
+ onChartUpdate: (chart) => {
273
+ var _a;
274
+ ((_a = this.props) === null || _a === void 0 ? void 0 : _a.onChartUpdate) && this.props.onChartUpdate(chart);
275
+ }
276
+ });
268
277
  });
269
278
  }
270
279
  render() {
271
280
  const handleEvent = (event) => {
272
- if (this.ttCanvas.chartInstance) {
281
+ if (this.ttCanvas && this.ttCanvas.chartInstance) {
273
282
  const chartInstance = this.ttCanvas.chartInstance;
274
283
  Object.defineProperty(event, 'target', {
275
284
  writable: false,
@@ -280,21 +289,24 @@ class GeneralChart extends React.Component {
280
289
  };
281
290
  const { canvasId, style = {} } = this.props;
282
291
  return (React.createElement(View, { key: canvasId, style: Object.assign(Object.assign(Object.assign({}, style_container), style), { padding: 0 }) },
283
- React.createElement(Canvas, { style: Object.assign({}, style_cs_tooltip_canvas), id: `${canvasId}_tooltip_canvas`, canvasId: `${canvasId}_tooltip_canvas` }),
284
- React.createElement(Canvas, { onTouchStart: handleEvent, onTouchMove: handleEvent, onTouchEnd: handleEvent, style: style_cs_canvas, id: `${canvasId}_draw_canvas`, canvasId: `${canvasId}_draw_canvas` }),
285
- React.createElement(Canvas, { style: Object.assign(Object.assign({}, style_cs_canvas), style_cs_canvas_hidden), id: `${canvasId}_hidden_canvas`, canvasId: `${canvasId}_hidden_canvas` })));
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` })));
286
295
  }
287
296
  }
288
297
 
289
298
  function VChart(_a) {
290
299
  var { type } = _a, args = __rest(_a, ["type"]);
291
- const env = type ? type.toLocaleLowerCase() : Taro.getEnv();
300
+ const env = (type !== null && type !== void 0 ? type : Taro.getEnv()).toLocaleLowerCase();
292
301
  const strategies = {
293
302
  lark: () => {
294
- return React.createElement(GeneralChart, Object.assign({}, args));
303
+ return React.createElement(GeneralChart, Object.assign({}, args, { mode: "miniApp" }));
295
304
  },
296
305
  tt: () => {
297
- return React.createElement(GeneralChart, Object.assign({}, args));
306
+ return React.createElement(GeneralChart, Object.assign({}, args, { mode: "miniApp" }));
307
+ },
308
+ weapp: () => {
309
+ return React.createElement(GeneralChart, Object.assign({}, args, { mode: "wx" }));
298
310
  },
299
311
  web: () => {
300
312
  return React.createElement(WebChart, Object.assign({}, args));
@@ -1,2 +1,2 @@
1
- import { IVChart, ISpec } from '@visactor/vchart';
2
- export { IVChart, ISpec };
1
+ import { IVChart, ISpec, RenderMode } from '@visactor/vchart';
2
+ export { IVChart, ISpec, RenderMode };
@@ -1,8 +1,10 @@
1
1
  type tt = 'tt';
2
2
  type lark = 'lark';
3
3
  type web = 'web' | 'h5';
4
+ type weapp = 'weapp';
4
5
  type TT = 'TT';
5
6
  type LARK = 'LARK';
6
7
  type WEB = 'WEB' | 'H5';
7
- export type VChartEnvType = tt | lark | web | TT | LARK | WEB;
8
+ type WEAPP = 'WEAPP';
9
+ export type VChartEnvType = tt | lark | weapp | web | TT | LARK | WEB | WEAPP;
8
10
  export {};
@@ -1,5 +1,5 @@
1
1
  export { IChartProps } from './IChartProps';
2
- export { IVChart } from './IVChart';
2
+ export { IVChart, RenderMode } from './IVChart';
3
3
  export { IEvent } from './IEvent';
4
4
  export { IOptions } from './IOptions';
5
5
  export { IDomRef } from './IDomRef';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visactor/taro-vchart",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
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": "1.5.3"
34
+ "@visactor/vchart": "1.5.4"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@rushstack/eslint-patch": "~1.1.4",
@@ -83,8 +83,10 @@
83
83
  "build:tt": "taro build --type tt",
84
84
  "build:lark": "taro build --type lark",
85
85
  "build:h5": "taro build --type h5",
86
+ "build:wx": "taro build --type weapp",
86
87
  "dev:tt": "npm run build:tt -- --watch",
87
88
  "dev:lark": "npm run build:lark -- --watch",
88
- "dev:h5": "npm run build:h5 -- --watch"
89
+ "dev:h5": "npm run build:h5 -- --watch",
90
+ "dev:wx": "npm run build:wx -- --watch"
89
91
  }
90
92
  }