Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita61dfe8

Browse files
committed
refactor: DMATH-34 Вынесены magic числа в конфиги и исправлен тест Renderer
1 parentc14fa97 commita61dfe8

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

‎src/app/algorithms/hungarian/page.tsx‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import{AlgorithmLayout,useAlgorithmLayout}from'@/components/graph/AlgorithmLayout';
44
import{GraphMatrixInput}from'@/components/input';
5+
import{graphConfig}from'@/shared/lib/config';
56
importtype{GraphDTO,NodeDTO,EdgeDTO}from'@/types';
67

78
functionHungarianContent(){
@@ -39,39 +40,33 @@ function HungarianContent() {
3940
constnodes:NodeDTO[]=[];
4041
constedges:EdgeDTO[]=[];
4142

42-
constradius=180;
43-
constcenterX=0;
44-
constcenterY=0;
45-
46-
constnodeColor='#3b82f6';
47-
constedgeColor='#60a5fa';
43+
const{ nodeRadius, center, nodeSize, nodeColors, edgeColors, edgeWidth, angleRange}=
44+
graphConfig;
4845

4946
for(leti=0;i<nodeCount;i++){
50-
constangleRange=Math.PI*0.8;
5147
conststartAngle=-angleRange/2;
5248
constangle=startAngle+(i/Math.max(1,nodeCount-1))*angleRange;
5349
nodes.push({
5450
id:`source_${i}`,
55-
x:centerX-radius*Math.cos(angle),
56-
y:centerY+radius*Math.sin(angle),
51+
x:center.x-nodeRadius*Math.cos(angle),
52+
y:center.y+nodeRadius*Math.sin(angle),
5753
label:`S${i+1}`,
58-
radius:25,
59-
color:nodeColor,
54+
radius:nodeSize.radius,
55+
color:nodeColors.default,
6056
state:'default',
6157
});
6258
}
6359

6460
for(leti=0;i<nodeCount;i++){
65-
constangleRange=Math.PI*0.8;
6661
conststartAngle=-angleRange/2;
6762
constangle=startAngle+(i/Math.max(1,nodeCount-1))*angleRange;
6863
nodes.push({
6964
id:`target_${i}`,
70-
x:centerX+radius*Math.cos(angle),
71-
y:centerY+radius*Math.sin(angle),
65+
x:center.x+nodeRadius*Math.cos(angle),
66+
y:center.y+nodeRadius*Math.sin(angle),
7267
label:`T${i+1}`,
73-
radius:25,
74-
color:'#8b5cf6',
68+
radius:nodeSize.radius,
69+
color:nodeColors.target,
7570
state:'default',
7671
});
7772
}
@@ -106,8 +101,8 @@ function HungarianContent() {
106101
target:targetId,
107102
weight:weight,
108103
directed:true,
109-
color:edgeColor,
110-
width:2,
104+
color:edgeColors.default,
105+
width:edgeWidth,
111106
state:'default',
112107
});
113108
}

‎src/services/renderer/__tests__/Renderer.browser.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,12 @@ describe('Renderer', () => {
280280
it('should draw all nodes and edges',()=>{
281281
model.addNode({id:'node1',x:100,y:100});
282282
model.addNode({id:'node2',x:200,y:200});
283-
model.addEdge({id:'edge1',source:'node1',target:'node2'});
283+
model.addEdge({id:'edge1',source:'node1',target:'node2',weight:5});
284284

285285
renderer.drawAll(model);
286286

287287
expect(mockGraphics).toHaveBeenCalledTimes(3);
288-
expect(mockText).toHaveBeenCalledTimes(2);
288+
expect(mockText).toHaveBeenCalledTimes(3);// 2 node labels + 1 edge weight
289289
});
290290

291291
it('should draw edges before nodes',()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp