init cleanups

This commit is contained in:
Prateeksha Singh 2018-04-18 01:37:20 +05:30
parent 75a4e69297
commit 57c1fcc3a3
5 changed files with 30 additions and 19 deletions

View File

@ -13,6 +13,9 @@
<a href="http://github.com/frappe/charts/tree/master/dist/js/frappe-charts.min.iife.js"> <a href="http://github.com/frappe/charts/tree/master/dist/js/frappe-charts.min.iife.js">
<img src="http://img.badgesize.io/frappe/charts/master/dist/frappe-charts.min.iife.js.svg?compression=gzip"> <img src="http://img.badgesize.io/frappe/charts/master/dist/frappe-charts.min.iife.js.svg?compression=gzip">
</a> </a>
<a href="https://travis-ci.org/frappe/charts">
<img src="https://img.shields.io/travis/frappe/charts.svg?style=flat-square">
</a>
</p> </p>
<p align="center"> <p align="center">

View File

@ -50,12 +50,13 @@ lineCompositeChart.parent.addEventListener('data-select', (e) => {
// ================================================================================ // ================================================================================
let args = { let customColors = ['purple', 'magenta', 'light-blue'];
let typeChartArgs = {
title: "My Awesome Chart", title: "My Awesome Chart",
data: typeData, data: typeData,
type: 'axis-mixed', type: 'axis-mixed',
height: 250, height: 250,
colors: ['purple', 'magenta', 'light-blue'], colors: customColors,
maxLegendPoints: 6, maxLegendPoints: 6,
maxSlices: 10, maxSlices: 10,
@ -66,7 +67,7 @@ let args = {
} }
}; };
let aggrChart = new Chart("#chart-aggr", args); let aggrChart = new Chart("#chart-aggr", typeChartArgs);
Array.prototype.slice.call( Array.prototype.slice.call(
document.querySelectorAll('.aggr-type-buttons button') document.querySelectorAll('.aggr-type-buttons button')
@ -74,9 +75,14 @@ Array.prototype.slice.call(
el.addEventListener('click', (e) => { el.addEventListener('click', (e) => {
let btn = e.target; let btn = e.target;
let type = btn.getAttribute('data-type'); let type = btn.getAttribute('data-type');
args.type = type; typeChartArgs.type = type;
if(type !== 'axis-mixed') {
typeChartArgs.colors = undefined;
} else {
typeChartArgs.colors = customColors;
}
let newChart = aggrChart.getDifferentChart(type); let newChart = new Chart("#chart-aggr", typeChartArgs);
if(newChart){ if(newChart){
aggrChart = newChart; aggrChart = newChart;
} }

View File

@ -49,12 +49,6 @@ var HEATMAP_COLORS_YELLOW = ['#ebedf0', '#fdf436', '#ffc700', '#ff9100', '#06001
// Universal constants // Universal constants
/**
* Returns the value of a number upto 2 decimal places.
* @param {Number} d Any number
*/
/** /**
* Returns whether or not two given arrays are equal. * Returns whether or not two given arrays are equal.
* @param {Array} arr1 First array * @param {Array} arr1 First array
@ -123,6 +117,7 @@ var MONTH_NAMES_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
// https://stackoverflow.com/a/11252167/6495043
function clone(date) { function clone(date) {
@ -163,8 +158,6 @@ function addDays(date, numberOfDays) {
date.setDate(date.getDate() + numberOfDays); date.setDate(date.getDate() + numberOfDays);
} }
// Composite Chart
// ================================================================================
var reportCountList = [152, 222, 199, 287, 534, 709, 1179, 1256, 1632, 1856, 1850]; var reportCountList = [152, 222, 199, 287, 534, 709, 1179, 1256, 1632, 1856, 1850];
var lineCompositeData = { var lineCompositeData = {
@ -345,12 +338,13 @@ lineCompositeChart.parent.addEventListener('data-select', function (e) {
// ================================================================================ // ================================================================================
var args = { var customColors = ['purple', 'magenta', 'light-blue'];
var typeChartArgs = {
title: "My Awesome Chart", title: "My Awesome Chart",
data: typeData, data: typeData,
type: 'axis-mixed', type: 'axis-mixed',
height: 250, height: 250,
colors: ['purple', 'magenta', 'light-blue'], colors: customColors,
maxLegendPoints: 6, maxLegendPoints: 6,
maxSlices: 10, maxSlices: 10,
@ -365,15 +359,20 @@ var args = {
} }
}; };
var aggrChart = new Chart("#chart-aggr", args); var aggrChart = new Chart("#chart-aggr", typeChartArgs);
Array.prototype.slice.call(document.querySelectorAll('.aggr-type-buttons button')).map(function (el) { Array.prototype.slice.call(document.querySelectorAll('.aggr-type-buttons button')).map(function (el) {
el.addEventListener('click', function (e) { el.addEventListener('click', function (e) {
var btn = e.target; var btn = e.target;
var type = btn.getAttribute('data-type'); var type = btn.getAttribute('data-type');
args.type = type; typeChartArgs.type = type;
if (type !== 'axis-mixed') {
typeChartArgs.colors = undefined;
} else {
typeChartArgs.colors = customColors;
}
var newChart = aggrChart.getDifferentChart(type); var newChart = new Chart("#chart-aggr", typeChartArgs);
if (newChart) { if (newChart) {
aggrChart = newChart; aggrChart = newChart;
} }

File diff suppressed because one or more lines are too long

View File

@ -289,6 +289,9 @@
chart.removeDataPoint(index) chart.removeDataPoint(index)
chart.updateDataset(datasetValues, index) chart.updateDataset(datasetValues, index)
// Exporting
chart.export();
</code></pre> </code></pre>
</div> </div>
</div> </div>