diff --git a/src/chart/graph/GraphView.ts b/src/chart/graph/GraphView.ts index f5672a0e9d..cb56a1da7f 100644 --- a/src/chart/graph/GraphView.ts +++ b/src/chart/graph/GraphView.ts @@ -120,6 +120,13 @@ class GraphView extends ChartView implements RoamHostView { this._firstRender ? null : seriesModel, ); } + else { + // On cartesian2d (or any coordinate system that is not its own view), + // nodes are laid out in global coordinates. Drop the transform a + // previous render on a view coordinate system left on the group. + mainGroup.stopAnimation(); + mainGroup.attr({x: 0, y: 0, scaleX: 1, scaleY: 1}); + } // Fix edge contact point with node adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel)); diff --git a/test/ut/spec/series/graph.test.ts b/test/ut/spec/series/graph.test.ts new file mode 100644 index 0000000000..e30f86f7a4 --- /dev/null +++ b/test/ut/spec/series/graph.test.ts @@ -0,0 +1,70 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + + +import { createChart } from '../../core/utHelper'; + + +describe('graph', function () { + + const viewOption = { + animation: false, + series: [{ + type: 'graph', + layout: 'none', + data: [{ name: 'a', x: 0, y: 0 }, { name: 'b', x: 1000, y: 800 }], + links: [{ source: 'a', target: 'b' }] + }] + }; + + const cartesianOption = { + animation: false, + xAxis: { type: 'value', min: 0, max: 10 }, + yAxis: { type: 'value', min: 0, max: 10 }, + series: [{ + type: 'graph', + coordinateSystem: 'cartesian2d', + data: [[2, 3], [8, 7]], + links: [{ source: 0, target: 1 }] + }] + }; + + function mainGroupTransform(chart: any) { + const group = chart._chartsViews[0]._mainGroup; + return [group.x, group.y, group.scaleX, group.scaleY]; + } + + it('places a cartesian2d graph on the grid after a graph on the view coordinate system', function () { + const switched = createChart({width: 400, height: 300}); + const direct = createChart({width: 400, height: 300}); + + try { + switched.setOption(viewOption); + switched.setOption(cartesianOption, true); + direct.setOption(cartesianOption); + + expect(mainGroupTransform(switched)).toEqual(mainGroupTransform(direct)); + expect(mainGroupTransform(switched)).toEqual([0, 0, 1, 1]); + } + finally { + switched.dispose(); + direct.dispose(); + } + }); +});