Skip to content

Commit be8b65d

Browse files
committed
made the piechart more responsive
1 parent 4a690b4 commit be8b65d

File tree

4 files changed

+42
-54
lines changed

4 files changed

+42
-54
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"dependencies": {
1212
"axios": "^0.19.0",
1313
"braces": "^3.0.2",
14-
"core-js": "^3.4.5",
14+
"core-js": "^3.4.7",
1515
"d3": "^5.14.2",
1616
"moment": "^2.24.0",
1717
"vue": "^2.6.10",
1818
"vue-moment": "^4.0.0",
1919
"vue-resize": "^0.4.5",
2020
"vue-router": "^3.1.3",
21-
"vuetify": "^2.1.12",
21+
"vuetify": "^2.1.13",
2222
"vuex": "^3.1.2"
2323
},
2424
"devDependencies": {
@@ -34,7 +34,7 @@
3434
"babel-core": "7.0.0-bridge.0",
3535
"babel-eslint": "^10.0.3",
3636
"deepmerge": "^4.2.2",
37-
"eslint": "^6.7.1",
37+
"eslint": "^6.7.2",
3838
"eslint-plugin-prettier": "^3.1.1",
3939
"eslint-plugin-vue": "^6.0.1",
4040
"eslint-plugin-vuetify": "^1.0.0-beta.3",
@@ -44,6 +44,6 @@
4444
"sass-loader": "^8.0.0",
4545
"vue-cli-plugin-vuetify": "^2.0.2",
4646
"vue-template-compiler": "^2.6.10",
47-
"vuetify-loader": "^1.4.2"
47+
"vuetify-loader": "^1.4.3"
4848
}
4949
}

