11<script >
22import _ from " lodash" ;
33import {
4- endOfMonth , endOfToday , endOfWeek , endOfYear , format , subDays , subMonths ,
5- subWeeks , subYears
4+ endOfDay , endOfMonth , endOfToday , endOfWeek , endOfYear ,
5+ format , subDays , subMonths , subWeeks , subYears
66} from " date-fns" ;
77import { Line , mixins } from " vue-chartjs" ;
88import ChartDataLabels from " chartjs-plugin-datalabels" ;
@@ -120,6 +120,7 @@ export default {
120120
121121 // Initialize the chart.
122122 this .renderChart (this .chartData , this .options );
123+ this .addMouseEventListener ();
123124 },
124125
125126 activated () {
@@ -133,6 +134,7 @@ export default {
133134 return ;
134135
135136 let dateFormat = " yyyy. MMM. dd" ;
137+ this .filterDateFormat = " yyyy-MM-dd" ;
136138
137139 if (this .resolution === " days" ) {
138140 const today = endOfToday ();
@@ -150,13 +152,15 @@ export default {
150152 subMonths (endOfCurrentMonth, i));
151153
152154 dateFormat = " yyyy. MMM" ;
155+ this .filterDateFormat = " yyyy-MM" ;
153156 }
154157 else if (this .resolution === " years" ) {
155158 const endOfCurrentYear = endOfYear (new Date ());
156159 this .dates = [ ... new Array (interval).keys () ].map (i =>
157160 subYears (endOfCurrentYear, i));
158161
159162 dateFormat = " yyyy" ;
163+ this .filterDateFormat = " yyyy" ;
160164 }
161165
162166 this .chartData .labels = [ ... this .dates ].reverse ().map ((d , idx ) => {
@@ -198,7 +202,6 @@ export default {
198202 this .chartData = { ... this .chartData };
199203 });
200204 },
201-
202205 fetchOutstandingReports (date ) {
203206 const { runIds , reportFilter } = this .getStatisticsFilters ();
204207
@@ -212,6 +215,50 @@ export default {
212215 ccService .getClient ().getSeverityCounts (runIds, rFilter, cmpData,
213216 handleThriftError (res => resolve (res)));
214217 });
218+ },
219+ addMouseEventListener () {
220+ const canvas = this .$refs .canvas ;
221+ const chartInstance = this .$data ._chart ;
222+
223+ canvas .addEventListener (" click" , event => {
224+ const points = chartInstance .getElementAtEvent (event );
225+ if (points .length > 0 ) {
226+ const firstPoint = points[0 ];
227+ const datasetIndex = firstPoint ._datasetIndex ;
228+ this .runName = this .$router .currentRoute .query [" run" ];
229+ this .severity = chartInstance .data .datasets [datasetIndex].label ;
230+ const date = this .dates .reverse ()[firstPoint ._index ];
231+ const formattedDate = new Date (format (date, this .filterDateFormat ));
232+ if (this .resolution === " days" ) {
233+ this .reportsDate = endOfDay (formattedDate);
234+ } else if (this .resolution === " weeks" ) {
235+ this .reportsDate = endOfWeek (formattedDate);
236+ } else if (this .resolution === " months" ) {
237+ this .reportsDate = endOfMonth (formattedDate);
238+ } else if (this .resolution === " years" ) {
239+ this .reportsDate = endOfYear (formattedDate);
240+ }
241+ this .$router .push ({
242+ name: " reports" ,
243+ query: {
244+ " run" : this .runName ,
245+ " is-unique" : " off" ,
246+ " diff-type" : " New" ,
247+ " open-reports-date" : ` ${ this .dateTimeToStr (this .reportsDate )} ` ,
248+ " severity" : this .severity
249+ }
250+ });
251+ }
252+ });
253+
254+ canvas .addEventListener (" mousemove" , event => {
255+ const points = chartInstance .getElementAtEvent (event );
256+ if (points .length > 0 ) {
257+ canvas .style .cursor = " pointer" ;
258+ } else {
259+ canvas .style .cursor = " default" ;
260+ }
261+ });
215262 }
216263 }
217264};
0 commit comments