Skip to content

Commit 36031b7

Browse files
committed
Remove options parameter in tracer constructors
1 parent e0686f2 commit 36031b7

File tree

6 files changed

+32
-41
lines changed

6 files changed

+32
-41
lines changed

src/backend/tracers

src/frontend/core/datas/Data.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
class Data {
2-
constructor(options) {
3-
this.options = {
4-
...this.getDefaultOptions(),
5-
...options,
6-
};
2+
constructor() {
73
this.init();
84
this.reset();
95
}
106

11-
getDefaultOptions() {
12-
return {};
13-
}
14-
157
init() {
168
}
179

src/frontend/core/datas/GraphData.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ import { distance } from '/common/util';
33
import { tracerManager } from '/core';
44

55
class GraphData extends Data {
6-
getDefaultOptions() {
7-
return {
8-
...super.getDefaultOptions(),
9-
directed: true,
10-
weighted: false,
11-
};
12-
}
13-
146
init() {
157
super.init();
168
this.dimensions = {
@@ -22,20 +14,29 @@ class GraphData extends Data {
2214
nodeWeightGap: 4,
2315
edgeWeightGap: 4,
2416
};
25-
this.logData = null;
17+
this.isDirected = true;
18+
this.isWeighted = false;
2619
this.callLayout = { method: this.layoutCircle, args: [] };
20+
this.logData = null;
21+
}
22+
23+
directed(isDirected = true) {
24+
this.isDirected = isDirected;
25+
}
26+
27+
weighted(isWeighted = true) {
28+
this.isWeighted = isWeighted;
2729
}
2830

2931
set(array2d = []) {
30-
const { weighted } = this.options;
3132
this.nodes = [];
3233
this.edges = [];
3334
for (let i = 0; i < array2d.length; i++) {
3435
this.addNode(i);
3536
for (let j = 0; j < array2d.length; j++) {
3637
const value = array2d[i][j];
3738
if (value) {
38-
this.addEdge(i, j, weighted ? value : null);
39+
this.addEdge(i, j, this.isWeighted ? value : null);
3940
}
4041
}
4142
}
@@ -64,8 +65,8 @@ class GraphData extends Data {
6465
return this.nodes.find(node => node.id === id);
6566
}
6667

67-
findEdge(source, target, directed = this.options.directed) {
68-
if (directed) {
68+
findEdge(source, target, isDirected = this.isDirected) {
69+
if (isDirected) {
6970
return this.edges.find(edge => edge.source === source && edge.target === target);
7071
} else {
7172
return this.edges.find(edge =>
@@ -74,21 +75,21 @@ class GraphData extends Data {
7475
}
7576
}
7677

77-
findLinkedEdges(source, directed = this.options.directed) {
78-
if (directed) {
78+
findLinkedEdges(source, isDirected = this.isDirected) {
79+
if (isDirected) {
7980
return this.edges.filter(edge => edge.source === source);
8081
} else {
8182
return this.edges.filter(edge => edge.source === source || edge.target === source);
8283
}
8384
}
8485

85-
findLinkedNodeIds(source, directed = this.options.directed) {
86-
const edges = this.findLinkedEdges(source, directed);
86+
findLinkedNodeIds(source, isDirected = this.isDirected) {
87+
const edges = this.findLinkedEdges(source, isDirected);
8788
return edges.map(edge => edge.source === source ? edge.target : edge.source);
8889
}
8990

90-
findLinkedNodes(source, directed = this.options.directed) {
91-
const ids = this.findLinkedNodeIds(source, directed);
91+
findLinkedNodes(source, isDirected = this.isDirected) {
92+
const ids = this.findLinkedNodeIds(source, isDirected);
9293
return ids.map(id => this.findNode(id));
9394
}
9495

src/frontend/core/renderers/GraphRenderer/index.jsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ class GraphRenderer extends Renderer {
3939
}
4040

4141
renderData() {
42-
const { nodes, edges, options, dimensions } = this.props.data;
42+
const { nodes, edges, isDirected, isWeighted, dimensions } = this.props.data;
4343
const { baseWidth, baseHeight, nodeRadius, arrowGap, nodeWeightGap, edgeWeightGap } = dimensions;
44-
const { directed, weighted } = options;
4544
const viewBox = [
4645
(this.centerX - baseWidth / 2) * this.zoom,
4746
(this.centerY - baseHeight / 2) * this.zoom,
@@ -71,7 +70,7 @@ class GraphRenderer extends Renderer {
7170
const dx = ex - sx;
7271
const dy = ey - sy;
7372
const degree = Math.atan2(dy, dx) / Math.PI * 180;
74-
if (directed) {
73+
if (isDirected) {
7574
const length = Math.sqrt(dx * dx + dy * dy);
7675
if (length !== 0) {
7776
ex = sx + dx / length * (length - nodeRadius - arrowGap);
@@ -81,9 +80,9 @@ class GraphRenderer extends Renderer {
8180

8281
return (
8382
<g className={classes(styles.edge, selectedCount && styles.selected, visitedCount && styles.visited)} key={`${source}-${target}`}>
84-
<path d={`M${sx},${sy} L${ex},${ey}`} className={classes(styles.line, directed && styles.directed)} />
83+
<path d={`M${sx},${sy} L${ex},${ey}`} className={classes(styles.line, isDirected && styles.directed)} />
8584
{
86-
weighted &&
85+
isWeighted &&
8786
<g transform={`translate(${mx},${my})`}>
8887
<text className={styles.weight} transform={`rotate(${degree})`}
8988
y={-edgeWeightGap}>{this.toString(weight)}</text>
@@ -102,7 +101,7 @@ class GraphRenderer extends Renderer {
102101
<circle className={styles.circle} r={nodeRadius} />
103102
<text className={styles.id}>{id}</text>
104103
{
105-
weighted &&
104+
isWeighted &&
106105
<text className={styles.weight} x={nodeRadius + nodeWeightGap}>{this.toString(weight)}</text>
107106
}
108107
</g>

src/frontend/core/tracerManager.jsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class TracerManager {
1212
this.started = false;
1313
this.lineIndicator = null;
1414
this.file = { name: '', content: '', contributors: [] };
15-
this.jsWorker = null;
1615
this.reset();
1716
}
1817

@@ -84,7 +83,7 @@ class TracerManager {
8483
if (this.onChangeRenderers) this.onChangeRenderers(this.renderers);
8584
}
8685

87-
addTracer(className, tracerKey, title, options) {
86+
addTracer(className, tracerKey, title) {
8887
const [DataClass, RendererClass] = {
8988
Tracer: [Data, Renderer],
9089
LogTracer: [LogData, LogRenderer],
@@ -93,7 +92,7 @@ class TracerManager {
9392
ChartTracer: [ChartData, ChartRenderer],
9493
GraphTracer: [GraphData, GraphRenderer],
9594
}[className];
96-
const data = new DataClass(options);
95+
const data = new DataClass();
9796
this.datas[tracerKey] = data;
9897
const renderer = (
9998
<RendererClass key={tracerKey} title={title} data={data} wsProps={{ fixed: true }} />
@@ -108,8 +107,8 @@ class TracerManager {
108107
const { tracerKey, method, args } = trace;
109108
try {
110109
if (method === 'construct') {
111-
const [className, title, options] = args;
112-
this.addTracer(className, tracerKey, title, options);
110+
const [className, title] = args;
111+
this.addTracer(className, tracerKey, title);
113112
return true;
114113
} else {
115114
const data = this.datas[tracerKey];

0 commit comments

Comments
 (0)