src/components/PieChart.vue

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
<script>
1010
import * as d3 from 'd3';
11-
import debounce from '../util/debounce';
1211
1312
export default {
1413
name: 'PieChart',
@@ -32,6 +31,8 @@ export default {
3231
},
3332
svg: null,
3433
svgSelection: null,
34+
chartWidth: 0,
35+
chartHeight: 0,
3536
}),
3637
3738
watch: {
@@ -51,18 +52,22 @@ export default {
5152
drawChart() {
5253
this.svgSelection = d3.select(this.svg);
5354
this.svgSelection.attr('width', this.width).attr('height', this.height);
54-
const chartWidth = this.width - (this.padding.left + this.padding.right);
55-
const chartHeight = this.height - (this.padding.top + this.padding.bottom);
55+
this.chartWidth = this.width - (this.padding.left + this.padding.right);
56+
this.chartHeight = this.height - (this.padding.top + this.padding.bottom);
5657
57-
this.chartLayer = this.svgSelection.append('g').attr('transform', `translate(${this.padding.left}, ${this.padding.top})`);
58+
this.chartLayer = this.svgSelection
59+
.append('g')
60+
.attr('transform', `translate(${this.padding.left}, ${this.padding.top})`);
5861
5962
this.arc = d3
6063
.arc()
61-
.outerRadius(chartHeight / 2)
62-
.innerRadius(chartHeight / 4)
64+
.outerRadius(this.chartHeight / 2)
65+
.innerRadius(this.chartHeight / 4)
6366
.padAngle(0.05);
6467
65-
this.pieG = this.chartLayer.append('g').attr('transform', `translate(${chartWidth / 2}, ${chartHeight / 2})`);
68+
this.pieG = this.chartLayer
69+
.append('g')
70+
.attr('transform', `translate(${this.chartWidth / 2}, ${this.chartHeight / 2})`);
6671
6772
this.updateChart(this.stats);
6873
},
@@ -83,16 +88,17 @@ export default {
8388
.attr('height', this.padding.top + this.height + this.padding.bottom)
8489
.attr('width', this.padding.left + this.width + this.padding.right);
8590
86-
debounce(function () {
87-
this.drawChart()
88-
}, 250);
91+
this.chartWidth = this.width - (this.padding.left + this.padding.right);
92+
this.chartHeight = this.height - (this.padding.top + this.padding.bottom);
93+
this.updateChart(this.stats);
8994
},
9095
9196
updateChart(stats) {
92-
d3.selectAll('path').remove();
93-
console.log(this.parentWidth());
97+
this.pieG = this.pieG.attr('transform', `translate(${this.chartWidth / 2}, ${this.chartHeight / 2})`);
9498
95-
const total = d3.sum(this.stats.map(stat => stat.value));
99+
d3.selectAll('path').remove();
100+
d3.selectAll('text').remove();
101+
// const total = d3.sum(this.stats.map(stat => stat.value));
96102
97103
const arcs = d3
98104
.pie()
@@ -103,13 +109,9 @@ export default {
103109
104110
block.select('path').attr('d', this.arc);
105111
106-
console.log(this.pieG.node());
107-
108112
this.pieG.append('span').attr('id', 'info');
109113
110-
const infoBlock = d3.select('#info');
111-
112-
console.log(infoBlock);
114+
// const infoBlock = d3.select('#info');
113115
114116
const newBlock = block.join('g').classed('arc', true);
115117

src/util/debounce.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

yarn.lock

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,11 +2959,16 @@ core-js@^2.4.0:
29592959
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.10.tgz#8a5b8391f8cc7013da703411ce5b585706300d7f"
29602960
integrity sha512-I39t74+4t+zau64EN1fE5v2W31Adtc/REhzWN+gWRRXg6WH5qAsZm62DHpQ1+Yhe4047T55jvzz7MUqF/dBBlA==
29612961

2962-
core-js@^3.4.3, core-js@^3.4.5:
2962+
core-js@^3.4.3:
29632963
version "3.4.5"
29642964
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.4.5.tgz#3dda65611d95699b5eb7742ea451ea052d37aa65"
29652965
integrity sha512-OuvejWH6vIaUo59Ndlh89purNm4DCIy/v3QoYlcGnn+PkYI8BhNHfCuAESrWX+ZPfq9JccVJ+XXgOMy77PJexg==
29662966

2967+
core-js@^3.4.7:
2968+
version "3.4.7"
2969+
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.4.7.tgz#57c35937da80fe494fbc3adcf9cf3dc00eb86b34"
2970+
integrity sha512-qaPVGw30J1wQ0GR3GvoPqlGf9GZfKKF4kFC7kiHlcsPTqH3txrs9crCp3ZiMAXuSenhz89Jnl4GZs/67S5VOSg==
2971+
29672972
[email protected], core-util-is@~1.0.0:
29682973
version "1.0.2"
29692974
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
@@ -4185,10 +4190,10 @@ eslint-visitor-keys@^1.0.0, eslint-visitor-keys@^1.1.0:
41854190
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-1.1.0.tgz#e2a82cea84ff246ad6fb57f9bde5b46621459ec2"
41864191
integrity sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A==
41874192

4188-
eslint@^6.7.1:
4189-
version "6.7.1"
4190-
resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.7.1.tgz#269ccccec3ef60ab32358a44d147ac209154b919"
4191-
integrity sha512-UWzBS79pNcsDSxgxbdjkmzn/B6BhsXMfUaOHnNwyE8nD+Q6pyT96ow2MccVayUTV4yMid4qLhMiQaywctRkBLA==
4193+
eslint@^6.7.2:
4194+
version "6.7.2"
4195+
resolved "https://registry.yarnpkg.com/eslint/-/eslint-6.7.2.tgz#c17707ca4ad7b2d8af986a33feba71e18a9fecd1"
4196+
integrity sha512-qMlSWJaCSxDFr8fBPvJM9kJwbazrhNcBU3+DszDW1OlEwKBBRWsJc7NJFelvwQpanHCR14cOLD41x8Eqvo3Nng==
41924197
dependencies:
41934198
"@babel/code-frame" "^7.0.0"
41944199
ajv "^6.10.0"
@@ -10589,17 +10594,17 @@ vue@^2.6.10:
1058910594
resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.10.tgz#a72b1a42a4d82a721ea438d1b6bf55e66195c637"
1059010595
integrity sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ==
1059110596

10592-
vuetify-loader@^1.4.2:
10593-
version "1.4.2"
10594-
resolved "https://registry.yarnpkg.com/vuetify-loader/-/vuetify-loader-1.4.2.tgz#0fefbca906de29939cd74f707c6bbc70bf1fc866"
10595-
integrity sha512-lRB2niiiMOtkPyRbZRGl7GyDXAvBtHBDIV3LKwrgJwdMRvZEYmNTqMM4IxR+oGXHPGBBV/apu0XmCq7Mqomzng==
10597+
vuetify-loader@^1.4.3:
10598+
version "1.4.3"
10599+
resolved "https://registry.yarnpkg.com/vuetify-loader/-/vuetify-loader-1.4.3.tgz#df1323c558be09890877e5fbe817b3a71a6c538d"
10600+
integrity sha512-fS0wRil682Ebsj2as+eruBoMPKaQYDhu/fDAndnTItzSY4RK4LOEIsssVL4vD6QY8dvUgoGL84SUQ6vGr777CA==
1059610601
dependencies:
1059710602
loader-utils "^1.2.0"
1059810603

10599-
vuetify@^2.1.12:
10600-
version "2.1.12"
10601-
resolved "https://registry.yarnpkg.com/vuetify/-/vuetify-2.1.12.tgz#7b02de32d7a169db468576ea5d5e8f60c603069a"
10602-
integrity sha512-xMaEX9pz/9bdV0jecuvINk5FD43bUkzfeLKfvrwBu0qroLTpLCdc7mZ7AURAxR5mVmgjqR9BFc7qRtQHA1Lq0Q==
10604+
vuetify@^2.1.13:
10605+
version "2.1.13"
10606+
resolved "https://registry.yarnpkg.com/vuetify/-/vuetify-2.1.13.tgz#58610027b8014c640510eb76e02c5a94e56bef04"
10607+
integrity sha512-wy7RfNmRW60sPNRxl0C7TwRcLRw2Yw+ofGlJTAcoQZnWDtDOriSq0p3Uk8X0jb6tzkeU5Ed0JY6zL0Rb0ZL3lw==
1060310608

1060410609
vuex@^3.1.2:
1060510610
version "3.1.2"

0 commit comments

Comments
 (0)