Skip to content

Commit d293f24

Browse files
committed
Sync charts on zoom/pan events
1 parent 630c2dd commit d293f24

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

web_src/js/components/RepoContributors.vue

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ ChartJS.register(
7777
const sfc = {
7878
components: { Line },
7979
data: () => ({
80-
data: {
81-
},
80+
data: {},
8281
8382
masterChartData: window.config.pageData.repoContributorsCommitStats || [],
8483
type: window.config.pageData.contributionType,
@@ -98,6 +97,19 @@ const sfc = {
9897
enabled: true,
9998
mode: "x",
10099
threshold: 20,
100+
101+
onPan: function (event) {
102+
var minVal = event.chart.options.scales.x.min;
103+
var maxVal = event.chart.options.scales.x.max;
104+
105+
Object.values(ChartJS.instances).forEach(function (instance) {
106+
if (instance !== event.chart){
107+
instance.options.scales.x.min = minVal;
108+
instance.options.scales.x.max = maxVal;
109+
instance.update();
110+
}
111+
});
112+
},
101113
},
102114
limits: {
103115
x: {
@@ -114,6 +126,20 @@ const sfc = {
114126
enabled: true,
115127
},
116128
mode: "x",
129+
130+
onZoomComplete: function (event) {
131+
var minVal = event.chart.options.scales.x.min;
132+
var maxVal = event.chart.options.scales.x.max;
133+
134+
Object.values(ChartJS.instances).forEach(function (instance) {
135+
if (instance !== event.chart){
136+
instance.options.scales.x.min = minVal;
137+
instance.options.scales.x.max = maxVal;
138+
instance.update();
139+
}
140+
});
141+
},
142+
117143
},
118144
},
119145
},
@@ -130,7 +156,7 @@ const sfc = {
130156
max: this.maxMainGraph(),
131157
},
132158
},
133-
}
159+
};
134160
},
135161
mainGraphData() {
136162
return {
@@ -162,12 +188,14 @@ const sfc = {
162188
},
163189
methods: {
164190
maxMainGraph() {
165-
const maxValue = Math.max(...this.masterChartData[""].weeks.map(o => o[this.type]))
166-
const [cooefficient, exp] = maxValue.toExponential().split('e')
191+
const maxValue = Math.max(
192+
...this.masterChartData[""].weeks.map((o) => o[this.type])
193+
);
194+
const [cooefficient, exp] = maxValue.toExponential().split("e");
167195
if (Number(cooefficient) % 1 == 0) {
168-
return maxValue
196+
return maxValue;
169197
}
170-
return (1 - Number(cooefficient) % 1) * 10 ** Number(exp) + maxValue
198+
return (1 - (Number(cooefficient) % 1)) * 10 ** Number(exp) + maxValue;
171199
},
172200
additions(data) {
173201
return Object.values(data).reduce((acc, item) => {

0 commit comments

Comments
 (0)