PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 5.2.2
WP Popular Posts v5.2.2
7.4.1 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / assets / js / chart.js
wordpress-popular-posts / assets / js Last commit date
vendor 6 years ago admin.js 6 years ago chart.js 6 years ago wpp.js 6 years ago wpp.min.js 6 years ago
chart.js
192 lines
1 var WPPChart = (function() {
2 "use strict";
3
4 /**
5 * Private functions and variables
6 */
7
8 var defaults = {
9 type: 'line',
10 data: {
11 labels: [],
12 datasets: [
13 {
14 label: "",
15 fill: true,
16 lineTension: 0.2,
17 borderWidth: 3,
18 backgroundColor: "rgba(221, 66, 66, 0.8)",
19 borderColor: "#881111",
20 borderCapStyle: 'butt',
21 borderDash: [],
22 borderDashOffset: 0.0,
23 borderJoinStyle: 'miter',
24 pointBorderColor: "#881111",
25 pointBackgroundColor: "#fff",
26 pointBorderWidth: 2,
27 pointHoverRadius: 4,
28 pointHoverBackgroundColor: "#881111",
29 pointHoverBorderColor: "#881111",
30 pointHoverBorderWidth: 3,
31 pointRadius: 3,
32 pointHitRadius: 10,
33 data: [],
34 },
35 {
36 label: "",
37 fill: true,
38 lineTension: 0.2,
39 borderWidth: 3,
40 backgroundColor: "rgba(136, 17, 17, 0.3)",
41 borderColor: "#a80000",
42 borderCapStyle: 'butt',
43 borderDash: [],
44 borderDashOffset: 0.0,
45 borderJoinStyle: 'miter',
46 pointBorderColor: "#a80000",
47 pointBackgroundColor: "#fff",
48 pointBorderWidth: 2,
49 pointHoverRadius: 4,
50 pointHoverBackgroundColor: "#a80000",
51 pointHoverBorderColor: "#a80000",
52 pointHoverBorderWidth: 3,
53 pointRadius: 3,
54 pointHitRadius: 10,
55 data: [],
56 }
57 ]
58 },
59 options: {
60 legend: {
61 display: true,
62 labels: {
63 fontColor: '#23282d',
64 fontFamily: '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif',
65 fontSize: 12
66 }
67 },
68 responsive: true,
69 maintainAspectRatio: false,
70 layout: {
71 padding: {
72 top: 2,
73 right: 5,
74 bottom: 0,
75 left: 5
76 }
77 },
78 scales: {
79 xAxes: [{
80 display: true,
81 gridLines: {
82 display: false,
83 },
84 ticks: {
85 fontSize: 10,
86 fontColor: '#23282d',
87 autoSkip: false,
88 maxRotation: 90,
89 minRotation: 90
90 }
91 }],
92 yAxes: [{
93 display: false
94 }]
95 }
96 }
97 },
98 chart = null,
99 canRender = !! window.CanvasRenderingContext2D,
100 element = null,
101 cvs = null;
102
103 var canRender = function(){
104 return canRender;
105 };
106
107 // Source: http://stackoverflow.com/a/5624139
108 var HexToRGB = function( hex ){
109 var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
110
111 hex = hex.replace(shorthandRegex, function( m, r, g, b ) {
112 return r + r + g + g + b + b;
113 });
114
115 var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
116
117 return result ? {
118 r: parseInt( result[1], 16 ),
119 g: parseInt( result[2], 16 ),
120 b: parseInt( result[3], 16 )
121 } : null;
122 };
123
124 /**
125 * Public functions
126 */
127
128 var init = function(container, options){
129 if ( ! canRender() ) {
130 throw new Error('Your browser is too old, WPPChart cannot create its data chart.');
131 }
132
133 if ( 'undefined' == typeof container ) {
134 throw new Error('Please tell WPPChart where to inject the chart.');
135 }
136
137 element = document.getElementById(container);
138
139 if ( ! element ) {
140 throw new Error('WPPChart cannot find ' + container);
141 }
142
143 if ( 'undefined' == typeof Chart ) {
144 throw new Error('ChartJS library not found');
145 }
146
147 cvs = document.createElement('canvas');
148 element.appendChild(cvs);
149 };
150
151 var populate = function(data){
152 if ( chart ) {
153 chart.destroy();
154 }
155
156 var config = defaults;
157
158 config.data.labels = data.labels;
159 config.data.datasets[0].label = data.datasets[0].label;
160 config.data.datasets[0].data = data.datasets[0].data;
161 config.data.datasets[1].label = data.datasets[1].label;
162 config.data.datasets[1].data = data.datasets[1].data;
163
164
165 var rgb_comments = HexToRGB(wpp_chart_params.colors[2]);
166 config.data.datasets[1].backgroundColor = "rgba(" + rgb_comments.r + ", " + rgb_comments.g + ", " + rgb_comments.b + ", 0.9)";
167 config.data.datasets[1].borderColor = wpp_chart_params.colors[2];
168 config.data.datasets[1].pointBorderColor = wpp_chart_params.colors[2];
169 config.data.datasets[1].pointHoverBackgroundColor = wpp_chart_params.colors[2];
170 config.data.datasets[1].pointHoverBorderColor = wpp_chart_params.colors[2];
171
172 var rgb_views = HexToRGB(wpp_chart_params.colors[3]);
173 config.data.datasets[0].backgroundColor = "rgba(" + rgb_views.r + ", " + rgb_views.g + ", " + rgb_views.b + ", 0.7)";
174 config.data.datasets[0].borderColor = wpp_chart_params.colors[3];
175 config.data.datasets[0].pointBorderColor = wpp_chart_params.colors[3];
176 config.data.datasets[0].pointHoverBackgroundColor = wpp_chart_params.colors[3];
177 config.data.datasets[0].pointHoverBorderColor = wpp_chart_params.colors[3];
178
179 chart = new Chart(cvs, config);
180 };
181
182 /**
183 * Provide access to public methods
184 */
185
186 return {
187 init: init,
188 populate: populate,
189 canRender: canRender
190 };
191 })();
192