Skip to content

Commit a74ffbd

Browse files
authored
Merge pull request #2970 from antvis/4.3.4
4.3.4
2 parents 935338f + 8b05506 commit a74ffbd

File tree

25 files changed

+526
-47
lines changed

25 files changed

+526
-47
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# ChangeLog
22

3+
#### 4.3.4
4+
5+
- fix: when select a node with click-select, selected combos should be deselected;
6+
- fix: contextmenu with click trigger does not show the menu up, closes: #2982;
7+
- fix: layout with collapsed combo, closes: #2988;
8+
- fix: zoom-canvas with optimizeZoom, drag-canvas shows the node shapes hiden by zoom-canvas optimizeZoom, closes: #2996;
9+
310
#### 4.3.3
411

512
- fix: uncombo with id, closes: #2924;

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-core",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "A Graph Visualization Framework in JavaScript",
55
"keywords": [
66
"antv",

packages/core/src/global.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const colorSet = {
6464
};
6565

6666
export default {
67-
version: '0.3.3',
67+
version: '0.3.4',
6868
rootContainerClassName: 'root-container',
6969
nodeContainerClassName: 'node-container',
7070
edgeContainerClassName: 'edge-container',

packages/core/src/graph/controller/item.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export default class ItemController {
167167
if (model.collapsed) {
168168
setTimeout(() => {
169169
graph.collapseCombo(item as ICombo);
170-
}, 16);
170+
}, 0);
171171
}
172172
}
173173

@@ -310,11 +310,12 @@ export default class ItemController {
310310
}
311311
const model = combo.getModel();
312312
const comboBBox = getComboBBox(model.collapsed ? [] : children, graph);
313+
const { x: comboX, y: comboY } = model.collapsed ? getComboBBox(children, graph) : comboBBox;
313314

314315
combo.set('bbox', comboBBox);
315316
combo.update({
316-
x: comboBBox.x,
317-
y: comboBBox.y,
317+
x: comboX,
318+
y: comboY,
318319
});
319320

320321
const shapeFactory = combo.get('shapeFactory');

packages/core/src/graph/graph.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,8 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
14461446
if (combosData) {
14471447
const comboTrees = plainCombosToTrees(combosData, (data as GraphData).nodes);
14481448
this.set('comboTrees', comboTrees);
1449+
} else {
1450+
this.set('comboTrees', []);
14491451
}
14501452

14511453
this.diffItems('node', items, (data as GraphData).nodes!);

