@visactor/taro-vchart 1.10.0-alpha.4 → 1.10.0-alpha.5
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/lib/src/chart/index.d.ts +1 -0
- package/lib/src/index.d.ts +3 -13
- package/lib/src/index.js +52 -12
- package/lib/src/simple.d.ts +2 -0
- package/lib/src/typings/IChartProps.d.ts +18 -2
- package/lib/src/typings/IVChart.d.ts +2 -2
- package/lib/src/typings/index.d.ts +2 -2
- package/lib/src/utils/tt-canvas/index.d.ts +3 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@visactor/vchart/build/es5';
|
package/lib/src/index.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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, 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
|
-
|
|
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
|
|
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');
|
|
@@ -251,10 +257,15 @@ class GeneralChart extends React.Component {
|
|
|
251
257
|
`${this.props.canvasId}_tooltip_canvas`,
|
|
252
258
|
`${this.props.canvasId}_hidden_canvas`
|
|
253
259
|
];
|
|
254
|
-
|
|
260
|
+
const { chartConstructor } = this.props;
|
|
261
|
+
const { vglobal } = chartConstructor;
|
|
262
|
+
if (vglobal) {
|
|
263
|
+
yield vglobal.setEnv('wx', { domref, force: true, canvasIdLists, freeCanvasIdx: 2, component: undefined });
|
|
264
|
+
}
|
|
255
265
|
}
|
|
256
266
|
domref.id = this.props.canvasId;
|
|
257
267
|
this.ttCanvas = new TTCanvas({
|
|
268
|
+
chartConstructor: this.props.chartConstructor,
|
|
258
269
|
dpr: dpr,
|
|
259
270
|
domref,
|
|
260
271
|
spec: this.props.spec,
|
|
@@ -295,20 +306,17 @@ class GeneralChart extends React.Component {
|
|
|
295
306
|
}
|
|
296
307
|
}
|
|
297
308
|
|
|
298
|
-
function
|
|
309
|
+
function VChartSimple(_a) {
|
|
299
310
|
var { type } = _a, args = __rest(_a, ["type"]);
|
|
300
311
|
const env = (type !== null && type !== void 0 ? type : Taro.getEnv()).toLocaleLowerCase();
|
|
301
312
|
const strategies = {
|
|
302
313
|
lark: () => {
|
|
303
|
-
registerLarkEnv();
|
|
304
314
|
return React.createElement(GeneralChart, Object.assign({}, args, { mode: "miniApp" }));
|
|
305
315
|
},
|
|
306
316
|
tt: () => {
|
|
307
|
-
registerLarkEnv();
|
|
308
317
|
return React.createElement(GeneralChart, Object.assign({}, args, { mode: "miniApp" }));
|
|
309
318
|
},
|
|
310
319
|
weapp: () => {
|
|
311
|
-
registerWXEnv();
|
|
312
320
|
return React.createElement(GeneralChart, Object.assign({}, args, { mode: "wx" }));
|
|
313
321
|
},
|
|
314
322
|
web: () => {
|
|
@@ -325,4 +333,36 @@ function VChart(_a) {
|
|
|
325
333
|
return React.createElement(GeneralChart, Object.assign({}, args));
|
|
326
334
|
}
|
|
327
335
|
|
|
328
|
-
|
|
336
|
+
function VChart(_a) {
|
|
337
|
+
var { type } = _a, args = __rest(_a, ["type"]);
|
|
338
|
+
const env = (type !== null && type !== void 0 ? type : Taro.getEnv()).toLocaleLowerCase();
|
|
339
|
+
// @ts-ignore
|
|
340
|
+
const props = Object.assign({ chartConstructor: VChart$1 }, args);
|
|
341
|
+
const strategies = {
|
|
342
|
+
lark: () => {
|
|
343
|
+
registerLarkEnv();
|
|
344
|
+
return React.createElement(GeneralChart, Object.assign({}, props, { mode: "miniApp" }));
|
|
345
|
+
},
|
|
346
|
+
tt: () => {
|
|
347
|
+
registerLarkEnv();
|
|
348
|
+
return React.createElement(GeneralChart, Object.assign({}, props, { mode: "miniApp" }));
|
|
349
|
+
},
|
|
350
|
+
weapp: () => {
|
|
351
|
+
registerWXEnv();
|
|
352
|
+
return React.createElement(GeneralChart, Object.assign({}, props, { mode: "wx" }));
|
|
353
|
+
},
|
|
354
|
+
web: () => {
|
|
355
|
+
return React.createElement(WebChart, Object.assign({}, props));
|
|
356
|
+
},
|
|
357
|
+
h5: () => {
|
|
358
|
+
return React.createElement(WebChart, Object.assign({}, props, { mode: "mobile-browser" }));
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
if (env && strategies[env] !== undefined) {
|
|
362
|
+
return strategies[env].call();
|
|
363
|
+
}
|
|
364
|
+
console.warn(`暂不支持 ${env} 环境`);
|
|
365
|
+
return React.createElement(GeneralChart, Object.assign({}, props));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export { VChart, VChartSimple, VChart as default };
|
|
@@ -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
|
-
|
|
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": "1.10.0-alpha.
|
|
3
|
+
"version": "1.10.0-alpha.5",
|
|
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.10.0-alpha.
|
|
34
|
+
"@visactor/vchart": "1.10.0-alpha.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@rushstack/eslint-patch": "~1.1.4",
|