Skip to content

Commit 2cfa27f

Browse files
hokolomoporrahir
authored andcommitted
[IMP] chart: add mouseup event to listened events
To detect a middle mouse click on a chart, we have to use the `mouseup` event, the `click` event is not triggered with middle mouse button. Note: ChartJS `onClick` is called at both the `click` and `mouseup` events, sso we have to be careful in the `onClick` handlers. closes #6076 Task: 4636147 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent e8d281f commit 2cfa27f

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

src/helpers/figures/charts/chart_ui_common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const CHART_COMMON_OPTIONS: ChartOptions = {
2121
},
2222
},
2323
animation: false,
24+
events: ["mousemove", "mouseout", "click", "touchstart", "touchmove", "mouseup"],
2425
};
2526

2627
export function truncateLabel(label: string | undefined): string {

src/helpers/figures/charts/runtime/chartjs_legend.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ export const INTERACTIVE_LEGEND_CONFIG = {
213213
target.style.cursor = "default";
214214
},
215215
onClick: (event, legendItem, legend) => {
216+
if (event.type !== "click") {
217+
return;
218+
}
216219
const index = legendItem.datasetIndex;
217220
if (!legend.legendItems || index === undefined) {
218221
return;

tests/figures/chart/__snapshots__/chart_plugin.test.ts.snap

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ exports[`Linear/Time charts font color is white with a dark background color 1`]
4747
"hitRadius": 15,
4848
},
4949
},
50+
"events": [
51+
"mousemove",
52+
"mouseout",
53+
"click",
54+
"touchstart",
55+
"touchmove",
56+
"mouseup",
57+
],
5058
"layout": {
5159
"padding": {
5260
"bottom": 10,
@@ -184,6 +192,14 @@ exports[`Linear/Time charts snapshot test of chartJS configuration for date char
184192
"hitRadius": 15,
185193
},
186194
},
195+
"events": [
196+
"mousemove",
197+
"mouseout",
198+
"click",
199+
"touchstart",
200+
"touchmove",
201+
"mouseup",
202+
],
187203
"layout": {
188204
"padding": {
189205
"bottom": 10,
@@ -328,6 +344,14 @@ exports[`Linear/Time charts snapshot test of chartJS configuration for linear ch
328344
"hitRadius": 15,
329345
},
330346
},
347+
"events": [
348+
"mousemove",
349+
"mouseout",
350+
"click",
351+
"touchstart",
352+
"touchmove",
353+
"mouseup",
354+
],
331355
"layout": {
332356
"padding": {
333357
"bottom": 10,
@@ -446,6 +470,14 @@ exports[`datasource tests create a chart with stacked bar 1`] = `
446470
"hitRadius": 15,
447471
},
448472
},
473+
"events": [
474+
"mousemove",
475+
"mouseout",
476+
"click",
477+
"touchstart",
478+
"touchmove",
479+
"mouseup",
480+
],
449481
"indexAxis": "x",
450482
"layout": {
451483
"padding": {
@@ -564,6 +596,14 @@ exports[`datasource tests create chart with a dataset of one cell (no title) 1`]
564596
"hitRadius": 15,
565597
},
566598
},
599+
"events": [
600+
"mousemove",
601+
"mouseout",
602+
"click",
603+
"touchstart",
604+
"touchmove",
605+
"mouseup",
606+
],
567607
"layout": {
568608
"padding": {
569609
"bottom": 10,
@@ -700,6 +740,14 @@ exports[`datasource tests create chart with column datasets 1`] = `
700740
"hitRadius": 15,
701741
},
702742
},
743+
"events": [
744+
"mousemove",
745+
"mouseout",
746+
"click",
747+
"touchstart",
748+
"touchmove",
749+
"mouseup",
750+
],
703751
"layout": {
704752
"padding": {
705753
"bottom": 10,
@@ -836,6 +884,14 @@ exports[`datasource tests create chart with column datasets with category title
836884
"hitRadius": 15,
837885
},
838886
},
887+
"events": [
888+
"mousemove",
889+
"mouseout",
890+
"click",
891+
"touchstart",
892+
"touchmove",
893+
"mouseup",
894+
],
839895
"layout": {
840896
"padding": {
841897
"bottom": 10,
@@ -972,6 +1028,14 @@ exports[`datasource tests create chart with column datasets without series title
9721028
"hitRadius": 15,
9731029
},
9741030
},
1031+
"events": [
1032+
"mousemove",
1033+
"mouseout",
1034+
"click",
1035+
"touchstart",
1036+
"touchmove",
1037+
"mouseup",
1038+
],
9751039
"layout": {
9761040
"padding": {
9771041
"bottom": 10,
@@ -1091,6 +1155,14 @@ exports[`datasource tests create chart with only the dataset title (no data) 1`]
10911155
"hitRadius": 15,
10921156
},
10931157
},
1158+
"events": [
1159+
"mousemove",
1160+
"mouseout",
1161+
"click",
1162+
"touchstart",
1163+
"touchmove",
1164+
"mouseup",
1165+
],
10941166
"layout": {
10951167
"padding": {
10961168
"bottom": 10,
@@ -1227,6 +1299,14 @@ exports[`datasource tests create chart with rectangle dataset 1`] = `
12271299
"hitRadius": 15,
12281300
},
12291301
},
1302+
"events": [
1303+
"mousemove",
1304+
"mouseout",
1305+
"click",
1306+
"touchstart",
1307+
"touchmove",
1308+
"mouseup",
1309+
],
12301310
"layout": {
12311311
"padding": {
12321312
"bottom": 10,
@@ -1363,6 +1443,14 @@ exports[`datasource tests create chart with row datasets 1`] = `
13631443
"hitRadius": 15,
13641444
},
13651445
},
1446+
"events": [
1447+
"mousemove",
1448+
"mouseout",
1449+
"click",
1450+
"touchstart",
1451+
"touchmove",
1452+
"mouseup",
1453+
],
13661454
"layout": {
13671455
"padding": {
13681456
"bottom": 10,
@@ -1499,6 +1587,14 @@ exports[`datasource tests create chart with row datasets with category title 1`]
14991587
"hitRadius": 15,
15001588
},
15011589
},
1590+
"events": [
1591+
"mousemove",
1592+
"mouseout",
1593+
"click",
1594+
"touchstart",
1595+
"touchmove",
1596+
"mouseup",
1597+
],
15021598
"layout": {
15031599
"padding": {
15041600
"bottom": 10,
@@ -1635,6 +1731,14 @@ exports[`datasource tests create chart with row datasets without series title 1`
16351731
"hitRadius": 15,
16361732
},
16371733
},
1734+
"events": [
1735+
"mousemove",
1736+
"mouseout",
1737+
"click",
1738+
"touchstart",
1739+
"touchmove",
1740+
"mouseup",
1741+
],
16381742
"layout": {
16391743
"padding": {
16401744
"bottom": 10,

0 commit comments

Comments
 (0)