Skip to content

Commit c7ed18b

Browse files
Add tooltip to Wincher ranking history chart
1 parent bc22b0a commit c7ed18b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

packages/js/src/components/WincherRankingHistoryChart.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* External dependencies */
22
import { Line } from "react-chartjs-2";
3-
import { CategoryScale, Chart, LineController, LineElement, LinearScale, PointElement, TimeScale, Colors, Legend } from "chart.js";
3+
import { CategoryScale, Chart, LineController, LineElement, LinearScale, PointElement, TimeScale, Colors, Legend, Tooltip } from "chart.js";
44
import "chartjs-adapter-moment";
55
import PropTypes from "prop-types";
66
import { noop } from "lodash";
7+
import moment from "moment";
78

8-
Chart.register( CategoryScale, LineController, LineElement, PointElement, LinearScale, TimeScale, Colors, Legend );
9+
Chart.register( CategoryScale, LineController, LineElement, PointElement, LinearScale, TimeScale, Colors, Legend, Tooltip );
910

1011
/**
1112
* Renders the Wincher ranking history chart.
@@ -26,9 +27,10 @@ export default function WincherRankingHistoryChart( { datasets, isChartShown } )
2627
y: value,
2728
} ) ),
2829
lineTension: 0,
29-
pointRadius: 0,
30-
pointHoverRadius: 0,
30+
pointRadius: 1,
31+
pointHoverRadius: 4,
3132
borderWidth: 2,
33+
pointHitRadius: 6,
3234
} ) );
3335

3436
return (
@@ -50,6 +52,20 @@ export default function WincherRankingHistoryChart( { datasets, isChartShown } )
5052
},
5153
onClick: noop,
5254
},
55+
tooltip: {
56+
enabled: true,
57+
callbacks: {
58+
title: ( x ) => moment( x[ 0 ].raw.x ).utc().format( "YYYY-MM-DD" ),
59+
},
60+
titleAlign: "center",
61+
intersect: false,
62+
mode: "point",
63+
position: "nearest",
64+
usePointStyle: true,
65+
boxHeight: 7,
66+
boxWidth: 7,
67+
boxPadding: 2,
68+
},
5369
},
5470
scales: {
5571
x: {

0 commit comments

Comments
 (0)