packages/element/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-element",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "A Graph Visualization Framework in JavaScript",
55
"keywords": [
66
"antv",
@@ -61,7 +61,7 @@
6161
},
6262
"dependencies": {
6363
"@antv/g-base": "^0.5.1",
64-
"@antv/g6-core": "0.3.3",
64+
"@antv/g6-core": "0.3.4",
6565
"@antv/util": "~2.0.5"
6666
},
6767
"devDependencies": {

packages/g6/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6",
3-
"version": "4.3.3",
3+
"version": "4.3.4",
44
"description": "A Graph Visualization Framework in JavaScript",
55
"keywords": [
66
"antv",
@@ -66,7 +66,7 @@
6666
]
6767
},
6868
"dependencies": {
69-
"@antv/g6-pc": "0.3.3"
69+
"@antv/g6-pc": "0.3.4"
7070
},
7171
"devDependencies": {
7272
"@babel/core": "^7.7.7",

packages/g6/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import G6 from '@antv/g6-pc';
22

3-
G6.version = '4.3.3';
3+
G6.version = '4.3.4';
44

55
export * from '@antv/g6-pc';
66
export default G6;
7-
export const version = '4.3.3';
7+
export const version = '4.3.4';

packages/pc/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-pc",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "A Graph Visualization Framework in JavaScript",
55
"keywords": [
66
"antv",
@@ -74,9 +74,9 @@
7474
"@antv/g-canvas": "^0.5.2",
7575
"@antv/g-math": "^0.1.1",
7676
"@antv/g-svg": "^0.5.1",
77-
"@antv/g6-core": "0.3.3",
78-
"@antv/g6-plugin": "0.3.3",
79-
"@antv/g6-element": "0.3.3",
77+
"@antv/g6-core": "0.3.4",
78+
"@antv/g6-plugin": "0.3.4",
79+
"@antv/g6-element": "0.3.4",
8080
"@antv/algorithm": "^0.1.8",
8181
"@antv/hierarchy": "^0.6.7",
8282
"@antv/layout": "^0.1.14",

packages/pc/src/behavior/click-select.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default {
5252

5353
// allow to select multiple nodes but did not press a key || do not allow the select multiple nodes
5454
if (!keydown || !multiple) {
55-
const selected = graph.findAllByState(type, self.selectedState);
55+
const selected = graph.findAllByState('node', self.selectedState).concat(graph.findAllByState('combo', self.selectedState));
5656
each(selected, (combo) => {
5757
if (combo !== item) {
5858
graph.setItemState(combo, self.selectedState, false);

packages/pc/src/behavior/drag-canvas.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ export default {
202202

203203
if (this.keydown) return;
204204

205+
const currentZoom = graph.getZoom();
206+
const modeController = graph.get('modeController');
207+
const zoomCanvas = modeController?.modes[modeController.mode]?.filter(behavior => behavior.type === 'zoom-canvas')?.[0];
208+
const optimizeZoom = zoomCanvas ? zoomCanvas.optimizeZoom || 0.1 : 0;
209+
205210
if (this.enableOptimize) {
206211
// 拖动结束后显示所有的边
207212
const edges = graph.getEdges();
@@ -213,15 +218,17 @@ export default {
213218
if (oriVis) shape.show();
214219
});
215220
}
216-
const nodes = graph.getNodes();
217-
for (let j = 0, nodeLen = nodes.length; j < nodeLen; j++) {
218-
const container = nodes[j].getContainer();
219-
const children = container.get('children');
220-
for (const child of children) {
221-
const isKeyShape = child.get('isKeyShape');
222-
if (!isKeyShape) {
223-
const oriVis = child.get('ori-visibility');
224-
if (oriVis) child.show();
221+
if (currentZoom > optimizeZoom) {
222+
const nodes = graph.getNodes();
223+
for (let j = 0, nodeLen = nodes.length; j < nodeLen; j++) {
224+
const container = nodes[j].getContainer();
225+
const children = container.get('children');
226+
for (const child of children) {
227+
const isKeyShape = child.get('isKeyShape');
228+
if (!isKeyShape) {
229+
const oriVis = child.get('ori-visibility');
230+
if (oriVis) child.show();
231+
}
225232
}
226233
}
227234
}

packages/pc/src/global.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const textColor = 'rgb(0, 0, 0)';
77
const colorSet = getColorsWithSubjectColor(subjectColor, backColor);
88

99
export default {
10-
version: '0.3.3',
10+
version: '0.3.4',
1111
rootContainerClassName: 'root-container',
1212
nodeContainerClassName: 'node-container',
1313
edgeContainerClassName: 'edge-container',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import G6 from '../../src';
2+
3+
const div = document.createElement('div');
4+
div.id = 'container';
5+
document.body.appendChild(div);
6+
7+
const data = {
8+
"combos": [
9+
{
10+
"id": "ccc",
11+
"label": "ccc",
12+
"collapsed": true
13+
}
14+
],
15+
"edges": [
16+
{
17+
"source": "a",
18+
"target": "b"
19+
}
20+
],
21+
"nodes": [
22+
{
23+
"id": "b"
24+
},
25+
{
26+
"comboId": "ccc",
27+
"id": "a"
28+
}
29+
]
30+
};
31+
32+
describe('combo layout with collapsed', () => {
33+
it('combo layout with collapsed', () => {
34+
const graph = new G6.Graph({
35+
container: 'container',
36+
width: 500,
37+
height: 500,
38+
// Set groupByTypes to false to get rendering result with reasonable visual zIndex for combos
39+
groupByTypes: false,
40+
layout: {
41+
type: 'grid'
42+
},
43+
});
44+
45+
graph.data(data);
46+
graph.render();
47+
console.log('data', data)
48+
setTimeout(() => {
49+
expect(data.combos[0].x).toBe(250)
50+
expect(data.combos[0].y).toBe(375)
51+
}, 0);
52+
});
53+
});

packages/pc/tests/unit/combo-issue-spec.ts

+27
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,30 @@ describe('combo edges', () => {
287287
graph.destroy();
288288
})
289289
});
290+
291+
292+
describe.only('select combo and node', () => {
293+
it('select combo and node', () => {
294+
const graph = new G6.Graph({
295+
container: 'container',
296+
width: 500,
297+
height: 500,
298+
// Set groupByTypes to false to get rendering result with reasonable visual zIndex for combos
299+
groupByTypes: false,
300+
comboStateStyles: {
301+
hover: {
302+
stroke: 'green',
303+
},
304+
selected: {
305+
stroke: 'red',
306+
},
307+
},
308+
modes: {
309+
default: ['click-select'],
310+
},
311+
});
312+
313+
graph.data(data);
314+
graph.render();
315+
});
316+
});

packages/plugin/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-plugin",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "G6 Plugin",
55
"main": "lib/index.js",
66
"module": "es/index.js",
@@ -22,7 +22,7 @@
2222
"@antv/g-base": "^0.5.1",
2323
"@antv/g-canvas": "^0.5.2",
2424
"@antv/g-svg": "^0.5.2",
25-
"@antv/g6-core": "0.3.3",
25+
"@antv/g6-core": "0.3.4",
2626
"@antv/matrix-util": "^3.0.4",
2727
"@antv/scale": "^0.3.4",
2828
"@antv/util": "^2.0.9",

packages/plugin/src/menu/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ export default class Menu extends Base {
9797

9898
const itemTypes = this.get('itemTypes');
9999
if (!e.item) {
100-
if (itemTypes.indexOf('canvas') === -1) return;
100+
if (itemTypes.indexOf('canvas') === -1) {
101+
self.onMenuHide();
102+
return;
103+
}
101104
} else {
102105
if (e.item && e.item.getType && itemTypes.indexOf(e.item.getType()) === -1) {
103106
self.onMenuHide();
@@ -157,7 +160,13 @@ export default class Menu extends Base {
157160
visibility: 'visible',
158161
});
159162

163+
// 左键单击会触发 body 上监听的 click 事件,导致菜单展示出来后又立即被隐藏了,需要过滤掉
164+
let triggeredByFirstClick = this.get('trigger') === 'click';
160165
const handler = (evt) => {
166+
if (triggeredByFirstClick) {
167+
triggeredByFirstClick = false;
168+
return;
169+
}
161170
self.onMenuHide();
162171
};
163172

0 commit comments

Comments
 (0)