|
378 | 378 | select.style.height = y4 - y3 + 'px'; |
379 | 379 | } |
380 | 380 |
|
381 | | - function getDataPoints(areaBoungingBox, numberOfRows){ |
| 381 | + function getDataPoints(areaBoungingBox, minDate, maxDate, dateFormat){ |
| 382 | + let dateKey = 'months'; |
| 383 | + switch(dateFormat){ |
| 384 | + case '%Y': |
| 385 | + dateKey = 'years'; |
| 386 | + break; |
| 387 | + case '%Y-%m': |
| 388 | + break; |
| 389 | + case '%Y-%m-%d': |
| 390 | + dateKey = 'days'; |
| 391 | + break; |
| 392 | + } |
| 393 | + let numberOfRows = getNumberOfRows(minDate, maxDate, dateFormat); |
382 | 394 | let onePoint = areaBoungingBox.width/numberOfRows; |
383 | 395 | let points = []; |
384 | 396 | for (var row = 0; row < numberOfRows; row++){ |
385 | | - points[row] = {left: (onePoint*row)+areaBoungingBox.left, width: onePoint} |
| 397 | + let min = moment(minDate).add(row, dateKey); |
| 398 | + points[row] = {left: (onePoint*row)+areaBoungingBox.left, width: onePoint, date: min, dateFormatted: min.format('YYYY-MM-DD')} |
| 399 | + } |
| 400 | + return points; |
| 401 | + } |
| 402 | +
|
| 403 | + function getNumberOfRows(minDate, maxDate, dateFormat){ |
| 404 | + switch(dateFormat){ |
| 405 | + case '%Y': |
| 406 | + return maxDate.endOf('years').diff(minDate, 'years')+1; |
| 407 | + break; |
| 408 | + case '%Y-%m': |
| 409 | + return maxDate.endOf('months').diff(minDate, 'months')+1; |
| 410 | + break; |
| 411 | + case '%Y-%m-%d': |
| 412 | + default: |
| 413 | + return maxDate.endOf('days').diff(minDate, 'days')+1; |
386 | 414 | } |
387 | | - return points |
388 | 415 | } |
389 | 416 |
|
390 | 417 | function selectPoints() { |
391 | | - let data = google.visualization.arrayToDataTable(it.prepareChartData(it.context.vm.result, it.options)); |
| 418 | + let prepareChartData = it.prepareChartData(it.context.vm.result, it.options); |
392 | 419 | let xx1 = x3 - graph.getBoundingClientRect().left + parseInt(graph.getAttribute('x')); |
393 | 420 | let xx2 = x4 - graph.getBoundingClientRect().left + parseInt(graph.getAttribute('x')); |
394 | 421 | let selection = []; |
395 | | - let dataPoints = getDataPoints(chartLayout.getChartAreaBoundingBox(), data.getNumberOfRows()); |
396 | | - for (var row = 0; row < data.getNumberOfRows(); row++) { |
| 422 | + let dataPoints = getDataPoints( |
| 423 | + chartLayout.getChartAreaBoundingBox(), |
| 424 | + moment(_.minBy(prepareChartData.slice(1), function(pcd){return pcd[0].v})[0].v), |
| 425 | + moment(_.maxBy(prepareChartData.slice(1), function(pcd){return pcd[0].v})[0].v), |
| 426 | + it.context.query.variables.dateFormat |
| 427 | + ); |
| 428 | + for (var row = 0; row < dataPoints.length; row++) { |
397 | 429 | let point = dataPoints[row]; |
398 | 430 | if ((point.left >= (xx1 - point.width)) && ((point.left + point.width) <= (xx2 + point.width))){ |
399 | | - selection.push(row); |
| 431 | + selection.push(point); |
400 | 432 | } |
401 | 433 | } |
402 | 434 | if(selection.length>0){ |
403 | | - // console.log(moment(data.getValue(selection[0], 0)).format('YYYY-MM-DD')); |
404 | | - // console.log(it.setTill(data.getValue(selection[selection.length-1], 0), it.context.query.variables.dateFormat)); |
405 | | - // it.context.is_request = true; |
406 | 435 | if (Array.isArray(it.historyRequests)){ |
407 | 436 | it.historyRequests.push(it.context.query.variables); |
408 | 437 | }else{ |
409 | 438 | it.historyRequests = [it.context.query.variables]; |
410 | 439 | } |
411 | 440 | it.hasInnerRequest = true; |
412 | | - it.context.query.request({from: moment(data.getValue(selection[0], 0)).format('YYYY-MM-DD'), till: it.setTill(data.getValue(selection[selection.length-1], 0), it.context.query.variables.dateFormat)}, function (data, his) { |
413 | | - // it.context.is_request = false; |
| 441 | + it.context.query.request({from: selection[0].date.format('YYYY-MM-DD'), till: it.setTill(selection[selection.length-1].date, it.context.query.variables.dateFormat)}, function (data, his) { |
414 | 442 | it.hasInnerRequest = true; |
415 | 443 | }); |
416 | 444 | } |
|
0 commit comments