Skip to content

Commit 45e981a

Browse files
committed
Merge branch 'main' of github.com:le5le-com/meta2d.js
2 parents c79e0c7 + a9d48f3 commit 45e981a

File tree

24 files changed

+1667
-900
lines changed

24 files changed

+1667
-900
lines changed

packages/chart-diagram/package.build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@meta2d/chart-diagram",
3-
"version": "1.0.13",
3+
"version": "1.0.14",
44
"description": "The charting library based on le5le meta2d and echarts/highcharts.",
55
"main": "index.js",
66
"types": "index.d.ts",

packages/chart-diagram/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@meta2d/chart-diagram",
3-
"version": "1.0.13",
3+
"version": "1.0.14",
44
"description": "The charting library based on le5le meta2d and echarts/highcharts.",
55
"main": "index.ts",
66
"types": "index.d.ts",

packages/chart-diagram/src/echarts.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export interface ChartPen extends Pen {
5959
geoUrl?: string;
6060
diabled?: boolean; //通过脚本setOption后,禁止默认拿到echarts.option去设置图元
6161
replaceMerge?: string; // 替换合并
62+
timeKeys?: string[]; // 时间键
63+
dataMap?:any; // 数据映射,sql 查询结果的映射
6264
};
6365
calculative?: {
6466
partialOption?: any; // 部分更新的 option
@@ -345,6 +347,9 @@ function beforeValue(pen: ChartPen, value: any) {
345347
return value;
346348
}
347349
if (pen.realTimes && pen.realTimes.length) {
350+
if(pen.echarts.dataMap&&value.data){
351+
value = formatData(pen, value);
352+
}
348353
let keys = Object.keys(value);
349354
const { xAxis, yAxis } = pen.echarts.option;
350355
const { max, replaceMode, timeFormat } = pen.echarts;
@@ -547,6 +552,45 @@ function beforeValue(pen: ChartPen, value: any) {
547552
return Object.assign(value, { echarts });
548553
}
549554

555+
/*
556+
将sql 查询结果的数据格式化为 echarts 可用的格式
557+
*/
558+
function formatData(pen: any, value:any) {
559+
if(!pen.echarts.dataMap||!value.data){
560+
return value;
561+
}
562+
if(value.data){
563+
let dataValue = {};
564+
if(Array.isArray(value.data)){
565+
//sql 列表
566+
for (const key in pen.echarts.dataMap) {
567+
if (pen.echarts.dataMap.hasOwnProperty(key)) {
568+
if(pen.echarts.timeKeys?.length&&pen.echarts.timeKeys.includes(pen.echarts.dataMap[key])){
569+
dataValue[key] = value.data.map(item=>formatTime(pen.echarts.timeFormat,item[pen.echarts.dataMap[key]]));
570+
}else{
571+
dataValue[key] = value.data.map(item=>item[pen.echarts.dataMap[key]]);
572+
}
573+
}
574+
}
575+
576+
}else{
577+
//sql 单条
578+
for (const key in pen.echarts.dataMap) {
579+
if (pen.echarts.dataMap.hasOwnProperty(key)) {
580+
if(pen.echarts.timeKeys?.length&&pen.echarts.timeKeys.includes(pen.echarts.dataMap[key])){
581+
dataValue[key] = formatTime(pen.echarts.timeFormat,value.data[pen.echarts.dataMap[key]]);
582+
}else{
583+
dataValue[key] = value.data[pen.echarts.dataMap[key]];
584+
}
585+
}
586+
}
587+
}
588+
delete value.data;
589+
Object.assign(value, dataValue);
590+
return value;
591+
}
592+
}
593+
550594
function binds(pen: ChartPen, values: IValue[], formItem: FormItem): IValue {
551595
if (formItem.key !== 'dataY') {
552596
return;

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@meta2d/core",
3-
"version": "1.0.74",
3+
"version": "1.0.77",
44
"description": "@meta2d/core: Powerful, Beautiful, Simple, Open - Web-Based 2D At Its Best .",
55
"main": "index.ts",
66
"types": "index.d.ts",

packages/core/src/canvas/canvas.ts

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,8 @@ export class Canvas {
13671367
!pen.parentId && this.randomCombineId(pen, pens);
13681368
}
13691369
if (Object.keys(this.randomIdObj).length !== 0) {
1370+
const keys = Object.keys(this.randomIdObj).join('|');
1371+
const regex = new RegExp(`(${keys})`, "g");
13701372
for (const pen of pens) {
13711373
if (pen.type) {
13721374
pen.anchors[0].connectTo = this.randomIdObj[pen.anchors[0].connectTo];
@@ -1378,6 +1380,20 @@ export class Canvas {
13781380
item.lineId = this.randomIdObj[item.lineId];
13791381
});
13801382
}
1383+
1384+
//动画、事件和状态
1385+
if(pen.animations?.length){
1386+
const str = JSON.stringify(pen.animations).replace(regex, match => this.randomIdObj[match]);
1387+
pen.animations = JSON.parse(str);
1388+
}
1389+
if(pen.triggers?.length){
1390+
const str = JSON.stringify(pen.triggers).replace(regex, match => this.randomIdObj[match]);
1391+
pen.triggers = JSON.parse(str);
1392+
}
1393+
if(pen.events?.length){
1394+
const str = JSON.stringify(pen.events).replace(regex, match => this.randomIdObj[match]);
1395+
pen.events = JSON.parse(str);
1396+
}
13811397
}
13821398
}
13831399
for (const pen of pens) {
@@ -1490,14 +1506,18 @@ export class Canvas {
14901506
pen.anchors[0].id,
14911507
pen.anchors[pen.anchors.length - 1].id,
14921508
];
1509+
}else{
1510+
beforeIds = [pen.id];
14931511
}
14941512
} else {
1495-
if (pen.connectedLines && pen.connectedLines.length) {
1513+
if(pens.length>1){
1514+
// if (pen.connectedLines && pen.connectedLines.length) {
14961515
beforeIds = [pen.id];
14971516
}
14981517
}
14991518
randomId(pen);
1500-
if (beforeIds) {
1519+
if(pens.length>1){
1520+
// if (beforeIds) {
15011521
if (beforeIds.length === 1) {
15021522
this.randomIdObj[beforeIds[0]] = pen.id;
15031523
} else {
@@ -2842,7 +2862,7 @@ export class Canvas {
28422862
const gridSize = this.store.data.gridSize || this.store.options.gridSize;
28432863
const { origin, scale } = this.store.data;
28442864
const autoAlignGrid =
2845-
this.store.options.autoAlignGrid && this.store.data.grid;
2865+
this.store.options.autoAlignGrid && (this.store.data.grid || this.store.options.grid);
28462866
movedPens.forEach((pen) => {
28472867
const i = this.movingPens.findIndex((item) => item.id === pen.id+movingSuffix);
28482868
if(i<0){
@@ -3767,6 +3787,7 @@ export class Canvas {
37673787
} else if (!pen.height) {
37683788
pen.width = this.width;
37693789
}
3790+
this.updatePenRect(pen);
37703791
}
37713792
calcInView(pen);
37723793
}
@@ -4203,6 +4224,12 @@ export class Canvas {
42034224
});
42044225
}
42054226
!pen.rotate && (pen.rotate = 0);
4227+
pen.lineAnimateImages ??= []
4228+
if(pen.lineAnimateImages){
4229+
pen.lineAnimateImages.forEach((src)=>{
4230+
this.__loadImage(src)
4231+
})
4232+
}
42064233
this.loadImage(pen);
42074234
this.parent.penNetwork(pen);
42084235
}
@@ -4572,6 +4599,33 @@ export class Canvas {
45724599
pen.calculative.strokeImage = pen.strokeImage;
45734600
}
45744601
}
4602+
4603+
// 加载图片到全局缓存
4604+
__loadImage(src:string){
4605+
return new Promise(resolve=>{
4606+
if(!globalStore.htmlElements[src]){
4607+
const img = new Image();
4608+
img.crossOrigin = 'anonymous';
4609+
img.src = src;
4610+
if (
4611+
this.store.options.cdn &&
4612+
!(
4613+
src.startsWith('http') ||
4614+
src.startsWith('//') ||
4615+
src.startsWith('data:image')
4616+
)
4617+
) {
4618+
img.src = this.store.options.cdn + src;
4619+
}
4620+
img.onload = () => {
4621+
globalStore.htmlElements[src] = img;
4622+
resolve(img);
4623+
};
4624+
}else{
4625+
resolve(globalStore.htmlElements[src]);
4626+
}
4627+
})
4628+
}
45754629
private imageTimer: any;
45764630
// 避免初始化图片加载重复调用 render,此处防抖
45774631
imageLoaded() {
@@ -5217,11 +5271,11 @@ export class Canvas {
52175271
}
52185272
scalePoint(this.store.data.origin, s, center);
52195273
this.store.data.pens.forEach((pen) => {
5274+
pen.onScale && pen.onScale(pen);
52205275
if (pen.parentId) {
52215276
return;
52225277
}
52235278
scalePen(pen, s, center);
5224-
pen.onScale && pen.onScale(pen);
52255279
if (pen.isRuleLine) {
52265280
// 扩大线的比例,若是放大,即不缩小,若是缩小,会放大
52275281
const lineScale = 1 / s; //s > 1 ? 1 : 1 / s / s;
@@ -6713,8 +6767,19 @@ export class Canvas {
67136767
const curPage = sessionStorage.getItem('page');
67146768
const scale = this.store.data.scale;
67156769
if(this.store.clipboard.mousePos&&(Math.abs(this.store.clipboard.mousePos.x-this.mousePos.x)>100*scale||Math.abs(this.store.clipboard.mousePos.y-this.mousePos.y)>100*scale)){
6716-
const offsetX = (scale-this.store.clipboard.scale)*this.store.clipboard.initRect.width/2;
6717-
const offsetY = (scale-this.store.clipboard.scale)*this.store.clipboard.initRect.height/2;
6770+
let _x = -this.store.clipboard.initRect.width/this.store.clipboard.scale/10/(scale);
6771+
let _y = -this.store.clipboard.initRect.height/this.store.clipboard.scale/10/(scale);
6772+
let offsetX = (scale-this.store.clipboard.scale)*this.store.clipboard.initRect.width/2+_x;
6773+
let offsetY = (scale-this.store.clipboard.scale)*this.store.clipboard.initRect.height/2+_y;
6774+
if(scale<this.store.clipboard.scale){
6775+
// 减小粘贴偏移量
6776+
offsetX = (scale-this.store.clipboard.scale)/((this.store.clipboard.scale-scale)*100)*this.store.clipboard.initRect.width/2+_x;
6777+
offsetY = (scale-this.store.clipboard.scale)/((this.store.clipboard.scale-scale)*100)*this.store.clipboard.initRect.height/2+_y;
6778+
}
6779+
if(this.store.clipboard.pens.length>1){
6780+
offsetX = (scale-1)*this.store.clipboard.initRect.width/this.store.clipboard.scale/2;
6781+
offsetY = (scale-1)*this.store.clipboard.initRect.height/this.store.clipboard.scale/2;
6782+
}
67186783
this.store.clipboard.pos = { x: this.mousePos.x-offsetX, y: this.mousePos.y-offsetY };
67196784
this.store.clipboard.offset = 0;
67206785
}else if (curPage !== clipboard.page) {
@@ -7119,7 +7184,7 @@ export class Canvas {
71197184
id = _id;
71207185
}
71217186
}
7122-
7187+
71237188
});
71247189
this.store.hover = this.store.pens[id];
71257190
this.store.pens[id].calculative.hover = true;
@@ -7846,7 +7911,7 @@ export class Canvas {
78467911
if (needCalcIconRectProps.includes(k)) {
78477912
willCalcIconRect = true;
78487913
}
7849-
if(pen.image && pen.name !== 'gif' && ['globalAlpha', 'flipY', 'flipX', 'x', 'y', 'width', 'height','iconWidth', 'iconHeight', 'imageRatio', 'iconLeft','iconTop', 'iconAlign', 'rotate'].includes(k)){
7914+
if(pen.image && pen.name !== 'gif' && ['globalAlpha', 'flipY', 'flipX', 'x', 'y', 'width', 'height','iconWidth', 'iconHeight', 'imageRatio', 'iconLeft','iconTop', 'iconAlign', 'rotate', 'visible'].includes(k)){
78507915
willRenderImage = true;
78517916
}
78527917
} else {
@@ -8442,6 +8507,7 @@ export class Canvas {
84428507
this.externalElements.style.zIndex = '5';
84438508
this.magnifierCanvas.magnifier = false;
84448509
this.externalElements.style.cursor = 'default';
8510+
this.magnifierCanvas.render();
84458511
this.render();
84468512
}
84478513

0 commit comments

Comments
 (0)