donation/public/assets/js/pages/project-details.init.js

167 lines
5.9 KiB
JavaScript

/*
Template Name: Minton - Responsive Bootstrap 4 Admin Dashboard
Author: CoderThemes
Website: https://coderthemes.com/
Contact: support@coderthemes.com
File: Project Detail init js
*/
! function ($) {
"use strict";
var ChartJs = function () {
this.$body = $("body"),
this.charts = []
};
ChartJs.prototype.respChart = function (selector, type, data, options) {
var draw = Chart.controllers.line.prototype.draw;
Chart.controllers.line.prototype.draw = function () {
draw.apply(this, arguments);
var ctx = this.chart.chart.ctx;
var _stroke = ctx.stroke;
ctx.stroke = function () {
ctx.save();
ctx.shadowColor = 'rgba(0,0,0,0.01)';
ctx.shadowBlur = 20;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 5;
_stroke.apply(this, arguments);
ctx.restore();
}
};
//default config
Chart.defaults.global.defaultFontColor = "#8391a2";
Chart.defaults.scale.gridLines.color = "#8391a2";
// get selector by context
var ctx = selector.get(0).getContext("2d");
// pointing parent container to make chart js inherit its width
var container = $(selector).parent();
// this function produce the responsive Chart JS
function generateChart() {
// make chart width fit with its container
var ww = selector.attr('width', $(container).width());
var chart;
switch (type) {
case 'Line':
chart = new Chart(ctx, { type: 'line', data: data, options: options });
break;
case 'Doughnut':
chart = new Chart(ctx, { type: 'doughnut', data: data, options: options });
break;
case 'Pie':
chart = new Chart(ctx, { type: 'pie', data: data, options: options });
break;
case 'Bar':
chart = new Chart(ctx, { type: 'bar', data: data, options: options });
break;
case 'Radar':
chart = new Chart(ctx, { type: 'radar', data: data, options: options });
break;
case 'PolarArea':
chart = new Chart(ctx, { data: data, type: 'polarArea', options: options });
break;
}
return chart;
};
// run function - render chart at first load
return generateChart();
},
// init various charts and returns
ChartJs.prototype.initCharts = function () {
var charts = [];
if ($('#line-chart-example').length > 0) {
var lineChart = {
labels: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
datasets: [{
label: "Completed Tasks",
backgroundColor: 'rgba(74, 129, 212, 0.3)',
borderColor: '#4a81d4',
data: [32, 42, 42, 62, 52, 75, 62]
}, {
label: "Plan Tasks",
fill: true,
backgroundColor: 'transparent',
borderColor: "#f1556c",
borderDash: [5, 5],
data: [42, 58, 66, 93, 82, 105, 92]
}]
};
var lineOpts = {
maintainAspectRatio: false,
legend: {
display: false
},
tooltips: {
intersect: false
},
hover: {
intersect: true
},
plugins: {
filler: {
propagate: false
}
},
scales: {
xAxes: [{
reverse: true,
gridLines: {
color: "rgba(0,0,0,0.05)"
}
}],
yAxes: [{
ticks: {
stepSize: 20
},
display: true,
borderDash: [5, 5],
gridLines: {
color: "rgba(0,0,0,0)",
fontColor: '#fff'
}
}]
}
};
charts.push(this.respChart($("#line-chart-example"), 'Line', lineChart, lineOpts));
}
return charts;
},
//initializing various components and plugins
ChartJs.prototype.init = function () {
var $this = this;
// font
Chart.defaults.global.defaultFontFamily = '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif';
// init charts
$this.charts = this.initCharts();
// enable resizing matter
$(window).on('resize', function (e) {
$.each($this.charts, function (index, chart) {
try {
chart.destroy();
}
catch (err) {
}
});
$this.charts = $this.initCharts();
});
},
//init flotchart
$.ChartJs = new ChartJs, $.ChartJs.Constructor = ChartJs
}(window.jQuery),
//initializing ChartJs
function ($) {
"use strict";
$.ChartJs.init()
}(window.jQuery);