|
|
@@ -1,4 +1,3 @@
|
|
|
-// @ts-nocheck - 为保持与原始代码逻辑完全一致,跳过类型检查
|
|
|
/**
|
|
|
* uCharts 主类
|
|
|
*
|
|
|
@@ -7,10 +6,10 @@
|
|
|
*/
|
|
|
|
|
|
import { uChartsEvent } from './u-charts-event';
|
|
|
-import { config, assign, util } from '../config';
|
|
|
-import { getH5Offset, getTouches as getTouchesUtil } from '../utils/misc';
|
|
|
+import { config as defaultConfig, assign, util, UChartsConfig } from '../config';
|
|
|
+import { getH5Offset, getTouches as getTouchesUtil, DOMEvent } from '../utils/misc';
|
|
|
import { measureText } from '../utils/text';
|
|
|
-import { calValidDistance } from '../utils/coordinate';
|
|
|
+import { calValidDistance, UChartInstance as CoordinateUChartInstance } from '../utils/coordinate';
|
|
|
import * as helperFunctions from '../helper-functions';
|
|
|
import * as dataProcessing from '../data-processing';
|
|
|
import * as chartsData from '../charts-data';
|
|
|
@@ -361,14 +360,17 @@ export class uCharts extends uChartsEvent {
|
|
|
constructor(opts: ChartsConfig) {
|
|
|
super();
|
|
|
|
|
|
- opts.pix = opts.pixelRatio ? opts.pixelRatio : 1;
|
|
|
+ // 确保必需的属性存在
|
|
|
+ if (!opts.height) opts.height = 300;
|
|
|
+ if (!opts.width) opts.width = 300;
|
|
|
+ if (!opts.pix) opts.pix = opts.pixelRatio ? opts.pixelRatio : 1;
|
|
|
opts.fontSize = opts.fontSize ? opts.fontSize : 13;
|
|
|
- opts.fontColor = opts.fontColor ? opts.fontColor : config.fontColor;
|
|
|
+ opts.fontColor = opts.fontColor ? opts.fontColor : defaultConfig.fontColor;
|
|
|
if (opts.background == "" || opts.background == "none") {
|
|
|
opts.background = "#FFFFFF"
|
|
|
}
|
|
|
- opts.title = assign({}, opts.title);
|
|
|
- opts.subtitle = assign({}, opts.subtitle);
|
|
|
+ opts.title = assign({}, opts.title || {});
|
|
|
+ opts.subtitle = assign({}, opts.subtitle || {});
|
|
|
opts.duration = opts.duration ? opts.duration : 1000;
|
|
|
opts.yAxis = assign({}, {
|
|
|
data: [],
|
|
|
@@ -382,7 +384,7 @@ export class uCharts extends uChartsEvent {
|
|
|
gridColor: '#cccccc',
|
|
|
padding: 10,
|
|
|
fontColor: '#666666'
|
|
|
- }, opts.yAxis);
|
|
|
+ }, opts.yAxis || {});
|
|
|
opts.xAxis = assign({}, {
|
|
|
rotateLabel: false,
|
|
|
rotateAngle: 45,
|
|
|
@@ -404,7 +406,7 @@ export class uCharts extends uChartsEvent {
|
|
|
titleOffsetY: 0,
|
|
|
titleOffsetX: 0,
|
|
|
titleFontColor: '#666666'
|
|
|
- }, opts.xAxis);
|
|
|
+ }, opts.xAxis || {});
|
|
|
opts.xAxis.scrollPosition = opts.xAxis.scrollAlign;
|
|
|
opts.legend = assign({}, {
|
|
|
show: true,
|
|
|
@@ -421,27 +423,31 @@ export class uCharts extends uChartsEvent {
|
|
|
fontColor: opts.fontColor,
|
|
|
formatter: {},
|
|
|
hiddenColor: '#CECECE'
|
|
|
- }, opts.legend);
|
|
|
- opts.extra = assign({
|
|
|
+ }, opts.legend || {});
|
|
|
+ opts.extra = {
|
|
|
tooltip: {
|
|
|
legendShape: 'auto'
|
|
|
- }
|
|
|
- }, opts.extra);
|
|
|
+ },
|
|
|
+ ...(opts.extra || {})
|
|
|
+ } as ExtraConfig;
|
|
|
opts.rotate = opts.rotate ? true : false;
|
|
|
opts.animation = opts.animation ? true : false;
|
|
|
opts.rotate = opts.rotate ? true : false;
|
|
|
opts.canvas2d = opts.canvas2d ? true : false;
|
|
|
|
|
|
- let config = assign({}, config);
|
|
|
+ let config: UChartsConfig = { ...defaultConfig };
|
|
|
config.color = opts.color ? opts.color : config.color;
|
|
|
if (opts.type == 'pie') {
|
|
|
- config.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.pie.labelWidth * opts.pix || config.pieChartLinePadding * opts.pix;
|
|
|
+ const pieLabelWidth = opts.extra?.pie?.labelWidth ?? 0;
|
|
|
+ config.pieChartLinePadding = opts.dataLabel === false ? 0 : pieLabelWidth * opts.pix || config.pieChartLinePadding * opts.pix;
|
|
|
}
|
|
|
if (opts.type == 'ring') {
|
|
|
- config.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.ring.labelWidth * opts.pix || config.pieChartLinePadding * opts.pix;
|
|
|
+ const ringLabelWidth = opts.extra?.ring?.labelWidth ?? 0;
|
|
|
+ config.pieChartLinePadding = opts.dataLabel === false ? 0 : ringLabelWidth * opts.pix || config.pieChartLinePadding * opts.pix;
|
|
|
}
|
|
|
if (opts.type == 'rose') {
|
|
|
- config.pieChartLinePadding = opts.dataLabel === false ? 0 : opts.extra.rose.labelWidth * opts.pix || config.pieChartLinePadding * opts.pix;
|
|
|
+ const roseLabelWidth = opts.extra?.rose?.labelWidth ?? 0;
|
|
|
+ config.pieChartLinePadding = opts.dataLabel === false ? 0 : roseLabelWidth * opts.pix || config.pieChartLinePadding * opts.pix;
|
|
|
}
|
|
|
config.pieChartTextPadding = opts.dataLabel === false ? 0 : config.pieChartTextPadding * opts.pix;
|
|
|
|
|
|
@@ -508,7 +514,7 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
this.opts = opts;
|
|
|
this.config = config;
|
|
|
- drawCharts.call(this, opts.type, opts, config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, config, this.context);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -533,11 +539,11 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
break;
|
|
|
case 'right':
|
|
|
- let _calYAxisData = calYAxisData(this.opts.series, this.opts, this.config, this.context);
|
|
|
+ let _calYAxisData = calYAxisData(this.opts.series || [], this.opts as any, this.config, this.context);
|
|
|
let yAxisWidth = _calYAxisData.yAxisWidth;
|
|
|
this.config.yAxisWidth = yAxisWidth;
|
|
|
let offsetLeft = 0;
|
|
|
- let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config);
|
|
|
+ let _getXAxisPoints0 = getXAxisPoints(this.opts.categories || [], this.opts as any, this.config);
|
|
|
let xAxisPoints = _getXAxisPoints0.xAxisPoints;
|
|
|
let startX = _getXAxisPoints0.startX;
|
|
|
let endX = _getXAxisPoints0.endX;
|
|
|
@@ -554,28 +560,33 @@ export class uCharts extends uChartsEvent {
|
|
|
this.opts._scrollDistance_ = offsetLeft;
|
|
|
break;
|
|
|
}
|
|
|
- drawCharts.call(this, this.opts.type, this.opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, this.opts.type || '', this.opts as any, this.config, this.context);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 缩放图表
|
|
|
* @param val - 缩放配置
|
|
|
*/
|
|
|
- zoom(val: any = this.opts.xAxis.itemCount): void {
|
|
|
+ zoom(val: any = this.opts.xAxis?.itemCount): void {
|
|
|
if (this.opts.enableScroll !== true) {
|
|
|
console.log('[uCharts] 请启用滚动条后使用')
|
|
|
return;
|
|
|
}
|
|
|
// 当前屏幕中间点
|
|
|
- let centerPoint = Math.round(Math.abs(this.scrollOption.currentOffset) / this.opts.chartData.eachSpacing) + Math.round(this.opts.xAxis.itemCount / 2);
|
|
|
+ if (!this.opts.chartData || !this.opts.chartData.eachSpacing) {
|
|
|
+ console.log('[uCharts] 图表数据未初始化')
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let centerPoint = Math.round(Math.abs(this.scrollOption.currentOffset) / this.opts.chartData.eachSpacing) + Math.round((this.opts.xAxis?.itemCount || 0) / 2);
|
|
|
this.opts.animation = false;
|
|
|
+ if (!this.opts.xAxis) return;
|
|
|
this.opts.xAxis.itemCount = val.itemCount;
|
|
|
// 重新计算x轴偏移距离
|
|
|
- let _calYAxisData = calYAxisData(this.opts.series, this.opts, this.config, this.context);
|
|
|
+ let _calYAxisData = calYAxisData(this.opts.series || [], this.opts as any, this.config, this.context);
|
|
|
let yAxisWidth = _calYAxisData.yAxisWidth;
|
|
|
this.config.yAxisWidth = yAxisWidth;
|
|
|
let offsetLeft = 0;
|
|
|
- let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config);
|
|
|
+ let _getXAxisPoints0 = getXAxisPoints(this.opts.categories || [], this.opts as any, this.config);
|
|
|
let xAxisPoints = _getXAxisPoints0.xAxisPoints;
|
|
|
let startX = _getXAxisPoints0.startX;
|
|
|
let endX = _getXAxisPoints0.endX;
|
|
|
@@ -596,9 +607,11 @@ export class uCharts extends uChartsEvent {
|
|
|
distance: 0,
|
|
|
lastMoveTime: 0
|
|
|
};
|
|
|
- calValidDistance(this, offsetLeft, this.opts.chartData, this.config, this.opts);
|
|
|
+ const self = this as unknown as CoordinateUChartInstance;
|
|
|
+ self.scrollOption = { position: this.scrollOption.currentOffset };
|
|
|
+ calValidDistance(self, offsetLeft, this.opts.chartData || { eachSpacing: 0 }, this.config as any, this.opts as any);
|
|
|
this.opts._scrollDistance_ = offsetLeft;
|
|
|
- drawCharts.call(this, this.opts.type, this.opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, this.opts.type || '', this.opts as any, this.config, this.context);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -611,22 +624,23 @@ export class uCharts extends uChartsEvent {
|
|
|
return;
|
|
|
}
|
|
|
const tcs = e.changedTouches;
|
|
|
- if (tcs.length < 2) {
|
|
|
+ if (!tcs || tcs.length < 2) {
|
|
|
return;
|
|
|
}
|
|
|
for (let i = 0; i < tcs.length; i++) {
|
|
|
tcs[i].x = tcs[i].x ? tcs[i].x : tcs[i].clientX;
|
|
|
tcs[i].y = tcs[i].y ? tcs[i].y : tcs[i].clientY;
|
|
|
}
|
|
|
- const ntcs = [getTouches(tcs[0], this.opts, e), getTouches(tcs[1], this.opts, e)];
|
|
|
- const xlength = Math.abs(ntcs[0].x - ntcs[1].x);
|
|
|
+ const ntcs = [getTouches(tcs[0], this.opts as any, e as any), getTouches(tcs[1], this.opts as any, e as any)];
|
|
|
+ const xlength = Math.abs((ntcs[0].x || 0) - (ntcs[1].x || 0));
|
|
|
// 记录初始的两指之间的数据
|
|
|
if (!this.scrollOption.moveCount) {
|
|
|
- let cts0 = { changedTouches: [{ x: tcs[0].x, y: this.opts.area[0] / this.opts.pix + 2 }] };
|
|
|
- let cts1 = { changedTouches: [{ x: tcs[1].x, y: this.opts.area[0] / this.opts.pix + 2 }] };
|
|
|
+ if (!this.opts.area || !this.opts.height) return;
|
|
|
+ let cts0 = { changedTouches: [{ x: tcs[0].x || 0, y: this.opts.area[0] / (this.opts.pix || 1) + 2 }] };
|
|
|
+ let cts1 = { changedTouches: [{ x: tcs[1].x || 0, y: this.opts.area[0] / (this.opts.pix || 1) + 2 }] };
|
|
|
if (this.opts.rotate) {
|
|
|
- cts0 = { changedTouches: [{ x: this.opts.height / this.opts.pix - this.opts.area[0] / this.opts.pix - 2, y: tcs[0].y }] };
|
|
|
- cts1 = { changedTouches: [{ x: this.opts.height / this.opts.pix - this.opts.area[0] / this.opts.pix - 2, y: tcs[1].y }] };
|
|
|
+ cts0 = { changedTouches: [{ x: this.opts.height / (this.opts.pix || 1) - this.opts.area[0] / (this.opts.pix || 1) - 2, y: tcs[0].y || 0 }] };
|
|
|
+ cts1 = { changedTouches: [{ x: this.opts.height / (this.opts.pix || 1) - this.opts.area[0] / (this.opts.pix || 1) - 2, y: tcs[1].y || 0 }] };
|
|
|
}
|
|
|
const moveCurrent1 = this.getCurrentDataIndex(cts0).index;
|
|
|
const moveCurrent2 = this.getCurrentDataIndex(cts1).index;
|
|
|
@@ -637,23 +651,25 @@ export class uCharts extends uChartsEvent {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- let currentEachSpacing = xlength / this.scrollOption.moveCount;
|
|
|
+ let currentEachSpacing = xlength / (this.scrollOption.moveCount || 1);
|
|
|
+ if (!this.opts.area || !this.opts.width || !this.opts.xAxis) return;
|
|
|
let itemCount = (this.opts.width - this.opts.area[1] - this.opts.area[3]) / currentEachSpacing;
|
|
|
itemCount = itemCount <= 2 ? 2 : itemCount;
|
|
|
+ if (!this.opts.categories) return;
|
|
|
itemCount = itemCount >= this.opts.categories.length ? this.opts.categories.length : itemCount;
|
|
|
this.opts.animation = false;
|
|
|
this.opts.xAxis.itemCount = itemCount;
|
|
|
// 重新计算滚动条偏移距离
|
|
|
let offsetLeft = 0;
|
|
|
- let _getXAxisPoints0 = getXAxisPoints(this.opts.categories, this.opts, this.config);
|
|
|
+ let _getXAxisPoints0 = getXAxisPoints(this.opts.categories || [], this.opts as any, this.config);
|
|
|
let xAxisPoints = _getXAxisPoints0.xAxisPoints;
|
|
|
let startX = _getXAxisPoints0.startX;
|
|
|
let endX = _getXAxisPoints0.endX;
|
|
|
let eachSpacing = _getXAxisPoints0.eachSpacing;
|
|
|
- let currentLeft = eachSpacing * this.scrollOption.moveCurrent1;
|
|
|
+ let currentLeft = eachSpacing * (this.scrollOption.moveCurrent1 || 0);
|
|
|
let screenWidth = endX - startX;
|
|
|
let MaxLeft = screenWidth - eachSpacing * (xAxisPoints.length - 1);
|
|
|
- offsetLeft = -currentLeft + Math.min(ntcs[0].x, ntcs[1].x) - this.opts.area[3] - eachSpacing;
|
|
|
+ offsetLeft = -currentLeft + Math.min(ntcs[0].x || 0, ntcs[1].x || 0) - (this.opts.area[3] || 0) - eachSpacing;
|
|
|
if (offsetLeft > 0) {
|
|
|
offsetLeft = 0;
|
|
|
}
|
|
|
@@ -663,9 +679,11 @@ export class uCharts extends uChartsEvent {
|
|
|
this.scrollOption.currentOffset = offsetLeft;
|
|
|
this.scrollOption.startTouchX = 0;
|
|
|
this.scrollOption.distance = 0;
|
|
|
- calValidDistance(this, offsetLeft, this.opts.chartData, this.config, this.opts);
|
|
|
+ const self = this as unknown as CoordinateUChartInstance;
|
|
|
+ self.scrollOption = { position: this.scrollOption.currentOffset };
|
|
|
+ calValidDistance(self, offsetLeft, this.opts.chartData || { eachSpacing: 0 }, this.config as any, this.opts as any);
|
|
|
this.opts._scrollDistance_ = offsetLeft;
|
|
|
- drawCharts.call(this, this.opts.type, this.opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, this.opts.type || '', this.opts as any, this.config, this.context);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -684,51 +702,52 @@ export class uCharts extends uChartsEvent {
|
|
|
let touches = null;
|
|
|
if (e.changedTouches) {
|
|
|
touches = e.changedTouches[0];
|
|
|
- } else {
|
|
|
+ } else if (e.mp && e.mp.changedTouches) {
|
|
|
touches = e.mp.changedTouches[0];
|
|
|
}
|
|
|
if (touches) {
|
|
|
- let _touches$ = getTouches(touches, this.opts, e);
|
|
|
+ let _touches$ = getTouches(touches, this.opts as any, e as any);
|
|
|
+ if (!this.opts.chartData) return { index: -1 };
|
|
|
if (this.opts.type === 'pie' || this.opts.type === 'ring') {
|
|
|
return findPieChartCurrentIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts.chartData.pieData, this.opts);
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts.chartData.pieData || [], this.opts as any);
|
|
|
} else if (this.opts.type === 'rose') {
|
|
|
return findRoseChartCurrentIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts.chartData.pieData, this.opts);
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts.chartData.pieData || [], this.opts as any);
|
|
|
} else if (this.opts.type === 'radar') {
|
|
|
return findRadarChartCurrentIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts.chartData.radarData, this.opts.categories.length);
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts.chartData.radarData || [], this.opts.categories?.length || 0);
|
|
|
} else if (this.opts.type === 'funnel') {
|
|
|
return findFunnelChartCurrentIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts.chartData.funnelData);
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts.chartData.funnelData || []);
|
|
|
} else if (this.opts.type === 'map') {
|
|
|
return findMapChartCurrentIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts);
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts as any);
|
|
|
} else if (this.opts.type === 'word') {
|
|
|
return findWordChartCurrentIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts.chartData.wordCloudData);
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts.chartData.wordCloudData || []);
|
|
|
} else if (this.opts.type === 'bar') {
|
|
|
return findBarChartCurrentIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts.chartData.calPoints, this.opts, this.config, Math.abs(this.scrollOption.currentOffset));
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts.chartData.calPoints || [], this.opts as any, this.config, Math.abs(this.scrollOption.currentOffset));
|
|
|
} else {
|
|
|
return findCurrentIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts.chartData.calPoints, this.opts, this.config, Math.abs(this.scrollOption.currentOffset));
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts.chartData.calPoints || [], this.opts as any, this.config, Math.abs(this.scrollOption.currentOffset));
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
@@ -743,15 +762,15 @@ export class uCharts extends uChartsEvent {
|
|
|
let touches = null;
|
|
|
if (e.changedTouches) {
|
|
|
touches = e.changedTouches[0];
|
|
|
- } else {
|
|
|
+ } else if (e.mp && e.mp.changedTouches) {
|
|
|
touches = e.mp.changedTouches[0];
|
|
|
}
|
|
|
if (touches) {
|
|
|
- let _touches$ = getTouches(touches, this.opts, e);
|
|
|
+ let _touches$ = getTouches(touches, this.opts as any, e as any);
|
|
|
return findLegendIndex({
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
- }, this.opts.chartData.legendData);
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
+ }, this.opts.chartData?.legendData || [], this.opts as any);
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
@@ -765,21 +784,23 @@ export class uCharts extends uChartsEvent {
|
|
|
let touches = null;
|
|
|
if (e.changedTouches) {
|
|
|
touches = e.changedTouches[0];
|
|
|
- } else {
|
|
|
+ } else if (e.mp && e.mp.changedTouches) {
|
|
|
touches = e.mp.changedTouches[0];
|
|
|
}
|
|
|
if (touches) {
|
|
|
- let _touches$ = getTouches(touches, this.opts, e);
|
|
|
+ let _touches$ = getTouches(touches, this.opts as any, e as any);
|
|
|
let index = this.getLegendDataIndex(e);
|
|
|
if (index >= 0) {
|
|
|
+ if (!this.opts.series) return;
|
|
|
if (this.opts.type == 'candle') {
|
|
|
+ if (!this.opts.seriesMA) return;
|
|
|
this.opts.seriesMA[index].show = !this.opts.seriesMA[index].show;
|
|
|
} else {
|
|
|
this.opts.series[index].show = !this.opts.series[index].show;
|
|
|
}
|
|
|
this.opts.animation = option.animation ? true : false;
|
|
|
this.opts._scrollDistance_ = this.scrollOption.currentOffset;
|
|
|
- drawCharts.call(this, this.opts.type, this.opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, this.opts.type || '', this.opts as any, this.config, this.context);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -793,29 +814,31 @@ export class uCharts extends uChartsEvent {
|
|
|
let touches = null;
|
|
|
if (e.changedTouches) {
|
|
|
touches = e.changedTouches[0];
|
|
|
- } else {
|
|
|
+ } else if (e.mp && e.mp.changedTouches) {
|
|
|
touches = e.mp.changedTouches[0];
|
|
|
}
|
|
|
if (!touches) {
|
|
|
console.log("[uCharts] 未获取到event坐标信息");
|
|
|
+ return;
|
|
|
}
|
|
|
- let _touches$ = getTouches(touches, this.opts, e);
|
|
|
+ let _touches$ = getTouches(touches, this.opts as any, e as any);
|
|
|
let currentOffset = this.scrollOption.currentOffset;
|
|
|
- let opts = assign({}, this.opts, {
|
|
|
+ let opts = {
|
|
|
+ ...this.opts,
|
|
|
_scrollDistance_: currentOffset,
|
|
|
animation: false
|
|
|
- });
|
|
|
+ } as ChartsConfig;
|
|
|
if (this.opts.type === 'line' || this.opts.type === 'area' || this.opts.type === 'column' || this.opts.type === 'scatter' || this.opts.type === 'bubble') {
|
|
|
let current = this.getCurrentDataIndex(e);
|
|
|
let index = option.index == undefined ? current.index : option.index;
|
|
|
if (index > -1 || index.length > 0) {
|
|
|
- let seriesData = getSeriesDataItem(this.opts.series, index, current.group);
|
|
|
+ let seriesData = getSeriesDataItem(this.opts.series || [], index, current.group);
|
|
|
if (seriesData.length !== 0) {
|
|
|
- let _getToolTipData = getToolTipData(seriesData, this.opts, index, current.group, this.opts.categories, option);
|
|
|
+ let _getToolTipData = getToolTipData(seriesData as any, this.opts as any, index, current.group, this.opts.categories || [], option);
|
|
|
let textList = _getToolTipData.textList;
|
|
|
let offset = _getToolTipData.offset;
|
|
|
- offset.y = _touches$.y;
|
|
|
- opts.tooltip = {
|
|
|
+ offset.y = _touches$.y || 0;
|
|
|
+ (opts as any).tooltip = {
|
|
|
textList: option.textList !== undefined ? option.textList : textList,
|
|
|
offset: option.offset !== undefined ? option.offset : offset,
|
|
|
option: option,
|
|
|
@@ -824,21 +847,21 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
if (this.opts.type === 'mount') {
|
|
|
let index = option.index == undefined ? this.getCurrentDataIndex(e).index : option.index;
|
|
|
if (index > -1) {
|
|
|
- let opts = assign({}, this.opts, { animation: false });
|
|
|
- let seriesData = assign({}, opts._series_[index]);
|
|
|
+ let opts = { ...this.opts, animation: false } as ChartsConfig;
|
|
|
+ let seriesData = { ...opts._series_?.[index] || {} };
|
|
|
let textList = [{
|
|
|
- text: option.formatter ? option.formatter(seriesData, undefined, index, opts) : seriesData.name + ': ' + seriesData.data,
|
|
|
- color: seriesData.color,
|
|
|
- legendShape: this.opts.extra.tooltip.legendShape == 'auto' ? seriesData.legendShape : this.opts.extra.tooltip.legendShape
|
|
|
+ text: option.formatter ? option.formatter(seriesData, undefined, index, opts) : (seriesData.name || '') + ': ' + (seriesData.data || ''),
|
|
|
+ color: seriesData.color || '',
|
|
|
+ legendShape: this.opts.extra?.tooltip?.legendShape == 'auto' ? seriesData.legendShape : this.opts.extra?.tooltip?.legendShape
|
|
|
}];
|
|
|
let offset = {
|
|
|
- x: opts.chartData.calPoints[index].x,
|
|
|
- y: _touches$.y
|
|
|
+ x: opts.chartData?.calPoints?.[index]?.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
};
|
|
|
opts.tooltip = {
|
|
|
textList: option.textList ? option.textList : textList,
|
|
|
@@ -848,19 +871,19 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
if (this.opts.type === 'bar') {
|
|
|
let current = this.getCurrentDataIndex(e);
|
|
|
let index = option.index == undefined ? current.index : option.index;
|
|
|
if (index > -1 || index.length > 0) {
|
|
|
- let seriesData = getSeriesDataItem(this.opts.series, index, current.group);
|
|
|
+ let seriesData = getSeriesDataItem(this.opts.series || [], index, current.group);
|
|
|
if (seriesData.length !== 0) {
|
|
|
- let _getToolTipData = getToolTipData(seriesData, this.opts, index, current.group, this.opts.categories, option);
|
|
|
+ let _getToolTipData = getToolTipData(seriesData as any, this.opts as any, index, current.group, this.opts.categories || [], option);
|
|
|
let textList = _getToolTipData.textList;
|
|
|
let offset = _getToolTipData.offset;
|
|
|
- offset.x = _touches$.x;
|
|
|
- opts.tooltip = {
|
|
|
+ offset.x = _touches$.x || 0;
|
|
|
+ (opts as any).tooltip = {
|
|
|
textList: option.textList !== undefined ? option.textList : textList,
|
|
|
offset: option.offset !== undefined ? option.offset : offset,
|
|
|
option: option,
|
|
|
@@ -868,24 +891,25 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
if (this.opts.type === 'mix') {
|
|
|
let current = this.getCurrentDataIndex(e);
|
|
|
let index = option.index == undefined ? current.index : option.index;
|
|
|
if (index > -1) {
|
|
|
let currentOffset = this.scrollOption.currentOffset;
|
|
|
- let opts = assign({}, this.opts, {
|
|
|
+ let opts = {
|
|
|
+ ...this.opts,
|
|
|
_scrollDistance_: currentOffset,
|
|
|
animation: false
|
|
|
- });
|
|
|
- let seriesData = getSeriesDataItem(this.opts.series, index);
|
|
|
+ } as ChartsConfig;
|
|
|
+ let seriesData = getSeriesDataItem(this.opts.series || [], index, []);
|
|
|
if (seriesData.length !== 0) {
|
|
|
- let _getMixToolTipData = getMixToolTipData(seriesData, this.opts, index, this.opts.categories, option);
|
|
|
+ let _getMixToolTipData = getMixToolTipData(seriesData as any, this.opts as any, index, this.opts.categories || [], option);
|
|
|
let textList = _getMixToolTipData.textList;
|
|
|
let offset = _getMixToolTipData.offset;
|
|
|
- offset.y = _touches$.y;
|
|
|
- opts.tooltip = {
|
|
|
+ offset.y = _touches$.y || 0;
|
|
|
+ (opts as any).tooltip = {
|
|
|
textList: option.textList ? option.textList : textList,
|
|
|
offset: option.offset !== undefined ? option.offset : offset,
|
|
|
option: option,
|
|
|
@@ -893,24 +917,25 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
if (this.opts.type === 'candle') {
|
|
|
let current = this.getCurrentDataIndex(e);
|
|
|
let index = option.index == undefined ? current.index : option.index;
|
|
|
if (index > -1) {
|
|
|
let currentOffset = this.scrollOption.currentOffset;
|
|
|
- let opts = assign({}, this.opts, {
|
|
|
+ let opts = {
|
|
|
+ ...this.opts,
|
|
|
_scrollDistance_: currentOffset,
|
|
|
animation: false
|
|
|
- });
|
|
|
- let seriesData = getSeriesDataItem(this.opts.series, index);
|
|
|
+ } as ChartsConfig;
|
|
|
+ let seriesData = getSeriesDataItem(this.opts.series || [], index, []);
|
|
|
if (seriesData.length !== 0) {
|
|
|
- let _getToolTipData = getCandleToolTipData(this.opts.series[0].data, seriesData, this.opts, index, this.opts.categories, this.opts.extra.candle, option);
|
|
|
+ let _getToolTipData = getCandleToolTipData(this.opts.series?.[0]?.data || [], seriesData, this.opts as any, index, this.opts.categories || [], this.opts.extra?.candle, option);
|
|
|
let textList = _getToolTipData.textList;
|
|
|
let offset = _getToolTipData.offset;
|
|
|
- offset.y = _touches$.y;
|
|
|
- opts.tooltip = {
|
|
|
+ offset.y = _touches$.y || 0;
|
|
|
+ (opts as any).tooltip = {
|
|
|
textList: option.textList ? option.textList : textList,
|
|
|
offset: option.offset !== undefined ? option.offset : offset,
|
|
|
option: option,
|
|
|
@@ -918,17 +943,17 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
if (this.opts.type === 'pie' || this.opts.type === 'ring' || this.opts.type === 'rose' || this.opts.type === 'funnel') {
|
|
|
let index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index;
|
|
|
if (index > -1) {
|
|
|
- let opts = assign({}, this.opts, { animation: false });
|
|
|
- let seriesData = assign({}, opts._series_[index]);
|
|
|
+ let opts = { ...this.opts, animation: false } as ChartsConfig;
|
|
|
+ let seriesData = { ...opts._series_?.[index] || {} };
|
|
|
let textList = [{
|
|
|
- text: option.formatter ? option.formatter(seriesData, undefined, index, opts) : seriesData.name + ': ' + seriesData.data,
|
|
|
- color: seriesData.color,
|
|
|
- legendShape: this.opts.extra.tooltip.legendShape == 'auto' ? seriesData.legendShape : this.opts.extra.tooltip.legendShape
|
|
|
+ text: option.formatter ? option.formatter(seriesData, undefined, index, opts) : (seriesData.name || '') + ': ' + (seriesData.data || ''),
|
|
|
+ color: seriesData.color || '',
|
|
|
+ legendShape: this.opts.extra?.tooltip?.legendShape == 'auto' ? seriesData.legendShape : this.opts.extra?.tooltip?.legendShape
|
|
|
}];
|
|
|
let offset = {
|
|
|
x: _touches$.x,
|
|
|
@@ -941,24 +966,25 @@ export class uCharts extends uChartsEvent {
|
|
|
index: index
|
|
|
};
|
|
|
}
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
if (this.opts.type === 'map') {
|
|
|
let index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index;
|
|
|
if (index > -1) {
|
|
|
- let opts = assign({}, this.opts, { animation: false });
|
|
|
- let seriesData = assign({}, this.opts.series[index]);
|
|
|
- seriesData.name = seriesData.properties.name
|
|
|
+ let opts = { ...this.opts, animation: false } as ChartsConfig;
|
|
|
+ if (!this.opts.series) return;
|
|
|
+ let seriesData = { ...this.opts.series[index] };
|
|
|
+ seriesData.name = (seriesData as any).properties?.name || seriesData.name || '';
|
|
|
let textList = [{
|
|
|
- text: option.formatter ? option.formatter(seriesData, undefined, index, this.opts) : seriesData.name,
|
|
|
- color: seriesData.color,
|
|
|
- legendShape: this.opts.extra.tooltip.legendShape == 'auto' ? seriesData.legendShape : this.opts.extra.tooltip.legendShape
|
|
|
+ text: option.formatter ? option.formatter(seriesData, undefined, index, this.opts) : (seriesData.name || ''),
|
|
|
+ color: seriesData.color || '',
|
|
|
+ legendShape: this.opts.extra?.tooltip?.legendShape == 'auto' ? seriesData.legendShape : this.opts.extra?.tooltip?.legendShape
|
|
|
}];
|
|
|
let offset = {
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
};
|
|
|
- opts.tooltip = {
|
|
|
+ (opts as any).tooltip = {
|
|
|
textList: option.textList ? option.textList : textList,
|
|
|
offset: option.offset !== undefined ? option.offset : offset,
|
|
|
option: option,
|
|
|
@@ -966,23 +992,24 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
}
|
|
|
opts.updateData = false;
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
if (this.opts.type === 'word') {
|
|
|
let index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index;
|
|
|
if (index > -1) {
|
|
|
- let opts = assign({}, this.opts, { animation: false });
|
|
|
- let seriesData = assign({}, this.opts.series[index]);
|
|
|
+ let opts = { ...this.opts, animation: false } as ChartsConfig;
|
|
|
+ if (!this.opts.series) return;
|
|
|
+ let seriesData = { ...this.opts.series[index] };
|
|
|
let textList = [{
|
|
|
- text: option.formatter ? option.formatter(seriesData, undefined, index, this.opts) : seriesData.name,
|
|
|
- color: seriesData.color,
|
|
|
- legendShape: this.opts.extra.tooltip.legendShape == 'auto' ? seriesData.legendShape : this.opts.extra.tooltip.legendShape
|
|
|
+ text: option.formatter ? option.formatter(seriesData, undefined, index, this.opts) : (seriesData.name || ''),
|
|
|
+ color: seriesData.color || '',
|
|
|
+ legendShape: this.opts.extra?.tooltip?.legendShape == 'auto' ? seriesData.legendShape : this.opts.extra?.tooltip?.legendShape
|
|
|
}];
|
|
|
let offset = {
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
};
|
|
|
- opts.tooltip = {
|
|
|
+ (opts as any).tooltip = {
|
|
|
textList: option.textList ? option.textList : textList,
|
|
|
offset: option.offset !== undefined ? option.offset : offset,
|
|
|
option: option,
|
|
|
@@ -990,26 +1017,26 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
}
|
|
|
opts.updateData = false;
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
if (this.opts.type === 'radar') {
|
|
|
let index = option.index == undefined ? this.getCurrentDataIndex(e) : option.index;
|
|
|
if (index > -1) {
|
|
|
- let opts = assign({}, this.opts, { animation: false });
|
|
|
- let seriesData = getSeriesDataItem(this.opts.series, index);
|
|
|
+ let opts = { ...this.opts, animation: false } as ChartsConfig;
|
|
|
+ let seriesData = getSeriesDataItem(this.opts.series || [], index, []);
|
|
|
if (seriesData.length !== 0) {
|
|
|
let textList = seriesData.map((item) => {
|
|
|
return {
|
|
|
- text: option.formatter ? option.formatter(item, this.opts.categories[index], index, this.opts) : item.name + ': ' + item.data,
|
|
|
- color: item.color,
|
|
|
- legendShape: this.opts.extra.tooltip.legendShape == 'auto' ? item.legendShape : this.opts.extra.tooltip.legendShape
|
|
|
+ text: option.formatter ? option.formatter(item, this.opts.categories?.[index], index, this.opts) : (item.name || '') + ': ' + (item.data || ''),
|
|
|
+ color: item.color || '',
|
|
|
+ legendShape: this.opts.extra?.tooltip?.legendShape == 'auto' ? item.legendShape : this.opts.extra?.tooltip?.legendShape
|
|
|
};
|
|
|
});
|
|
|
let offset = {
|
|
|
- x: _touches$.x,
|
|
|
- y: _touches$.y
|
|
|
+ x: _touches$.x || 0,
|
|
|
+ y: _touches$.y || 0
|
|
|
};
|
|
|
- opts.tooltip = {
|
|
|
+ (opts as any).tooltip = {
|
|
|
textList: option.textList ? option.textList : textList,
|
|
|
offset: option.offset !== undefined ? option.offset : offset,
|
|
|
option: option,
|
|
|
@@ -1017,7 +1044,7 @@ export class uCharts extends uChartsEvent {
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1032,11 +1059,12 @@ export class uCharts extends uChartsEvent {
|
|
|
distance: 0,
|
|
|
lastMoveTime: 0
|
|
|
};
|
|
|
- let opts = assign({}, this.opts, {
|
|
|
+ let opts = {
|
|
|
+ ...this.opts,
|
|
|
_scrollDistance_: distance,
|
|
|
animation: false
|
|
|
- });
|
|
|
- drawCharts.call(this, this.opts.type, opts, this.config, this.context);
|
|
|
+ } as ChartsConfig;
|
|
|
+ drawCharts.call(this, this.opts.type || '', opts as any, this.config, this.context);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1047,12 +1075,12 @@ export class uCharts extends uChartsEvent {
|
|
|
let touches = null;
|
|
|
if (e.changedTouches) {
|
|
|
touches = e.changedTouches[0];
|
|
|
- } else {
|
|
|
+ } else if (e.mp && e.mp.changedTouches) {
|
|
|
touches = e.mp.changedTouches[0];
|
|
|
}
|
|
|
- let _touches$ = getTouches(touches, this.opts, e);
|
|
|
if (touches && this.opts.enableScroll === true) {
|
|
|
- this.scrollOption.startTouchX = _touches$.x;
|
|
|
+ let _touches$ = getTouches(touches, this.opts as any, e as any);
|
|
|
+ this.scrollOption.startTouchX = _touches$.x || 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1074,22 +1102,25 @@ export class uCharts extends uChartsEvent {
|
|
|
let touches = null;
|
|
|
if (e.changedTouches) {
|
|
|
touches = e.changedTouches[0];
|
|
|
- } else {
|
|
|
+ } else if (e.mp && e.mp.changedTouches) {
|
|
|
touches = e.mp.changedTouches[0];
|
|
|
}
|
|
|
if (touches && this.opts.enableScroll === true) {
|
|
|
- let _touches$ = getTouches(touches, this.opts, e);
|
|
|
+ let _touches$ = getTouches(touches, this.opts as any, e as any);
|
|
|
let _distance;
|
|
|
- _distance = _touches$.x - this.scrollOption.startTouchX;
|
|
|
+ _distance = (_touches$.x || 0) - this.scrollOption.startTouchX;
|
|
|
let currentOffset = this.scrollOption.currentOffset;
|
|
|
- let validDistance = calValidDistance(this, currentOffset + _distance, this.opts.chartData, this.config, this.opts);
|
|
|
+ const self = this as unknown as CoordinateUChartInstance;
|
|
|
+ self.scrollOption = { position: this.scrollOption.currentOffset };
|
|
|
+ let validDistance = calValidDistance(self, currentOffset + _distance, this.opts.chartData || { eachSpacing: 0 }, this.config as any, this.opts as any);
|
|
|
this.scrollOption.distance = _distance = validDistance - currentOffset;
|
|
|
- let opts = assign({}, this.opts, {
|
|
|
+ let opts = {
|
|
|
+ ...this.opts,
|
|
|
_scrollDistance_: currentOffset + _distance,
|
|
|
animation: false
|
|
|
- });
|
|
|
+ } as ChartsConfig;
|
|
|
this.opts = opts;
|
|
|
- drawCharts.call(this, opts.type, opts, this.config, this.context);
|
|
|
+ drawCharts.call(this, opts.type || '', opts as any, this.config, this.context);
|
|
|
return currentOffset + _distance;
|
|
|
}
|
|
|
return 0;
|