Commit eeb995f6 authored by Rodrigo Tapia-McClung's avatar Rodrigo Tapia-McClung

Only update chart on month change

parent 93da8952
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* January 2021 * January 2021
*/ */
/* globals map, userFiles, userDates, indicators, indicatorVars, indicatorsNames */ /* globals map, userFiles, userDates, indicators, indicatorVars, indicatorsNames, updateBarChart, barChartData */
/* exported makeIndicatorGraph, getData, updateData, getDataInSelection */ /* exported makeIndicatorGraph, getData, updateData, getDataInSelection */
let mainTextColor = getComputedStyle(document.body).getPropertyValue('--main-text-color'); let mainTextColor = getComputedStyle(document.body).getPropertyValue('--main-text-color');
...@@ -846,21 +846,21 @@ am4core.ready(function() { ...@@ -846,21 +846,21 @@ am4core.ready(function() {
var range_lluvInv = categoryAxis.axisRanges.create(); var range_lluvInv = categoryAxis.axisRanges.create();
range_lluvInv.category = "December"; range_lluvInv.category = "December";
range_lluvInv.endcategory = "January";; range_lluvInv.endcategory = "January";
range_lluvInv.axisFill.fill = am4core.color("#E1DBC8"); range_lluvInv.axisFill.fill = am4core.color("#E1DBC8");
range_lluvInv.axisFill.fillOpacity = 0.4; range_lluvInv.axisFill.fillOpacity = 0.4;
range_lluvInv.grid.strokeOpacity = 0; range_lluvInv.grid.strokeOpacity = 0;
var range_lluvInv_1 = categoryAxis.axisRanges.create(); var range_lluvInv_1 = categoryAxis.axisRanges.create();
range_lluvInv_1.category = "January"; range_lluvInv_1.category = "January";
range_lluvInv_1.endcategory = "February";; range_lluvInv_1.endcategory = "February";
range_lluvInv_1.axisFill.fill = am4core.color("#E1DBC8"); range_lluvInv_1.axisFill.fill = am4core.color("#E1DBC8");
range_lluvInv_1.axisFill.fillOpacity = 0.4; range_lluvInv_1.axisFill.fillOpacity = 0.4;
range_lluvInv_1.grid.strokeOpacity = 0; range_lluvInv_1.grid.strokeOpacity = 0;
var range_lluvInv_2 = categoryAxis.axisRanges.create(); var range_lluvInv_2 = categoryAxis.axisRanges.create();
range_lluvInv_2.category = "February"; range_lluvInv_2.category = "February";
range_lluvInv_2.endcategory = "March";; range_lluvInv_2.endcategory = "March";
range_lluvInv_2.axisFill.fill = am4core.color("#E1DBC8"); range_lluvInv_2.axisFill.fill = am4core.color("#E1DBC8");
range_lluvInv_2.axisFill.fillOpacity = 0.4; range_lluvInv_2.axisFill.fillOpacity = 0.4;
range_lluvInv_2.grid.strokeOpacity = 0; range_lluvInv_2.grid.strokeOpacity = 0;
...@@ -1203,6 +1203,7 @@ am4core.ready(function() { ...@@ -1203,6 +1203,7 @@ am4core.ready(function() {
series3.strokeWidth = 2; series3.strokeWidth = 2;
chart.cursor = new am4charts.XYCursor(); chart.cursor = new am4charts.XYCursor();
chart.snapToSeries = series2;
chart.cursor.xAxis = dateAxis; chart.cursor.xAxis = dateAxis;
chart.scrollbarX = new am4core.Scrollbar(); chart.scrollbarX = new am4core.Scrollbar();
chart.scrollbarX.minHeight = 1; chart.scrollbarX.minHeight = 1;
...@@ -1293,8 +1294,13 @@ am4core.ready(function() { ...@@ -1293,8 +1294,13 @@ am4core.ready(function() {
/* Set up cursor behavior */ /* Set up cursor behavior */
let previousDate = "";
chart.cursor.events.on("cursorpositionchanged", function(ev) { chart.cursor.events.on("cursorpositionchanged", function(ev) {
let xAxis = ev.target.chart.xAxes.getIndex(0); let xAxis = ev.target.chart.xAxes.getIndex(0);
/*let axis = dateAxis.positionToDate(dateAxis.toAxisPosition(ev.target.xPosition)),
currentYear = axis.getFullYear().toString(),
currentMonth = axis.getMonth().toString();
console.log(currentYear, currentMonth)*/
let yy = xAxis.positionToDate(xAxis.toAxisPosition(ev.target.xPosition)).getFullYear().toString(); let yy = xAxis.positionToDate(xAxis.toAxisPosition(ev.target.xPosition)).getFullYear().toString();
let mm = xAxis.positionToDate(xAxis.toAxisPosition(ev.target.xPosition)).getMonth().toString(); let mm = xAxis.positionToDate(xAxis.toAxisPosition(ev.target.xPosition)).getMonth().toString();
let month = 0, let month = 0,
...@@ -1304,9 +1310,12 @@ am4core.ready(function() { ...@@ -1304,9 +1310,12 @@ am4core.ready(function() {
month = parseInt(mm) + 1; month = parseInt(mm) + 1;
month.toString(); month.toString();
} }
filterDate = new Date(`${yy}-${month}-01T00:00:00`); let filterDate = new Date(`${yy}-${month}-01T00:00:00`);
// only update chart when dates in cursor change month
if (filterDate.valueOf() != previousDate.valueOf()) {
previousDate = filterDate;
updateBarChart(filterDate, barChartData); updateBarChart(filterDate, barChartData);
}
}) })
/* popChart.cursor = new am4charts.XYCursor(); /* popChart.cursor = new am4charts.XYCursor();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment