From 1abd4a8ac6bc04832ed8b4c729f669e307582408 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 18 Nov 2021 11:24:21 +0545 Subject: [PATCH] chart updated for consistency --- public/dist/scripts/app-all.js | 6 ++++-- public/dist/scripts/app.js | 6 ++++-- public/scripts/views/forms/chart.js | 20 +++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/public/dist/scripts/app-all.js b/public/dist/scripts/app-all.js index 9e285b79a..00061903d 100644 --- a/public/dist/scripts/app-all.js +++ b/public/dist/scripts/app-all.js @@ -3338,8 +3338,10 @@ button.addEventListener("click",function(){var clone=document.createElement(elem clone.innerHTML=template;clone.className=element.className;var input=clone.querySelector("input, select, textarea");view.render(clone);if(target){target.appendChild(clone);}else{button.parentNode.insertBefore(clone,button);} if(input){input.focus();} Array.prototype.slice.call(clone.querySelectorAll("[data-remove]")).map(function(obj){obj.addEventListener("click",function(){clone.parentNode.removeChild(clone);obj.scrollIntoView({behavior:"smooth"});});});Array.prototype.slice.call(clone.querySelectorAll("[data-up]")).map(function(obj){obj.addEventListener("click",function(){if(clone.previousElementSibling){clone.parentNode.insertBefore(clone,clone.previousElementSibling);obj.scrollIntoView({behavior:"smooth"});}});});Array.prototype.slice.call(clone.querySelectorAll("[data-down]")).map(function(obj){obj.addEventListener("click",function(){if(clone.nextElementSibling){clone.parentNode.insertBefore(clone.nextElementSibling,clone);obj.scrollIntoView({behavior:"smooth"});}});});});element.parentNode.insertBefore(button,element.nextSibling);element.parentNode.removeChild(element);button.form.addEventListener('reset',function(event){target.innerHTML='';if(first){button.click();}});if(first){button.click();}}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-add",repeat:false,controller:function(element,view,container,document){for(var i=0;ihighest){highest=data[x].value;} +config.data.datasets[i].data[x]=data[x].value;config.data.labels[x]=date.format(dateFormat,data[x].date);}} +if(highest==0){config.options.scales.y.ticks.stepSize=1;config.options.scales.y.max=ticksCount;}else{highest=Math.ceil(highest/ticksCount)*ticksCount;config.options.scales.y.ticks.stepSize=highest/ticksCount;config.options.scales.y.max=highest;} if(chart){chart.destroy();} else{} chart=new Chart(child.getContext("2d"),config);wrapper.dataset["canvas"]=true;} diff --git a/public/dist/scripts/app.js b/public/dist/scripts/app.js index 949075f91..eb8d29841 100644 --- a/public/dist/scripts/app.js +++ b/public/dist/scripts/app.js @@ -374,8 +374,10 @@ button.addEventListener("click",function(){var clone=document.createElement(elem clone.innerHTML=template;clone.className=element.className;var input=clone.querySelector("input, select, textarea");view.render(clone);if(target){target.appendChild(clone);}else{button.parentNode.insertBefore(clone,button);} if(input){input.focus();} Array.prototype.slice.call(clone.querySelectorAll("[data-remove]")).map(function(obj){obj.addEventListener("click",function(){clone.parentNode.removeChild(clone);obj.scrollIntoView({behavior:"smooth"});});});Array.prototype.slice.call(clone.querySelectorAll("[data-up]")).map(function(obj){obj.addEventListener("click",function(){if(clone.previousElementSibling){clone.parentNode.insertBefore(clone,clone.previousElementSibling);obj.scrollIntoView({behavior:"smooth"});}});});Array.prototype.slice.call(clone.querySelectorAll("[data-down]")).map(function(obj){obj.addEventListener("click",function(){if(clone.nextElementSibling){clone.parentNode.insertBefore(clone.nextElementSibling,clone);obj.scrollIntoView({behavior:"smooth"});}});});});element.parentNode.insertBefore(button,element.nextSibling);element.parentNode.removeChild(element);button.form.addEventListener('reset',function(event){target.innerHTML='';if(first){button.click();}});if(first){button.click();}}});})(window);(function(window){"use strict";window.ls.container.get("view").add({selector:"data-forms-add",repeat:false,controller:function(element,view,container,document){for(var i=0;ihighest){highest=data[x].value;} +config.data.datasets[i].data[x]=data[x].value;config.data.labels[x]=date.format(dateFormat,data[x].date);}} +if(highest==0){config.options.scales.y.ticks.stepSize=1;config.options.scales.y.max=ticksCount;}else{highest=Math.ceil(highest/ticksCount)*ticksCount;config.options.scales.y.ticks.stepSize=highest/ticksCount;config.options.scales.y.max=highest;} if(chart){chart.destroy();} else{} chart=new Chart(child.getContext("2d"),config);wrapper.dataset["canvas"]=true;} diff --git a/public/scripts/views/forms/chart.js b/public/scripts/views/forms/chart.js index bf8dc6f6b..75ac61e16 100644 --- a/public/scripts/views/forms/chart.js +++ b/public/scripts/views/forms/chart.js @@ -14,6 +14,7 @@ let colors = (element.getAttribute('data-colors') || 'blue,green,orange,red').split(','); let themes = {'blue': '#29b5d9', 'green': '#4eb55b', 'orange': '#fba233', 'red': '#dc3232', 'create': '#00b680', 'read': '#009cde', 'update': '#696fd7', 'delete': '#da5d95',}; let range = {'24h': 'H:i', '7d': 'd F Y', '30d': 'd F Y', '90d': 'd F Y'} + let ticksCount = 5; element.parentNode.insertBefore(wrapper, element.nextSibling); @@ -53,10 +54,9 @@ }, y: { display: showYAxis, + min: 0, ticks: { - maxTicksLimit: 7, - min: 7, - max: 7, + count: ticksCount, }, } }, @@ -72,6 +72,7 @@ } }; + let highest = 0; for (let i = 0; i < sources.length; i++) { let label = sources[i].substring(0, sources[i].indexOf('=')); let path = sources[i].substring(sources[i].indexOf('=') + 1); @@ -95,10 +96,23 @@ let dateFormat = (value.range && range[value.range]) ? range[value.range] : 'd F Y'; for (let x = 0; x < data.length; x++) { + if(data[x].value > highest) { + highest = data[x].value; + } config.data.datasets[i].data[x] = data[x].value; config.data.labels[x] = date.format(dateFormat, data[x].date); } } + + if(highest == 0) { + config.options.scales.y.ticks.stepSize = 1; + config.options.scales.y.max = ticksCount; + } else { + // ceiling of the highest value + highest = Math.ceil(highest / ticksCount) * ticksCount; + config.options.scales.y.ticks.stepSize = highest / ticksCount; + config.options.scales.y.max = highest; + } if(chart) { chart.destroy();