Skip to content

Commit 5653ae5

Browse files
committed
chore: update desc
1 parent 66712f9 commit 5653ae5

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

src/components/CompleteHistogramI.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export default {
1111
return {}
1212
},
1313
mounted () {
14-
// 得到 SVG 画布
1514
let marge = { top: 60, bottom: 60, left: 60, right: 60 }
1615
let svg = d3.select('svg')
1716
let width = svg.attr('width')
@@ -21,7 +20,8 @@ export default {
2120
2221
let dataset = [10, 20, 30, 23, 13, 40, 27, 35, 20]
2322
24-
// x , y 方向绘制坐标轴
23+
// Draw the axis in the X, Y direction
24+
// x , y 方向绘制坐标轴
2525
let xScale = d3.scaleBand()
2626
.domain(d3.range(dataset.length))
2727
.rangeRound([0, width - marge.left - marge.right])
@@ -40,12 +40,14 @@ export default {
4040
.attr('transform', 'translate(0, 0)')
4141
.call(yAxis)
4242
43+
// Create gourps for rectangles and corresponding text
4344
// 给矩形和对应文字创建分组
4445
let gs = g.selectAll('.rect')
4546
.data(dataset)
4647
.enter()
4748
.append('g')
4849
50+
// draw rectangle
4951
// 绘制矩形
5052
let rectPadding = 20
5153
gs.append('rect')
@@ -62,6 +64,8 @@ export default {
6264
return height - marge.top - marge.bottom - yScale(d)
6365
})
6466
.attr('fill', 'lightblue')
67+
68+
// Draw text
6569
// 绘制文字
6670
gs.append('text')
6771
.attr('x', function (d, i) {

src/components/CompleteHistogramII.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export default {
1111
return {}
1212
},
1313
mounted () {
14-
// 得到 SVG 画布
1514
let marge = { top: 60, bottom: 60, left: 60, right: 60 }
1615
let svg = d3.select('svg')
1716
let width = svg.attr('width')
@@ -21,6 +20,7 @@ export default {
2120
2221
let dataset = [10, 20, 30, 23, 13, 40, 27, 35, 20]
2322
23+
// Draw the axis in the X, Y direction
2424
// x , y 方向绘制坐标轴
2525
let xScale = d3.scaleBand()
2626
.domain(d3.range(dataset.length))
@@ -40,19 +40,22 @@ export default {
4040
.attr('transform', 'translate(0, 0)')
4141
.call(yAxis)
4242
43+
// Create gourps for rectangles and corresponding text
4344
// 给矩形和对应文字创建分组
4445
let gs = g.selectAll('.rect')
4546
.data(dataset)
4647
.enter()
4748
.append('g')
4849
50+
// draw rectangle
4951
// 绘制矩形
5052
let rectPadding = 20
5153
gs.append('rect')
5254
.attr('x', function (d, i) {
5355
return xScale(i) + rectPadding / 2
5456
})
5557
.attr('y', function () {
58+
// init state
5659
// 初始状态
5760
let min = yScale.domain()[0]
5861
return yScale(min)
@@ -61,6 +64,7 @@ export default {
6164
return xScale.step() - rectPadding
6265
})
6366
.attr('height', function () {
67+
// init state
6468
// 初始状态
6569
return 0
6670
})
@@ -72,13 +76,16 @@ export default {
7276
})
7377
// .ease(d3.easeElasticInout)
7478
.attr('y', function (d) {
79+
// Return to the final state
7580
// 回到最终状态
7681
return yScale(d)
7782
})
7883
.attr('height', function (d) {
84+
// Return to the final state
7985
// 回到最终状态
8086
return height - marge.top - marge.bottom - yScale(d)
8187
})
88+
// Draw text
8289
// 绘制文字
8390
gs.append('text')
8491
.attr('x', function (d, i) {

src/components/CompleteHistogramIII.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ export default {
3232
g.append('g')
3333
.attr('transform', 'trnslate(0, 0)')
3434
.call(yAxis)
35+
36+
// Draw rectangle and text
3537
// 绘制矩形和文字
3638
let gs = g.selectAll('.rect')
3739
.data(dataset)
3840
.enter()
3941
.append('g')
4042
43+
// Draw rectangle
4144
// 绘制矩形
4245
let rectPadding = 20
4346
gs.append('rect')
@@ -67,6 +70,8 @@ export default {
6770
.duration(1000)
6871
.attr('fill', 'lightblue')
6972
})
73+
74+
// Draw text
7075
// 绘制文字
7176
gs.append('text')
7277
.attr('x', function (d, i) {

src/components/ForceDirectedGraph.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default {
1818
let g = svg.append('g')
1919
.attr('transform', 'translate(' + marge.top + ',' + marge.left + ')')
2020
21-
// 准备数据
21+
// Node Dataset
2222
// 节点集
2323
let nodes = [
2424
{ name: '湖南邵阳' },
@@ -31,6 +31,7 @@ export default {
3131
{ name: '小明' },
3232
{ name: '组长' }
3333
]
34+
// Side Dataset
3435
// 边集
3536
let edges = [
3637
{ source: 0, target: 4, relation: '籍贯', value: 1.3 },
@@ -44,31 +45,35 @@ export default {
4445
{ source: 6, target: 7, relation: '朋友', value: 0.7 },
4546
{ source: 6, target: 8, relation: '职责', value: 2 }
4647
]
48+
// Set a color scale
4749
// 设置一个颜色比例尺
4850
let colorScale = d3.scaleOrdinal()
4951
.domain(d3.range(nodes.length))
5052
.range(d3.schemeCategory10)
53+
// Create a new force guide diagram
5154
// 新建一个力导向图
5255
let forceSimulation = d3.forceSimulation()
5356
.force('link', d3.forceLink())
5457
.force('charge', d3.forceManyBody())
5558
.force('center', d3.forceCenter())
59+
// Generate node data
5660
// 生成节点数据
5761
forceSimulation.nodes(nodes)
5862
.on('tick', ticked)
63+
// Generate side data
5964
// 生成边数据
6065
forceSimulation.force('link')
6166
.links(edges)
62-
.distance(function (d) { // 每一边的长度
67+
.distance(function (d) { // side length / 每一边的长度
6368
return d.value * 100
6469
})
70+
// Set drawing center location
6571
// 设置图形中心位置
6672
forceSimulation.force('center')
6773
.x(width / 2)
6874
.y(height / 2)
69-
// // 顶点集,边集
70-
// console.log(nodes)
71-
// console.log(edges)
75+
76+
// Draw side
7277
// 绘制边
7378
let links = g.append('g')
7479
.selectAll('line')
@@ -79,6 +84,7 @@ export default {
7984
return colorScale(i)
8085
})
8186
.attr('stroke-width', 1)
87+
// Text on side
8288
// 边上的文字
8389
let linksText = g.append('g')
8490
.selectAll('text')
@@ -88,6 +94,7 @@ export default {
8894
.text(function (d) {
8995
return d.relation
9096
})
97+
// Create group
9198
// 创建分组
9299
let gs = g.selectAll('.circleText')
93100
.data(nodes)
@@ -103,13 +110,15 @@ export default {
103110
.on('drag', dragged)
104111
.on('end', ended)
105112
)
113+
// Draw node
106114
// 绘制节点
107115
gs.append('circle')
108116
.attr('r', 10)
109117
.attr('fill', function (d, i) {
110118
return colorScale(i)
111119
})
112-
// 文字
120+
// Draw text
121+
// 绘制文字
113122
gs.append('text')
114123
.attr('x', -10)
115124
.attr('y', -20)
@@ -133,7 +142,7 @@ export default {
133142
// drag
134143
function started (d) {
135144
if (!d3.event.active) {
136-
forceSimulation.alphaTarget(0.8).restart() // 设置衰减系数,对节点位置移动过程的模拟,数值越高移动越快,数值范围[0, 1]
145+
forceSimulation.alphaTarget(0.8).restart() // Set the attenuation coefficient to simulate the node position movement process. The higher the value, the faster the movement. The value range is [0, 1] // 设置衰减系数,对节点位置移动过程的模拟,数值越高移动越快,数值范围[0, 1]
137146
}
138147
d.fx = d.x
139148
d.fy = d.y

0 commit comments

Comments
 (0)