@cloudbase/weda-ui-mp 3.14.2 → 3.14.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/components/chart/bar/index.js +4 -20
- package/components/chart/bar/index.wxml +1 -1
- package/components/chart/ec-canvas/ec-canvas.js +35 -37
- package/components/chart/ec-canvas/ec-canvas.wxml +1 -1
- package/components/chart/line/index.js +4 -20
- package/components/chart/line/index.wxml +1 -1
- package/components/chart/pie/index.js +4 -20
- package/components/chart/pie/index.wxml +1 -1
- package/package.json +1 -1
|
@@ -220,10 +220,6 @@ Component({
|
|
|
220
220
|
},
|
|
221
221
|
data: {
|
|
222
222
|
ec: {},
|
|
223
|
-
canvas_id: {
|
|
224
|
-
type: String,
|
|
225
|
-
value: `canvas_line_${Date.now()}_${Math.random() * 100}`,
|
|
226
|
-
},
|
|
227
223
|
},
|
|
228
224
|
lifetimes: {
|
|
229
225
|
attached() {
|
|
@@ -269,22 +265,11 @@ Component({
|
|
|
269
265
|
return options ?? [];
|
|
270
266
|
} else {
|
|
271
267
|
if (this.properties.dataSourceType === 'variable') {
|
|
272
|
-
const result = transform(
|
|
273
|
-
'bar',
|
|
274
|
-
this.properties.datasourceVariable,
|
|
275
|
-
this.properties
|
|
276
|
-
);
|
|
268
|
+
const result = transform('bar', this.properties.datasourceVariable, this.properties);
|
|
277
269
|
return result ?? [];
|
|
278
270
|
} else if (this.properties.dataSourceType === 'custom-connector') {
|
|
279
|
-
const { connector, connectorMethod, connectorParams } =
|
|
280
|
-
|
|
281
|
-
if (
|
|
282
|
-
!(
|
|
283
|
-
connector?.datasource?.name &&
|
|
284
|
-
connectorMethod?.name &&
|
|
285
|
-
connectorParams
|
|
286
|
-
)
|
|
287
|
-
) {
|
|
271
|
+
const { connector, connectorMethod, connectorParams } = this.properties;
|
|
272
|
+
if (!(connector?.datasource?.name && connectorMethod?.name && connectorParams)) {
|
|
288
273
|
console.warn('Chart 参数不完整');
|
|
289
274
|
}
|
|
290
275
|
const res = await callDataSource({
|
|
@@ -299,6 +284,7 @@ Component({
|
|
|
299
284
|
},
|
|
300
285
|
initData() {
|
|
301
286
|
this.setData({
|
|
287
|
+
id: this.id,
|
|
302
288
|
ec: {
|
|
303
289
|
onInit: this.initChart.bind(this),
|
|
304
290
|
},
|
|
@@ -312,7 +298,6 @@ Component({
|
|
|
312
298
|
});
|
|
313
299
|
canvas.setChart(objEchart);
|
|
314
300
|
const options = await this.getData();
|
|
315
|
-
console.log('设置前参数bar', options);
|
|
316
301
|
objEchart.setOption(options, true);
|
|
317
302
|
this._chart = objEchart;
|
|
318
303
|
return objEchart;
|
|
@@ -324,7 +309,6 @@ Component({
|
|
|
324
309
|
const canvas = this.selectComponent(`#canvas_${this.properties.id}`);
|
|
325
310
|
canvas?.init();
|
|
326
311
|
const options = await this.getData();
|
|
327
|
-
console.log('设置前参数bar', options);
|
|
328
312
|
this._chart && this._chart.setOption(options, true);
|
|
329
313
|
},
|
|
330
314
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}"
|
|
1
|
+
<view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvasId="{{'canvas_'+id}}" ec="{{ ec }}" /> </view>
|
|
@@ -48,7 +48,7 @@ Component({
|
|
|
48
48
|
data: {
|
|
49
49
|
isUseNewCanvas: false,
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
domObserver: null,
|
|
52
52
|
ready: function () {
|
|
53
53
|
// Disable prograssive because drawImage doesn't support DOM as parameter
|
|
54
54
|
// See https://developers.weixin.qq.com/miniprogram/dev/api/canvas/CanvasContext.drawImage.html
|
|
@@ -67,14 +67,10 @@ Component({
|
|
|
67
67
|
if (!this.data.ec) {
|
|
68
68
|
console.warn(
|
|
69
69
|
'组件需绑定 ec 变量,例:<ec-canvas id="mychart-dom-bar" ' +
|
|
70
|
-
'canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>'
|
|
70
|
+
'canvas-id="mychart-bar" ec="{{ ec }}"></ec-canvas>',
|
|
71
71
|
);
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
if (!this.data.ec.lazyLoad) {
|
|
76
|
-
this.init();
|
|
77
|
-
}
|
|
78
74
|
},
|
|
79
75
|
|
|
80
76
|
methods: {
|
|
@@ -100,13 +96,11 @@ Component({
|
|
|
100
96
|
console.error(
|
|
101
97
|
'微信基础库版本过低,需大于等于 1.9.91。' +
|
|
102
98
|
'参见:https://github.com/ecomfe/echarts-for-weixin' +
|
|
103
|
-
'#%E5%BE%AE%E4%BF%A1%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82'
|
|
99
|
+
'#%E5%BE%AE%E4%BF%A1%E7%89%88%E6%9C%AC%E8%A6%81%E6%B1%82',
|
|
104
100
|
);
|
|
105
101
|
return;
|
|
106
102
|
} else {
|
|
107
|
-
console.warn(
|
|
108
|
-
'建议将微信基础库调整大于等于2.9.0版本。升级后绘图将有更好性能'
|
|
109
|
-
);
|
|
103
|
+
console.warn('建议将微信基础库调整大于等于2.9.0版本。升级后绘图将有更好性能');
|
|
110
104
|
this.initByOldWay(callback);
|
|
111
105
|
}
|
|
112
106
|
}
|
|
@@ -128,16 +122,8 @@ Component({
|
|
|
128
122
|
.boundingClientRect(async (res) => {
|
|
129
123
|
if (typeof callback === 'function') {
|
|
130
124
|
this.chart = callback(canvas, res.width, res.height, canvasDpr);
|
|
131
|
-
} else if (
|
|
132
|
-
this.data.ec
|
|
133
|
-
typeof this.data.ec.onInit === 'function'
|
|
134
|
-
) {
|
|
135
|
-
this.chart = await this.data.ec.onInit(
|
|
136
|
-
canvas,
|
|
137
|
-
res.width,
|
|
138
|
-
res.height,
|
|
139
|
-
canvasDpr
|
|
140
|
-
);
|
|
125
|
+
} else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
|
|
126
|
+
this.chart = await this.data.ec.onInit(canvas, res.width, res.height, canvasDpr);
|
|
141
127
|
} else {
|
|
142
128
|
this.triggerEvent('init', {
|
|
143
129
|
canvas: canvas,
|
|
@@ -154,7 +140,7 @@ Component({
|
|
|
154
140
|
// version >= 2.9.0:使用新的方式初始化
|
|
155
141
|
const query = wx.createSelectorQuery().in(this);
|
|
156
142
|
query
|
|
157
|
-
.select(
|
|
143
|
+
.select(`#${this.data.canvasId}`)
|
|
158
144
|
.fields({ node: true, size: true })
|
|
159
145
|
.exec(async (res) => {
|
|
160
146
|
const canvasNode = res[0].node;
|
|
@@ -166,28 +152,15 @@ Component({
|
|
|
166
152
|
|
|
167
153
|
const ctx = canvasNode.getContext('2d');
|
|
168
154
|
|
|
169
|
-
const canvas = new WxCanvas(
|
|
170
|
-
ctx,
|
|
171
|
-
this.data.canvasId,
|
|
172
|
-
true,
|
|
173
|
-
canvasNode
|
|
174
|
-
);
|
|
155
|
+
const canvas = new WxCanvas(ctx, this.data.canvasId, true, canvasNode);
|
|
175
156
|
echarts.setCanvasCreator(() => {
|
|
176
157
|
return canvas;
|
|
177
158
|
});
|
|
178
159
|
|
|
179
160
|
if (typeof callback === 'function') {
|
|
180
161
|
this.chart = callback(canvas, canvasWidth, canvasHeight, canvasDpr);
|
|
181
|
-
} else if (
|
|
182
|
-
this.data.ec
|
|
183
|
-
typeof this.data.ec.onInit === 'function'
|
|
184
|
-
) {
|
|
185
|
-
this.chart = await this.data.ec.onInit(
|
|
186
|
-
canvas,
|
|
187
|
-
canvasWidth,
|
|
188
|
-
canvasHeight,
|
|
189
|
-
canvasDpr
|
|
190
|
-
);
|
|
162
|
+
} else if (this.data.ec && typeof this.data.ec.onInit === 'function') {
|
|
163
|
+
this.chart = await this.data.ec.onInit(canvas, canvasWidth, canvasHeight, canvasDpr);
|
|
191
164
|
} else {
|
|
192
165
|
this.triggerEvent('init', {
|
|
193
166
|
canvas: canvas,
|
|
@@ -196,6 +169,8 @@ Component({
|
|
|
196
169
|
dpr: canvasDpr,
|
|
197
170
|
});
|
|
198
171
|
}
|
|
172
|
+
|
|
173
|
+
this.domObserver && this.domObserver.disconnect();
|
|
199
174
|
});
|
|
200
175
|
},
|
|
201
176
|
canvasToTempFilePath(opt) {
|
|
@@ -264,6 +239,29 @@ Component({
|
|
|
264
239
|
handler.processGesture(wrapTouch(e), 'end');
|
|
265
240
|
}
|
|
266
241
|
},
|
|
242
|
+
|
|
243
|
+
// 监听模块曝光
|
|
244
|
+
observeModuleExpose() {
|
|
245
|
+
this.domObserver && this.domObserver.disconnect();
|
|
246
|
+
this.domObserver = wx.createIntersectionObserver(this);
|
|
247
|
+
this.domObserver.relativeToViewport().observe(`#${this.data.canvasId}`, (res) => {
|
|
248
|
+
// 当页面出现图表时再绘制图表,避免出现白屏
|
|
249
|
+
if (res.intersectionRatio) {
|
|
250
|
+
this.init();
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
lifetimes: {
|
|
256
|
+
attached() {
|
|
257
|
+
// 在组件实例进入页面节点树时执行
|
|
258
|
+
if (!this.data.ec.lazyLoad) {
|
|
259
|
+
this.observeModuleExpose();
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
detached() {
|
|
263
|
+
this.domObserver && this.domObserver.disconnect();
|
|
264
|
+
},
|
|
267
265
|
},
|
|
268
266
|
});
|
|
269
267
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
<!-- 新的:接口对齐了H5 -->
|
|
2
|
-
<canvas wx:if="{{isUseNewCanvas}}" type="2d" class="ec-canvas" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
|
|
2
|
+
<canvas wx:if="{{isUseNewCanvas}}" type="2d" class="ec-canvas" id="{{canvasId}}" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
|
|
3
3
|
<!-- 旧的 -->
|
|
4
4
|
<canvas wx:else class="ec-canvas" canvas-id="{{ canvasId }}" bindinit="init" bindtouchstart="{{ ec.disableTouch ? '' : 'touchStart' }}" bindtouchmove="{{ ec.disableTouch ? '' : 'touchMove' }}" bindtouchend="{{ ec.disableTouch ? '' : 'touchEnd' }}"></canvas>
|
|
@@ -215,10 +215,6 @@ Component({
|
|
|
215
215
|
},
|
|
216
216
|
data: {
|
|
217
217
|
ec: {},
|
|
218
|
-
canvas_id: {
|
|
219
|
-
type: String,
|
|
220
|
-
value: `canvas_line_${Date.now()}_${Math.random() * 100}`,
|
|
221
|
-
},
|
|
222
218
|
},
|
|
223
219
|
lifetimes: {
|
|
224
220
|
attached() {
|
|
@@ -264,22 +260,11 @@ Component({
|
|
|
264
260
|
return options ?? [];
|
|
265
261
|
} else {
|
|
266
262
|
if (this.properties.dataSourceType === 'variable') {
|
|
267
|
-
const result = transform(
|
|
268
|
-
'line',
|
|
269
|
-
this.properties.datasourceVariable,
|
|
270
|
-
this.properties
|
|
271
|
-
);
|
|
263
|
+
const result = transform('line', this.properties.datasourceVariable, this.properties);
|
|
272
264
|
return result ?? [];
|
|
273
265
|
} else if (this.properties.dataSourceType === 'custom-connector') {
|
|
274
|
-
const { connector, connectorMethod, connectorParams } =
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
!(
|
|
278
|
-
connector?.datasource?.name &&
|
|
279
|
-
connectorMethod?.name &&
|
|
280
|
-
connectorParams
|
|
281
|
-
)
|
|
282
|
-
) {
|
|
266
|
+
const { connector, connectorMethod, connectorParams } = this.properties;
|
|
267
|
+
if (!(connector?.datasource?.name && connectorMethod?.name && connectorParams)) {
|
|
283
268
|
console.warn('Chart 参数不完整');
|
|
284
269
|
}
|
|
285
270
|
const res = await callDataSource({
|
|
@@ -294,6 +279,7 @@ Component({
|
|
|
294
279
|
},
|
|
295
280
|
initData() {
|
|
296
281
|
this.setData({
|
|
282
|
+
id: this.id,
|
|
297
283
|
ec: {
|
|
298
284
|
onInit: this.initChart.bind(this),
|
|
299
285
|
},
|
|
@@ -307,7 +293,6 @@ Component({
|
|
|
307
293
|
});
|
|
308
294
|
canvas.setChart(objEchart);
|
|
309
295
|
const options = await this.getData();
|
|
310
|
-
console.log('设置前参数line', options);
|
|
311
296
|
objEchart.setOption(options, true);
|
|
312
297
|
this._chart = objEchart;
|
|
313
298
|
return objEchart;
|
|
@@ -319,7 +304,6 @@ Component({
|
|
|
319
304
|
const canvas = this.selectComponent(`#canvas_${this.properties.id}`);
|
|
320
305
|
canvas?.init();
|
|
321
306
|
const options = await this.getData();
|
|
322
|
-
console.log('设置前参数line', options);
|
|
323
307
|
this._chart && this._chart.setOption(options, true);
|
|
324
308
|
},
|
|
325
309
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}"
|
|
1
|
+
<view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvasId="{{'canvas_'+id}}" ec="{{ ec }}" /> </view>
|
|
@@ -145,10 +145,6 @@ Component({
|
|
|
145
145
|
},
|
|
146
146
|
data: {
|
|
147
147
|
ec: {},
|
|
148
|
-
canvas_id: {
|
|
149
|
-
type: String,
|
|
150
|
-
value: `canvas_pie_${Date.now()}_${Math.random() * 100}`,
|
|
151
|
-
},
|
|
152
148
|
},
|
|
153
149
|
lifetimes: {
|
|
154
150
|
attached() {
|
|
@@ -173,7 +169,6 @@ Component({
|
|
|
173
169
|
const canvas = this.selectComponent(`#canvas_${this.properties.id}`);
|
|
174
170
|
canvas?.init();
|
|
175
171
|
const options = await this.getData();
|
|
176
|
-
console.log('设置前参数pie', options);
|
|
177
172
|
this._chart && this._chart.setOption(options, true);
|
|
178
173
|
},
|
|
179
174
|
},
|
|
@@ -204,22 +199,11 @@ Component({
|
|
|
204
199
|
return options ?? [];
|
|
205
200
|
} else {
|
|
206
201
|
if (this.properties.dataSourceType === 'variable') {
|
|
207
|
-
const result = transform(
|
|
208
|
-
'pie',
|
|
209
|
-
this.properties.datasourceVariable,
|
|
210
|
-
this.properties
|
|
211
|
-
);
|
|
202
|
+
const result = transform('pie', this.properties.datasourceVariable, this.properties);
|
|
212
203
|
return result ?? [];
|
|
213
204
|
} else if (this.properties.dataSourceType === 'custom-connector') {
|
|
214
|
-
const { connector, connectorMethod, connectorParams } =
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
!(
|
|
218
|
-
connector?.datasource?.name &&
|
|
219
|
-
connectorMethod?.name &&
|
|
220
|
-
connectorParams
|
|
221
|
-
)
|
|
222
|
-
) {
|
|
205
|
+
const { connector, connectorMethod, connectorParams } = this.properties;
|
|
206
|
+
if (!(connector?.datasource?.name && connectorMethod?.name && connectorParams)) {
|
|
223
207
|
console.warn('Chart 参数不完整');
|
|
224
208
|
}
|
|
225
209
|
const res = await callDataSource({
|
|
@@ -234,6 +218,7 @@ Component({
|
|
|
234
218
|
},
|
|
235
219
|
initData() {
|
|
236
220
|
this.setData({
|
|
221
|
+
id: this.id,
|
|
237
222
|
ec: {
|
|
238
223
|
onInit: this.initChart.bind(this),
|
|
239
224
|
},
|
|
@@ -248,7 +233,6 @@ Component({
|
|
|
248
233
|
canvas.setChart(objEchart);
|
|
249
234
|
const options = await this.getData();
|
|
250
235
|
// objEchart.clear();
|
|
251
|
-
console.log('设置前参数pie', options);
|
|
252
236
|
objEchart.setOption(options, true);
|
|
253
237
|
this._chart = objEchart;
|
|
254
238
|
return objEchart;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}"
|
|
1
|
+
<view wx:if="ec" class="{{className}} ec_container" style="{{style}}" id="{{id}}"> <ec-canvas id="{{'canvas_'+id}}" canvasId="{{'canvas_'+id}}" ec="{{ ec }}" /> </view>
|