Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/bdthemes-element-pack/assets/js/modules/ep-chart.js
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
/**
2
+
* Start chart widget script
3
+
*/
4
+
5
+
(function ($, elementor) {
6
+
7
+
'use strict';
8
+
9
+
var widgetChart = function ($scope, $) {
10
+
11
+
var $chart = $scope.find('.bdt-chart'),
12
+
$chart_canvas = $chart.find('> canvas'),
13
+
settings = $chart.data('settings'),
14
+
suffixprefix = $chart.data('suffixprefix');
15
+
16
+
if (!$chart.length) {
17
+
return;
18
+
}
19
+
20
+
epObserveTarget($scope[0], function () {
21
+
var $this = $($chart),
22
+
ctx = $chart.find('> canvas')[0].getContext('2d'),
23
+
myChart = null;
24
+
25
+
if (myChart != null) {
26
+
myChart.destroy();
27
+
}
28
+
29
+
myChart = new Chart(ctx, settings);
30
+
31
+
32
+
var thouSeparator = settings.valueSeparator,
33
+
separatorSymbol = settings.separatorSymbol,
34
+
xAxesSeparator = settings.xAxesSeparator,
35
+
yAxesSeparator = settings.yAxesSeparator;
36
+
var _k_formatter = (settings.kFormatter == 'yes') ? true : false;
37
+
38
+
/**
39
+
* start update
40
+
* s_p_status = s = suffix, p = prefix
41
+
*/
42
+
43
+
if (settings.type == 'pie' || settings.type == 'doughnut') {
44
+
return;
45
+
}
46
+
47
+
var
48
+
s_p_status = (typeof suffixprefix.suffix_prefix_status !== 'undefined') ? suffixprefix.suffix_prefix_status : 'no',
49
+
50
+
x_prefix = (typeof suffixprefix.x_custom_prefix !== 'undefined') ? suffixprefix.x_custom_prefix : '',
51
+
x_suffix = (typeof suffixprefix.x_custom_suffix !== 'undefined') ? suffixprefix.x_custom_suffix : '',
52
+
53
+
y_suffix = (typeof suffixprefix.y_custom_suffix !== 'undefined') ? suffixprefix.y_custom_suffix : '',
54
+
y_prefix = (typeof suffixprefix.y_custom_prefix !== 'undefined') ? suffixprefix.y_custom_prefix : '';
55
+
56
+
57
+
function addCommas(nStr, separatorSymbol, _k_formatter) {
58
+
nStr += '';
59
+
var x = nStr.split('.');
60
+
var x1 = x[0];
61
+
var x2 = x.length > 1 ? '.' + x[1] : '';
62
+
var rgx = /(\d+)(\d{3})/;
63
+
while (rgx.test(x1)) {
64
+
x1 = x1.replace(rgx, '$1' + separatorSymbol + '$2');
65
+
}
66
+
67
+
if (_k_formatter == true) {
68
+
if (nStr >= 1000000000) {
69
+
return (nStr / 1000000000).toFixed(1).replace(/\.0$/, '') + 'G';
70
+
}
71
+
if (nStr >= 1000000) {
72
+
return (nStr / 1000000).toFixed(1).replace(/\.0$/, '') + 'M';
73
+
}
74
+
if (nStr >= 1000) {
75
+
return (nStr / 1000).toFixed(1).replace(/\.0$/, '') + 'K';
76
+
}
77
+
return nStr;
78
+
} else {
79
+
return x1 + x2;
80
+
}
81
+
}
82
+
83
+
84
+
function updateChartSetting(chart, thouSeparator = 'no', separatorSymbol = ',') {
85
+
86
+
// chart.options.scales.x.ticks = {
87
+
// callback: function (value, index, ticks) {
88
+
89
+
// if (s_p_status == 'yes' && thouSeparator == 'yes' && xAxesSeparator == 'yes') {
90
+
// return x_prefix + addCommas(value, separatorSymbol, _k_formatter) + x_suffix;
91
+
// } else if (s_p_status == 'no' && thouSeparator == 'yes' && xAxesSeparator == 'yes') {
92
+
// return addCommas(value, separatorSymbol, _k_formatter);
93
+
// } else {
94
+
// return x_prefix + value + x_suffix;
95
+
// }
96
+
97
+
// }
98
+
// }
99
+
100
+
if (suffixprefix.type == 'horizontalBar') {
101
+
chart.options.scales.x.ticks = {
102
+
callback: function (value, index) {
103
+
104
+
if (s_p_status == 'yes' && thouSeparator == 'yes' && yAxesSeparator == 'yes') {
105
+
return y_prefix + addCommas(value, separatorSymbol, _k_formatter) + y_suffix;
106
+
} else if (s_p_status == 'no' && thouSeparator == 'yes' && yAxesSeparator == 'yes') {
107
+
return addCommas(value, separatorSymbol, _k_formatter);
108
+
} else {
109
+
return y_prefix + value + y_suffix;
110
+
}
111
+
}
112
+
}
113
+
} else if (suffixprefix.type == 'bar' || suffixprefix.type == 'line' || suffixprefix.type == 'bubble') {
114
+
chart.options.scales.y.ticks = {
115
+
callback: function (value, index) {
116
+
117
+
if (s_p_status == 'yes' && thouSeparator == 'yes' && yAxesSeparator == 'yes') {
118
+
return y_prefix + addCommas(value, separatorSymbol, _k_formatter) + y_suffix;
119
+
} else if (s_p_status == 'no' && thouSeparator == 'yes' && yAxesSeparator == 'yes') {
120
+
return addCommas(value, separatorSymbol, _k_formatter);
121
+
} else {
122
+
return y_prefix + value + y_suffix;
123
+
}
124
+
}
125
+
}
126
+
}
127
+
128
+
chart.update();
129
+
}
130
+
if (s_p_status == 'yes' && thouSeparator == 'no') {
131
+
updateChartSetting(myChart);
132
+
} else if (s_p_status == 'yes' && thouSeparator == 'yes') {
133
+
updateChartSetting(myChart, thouSeparator, separatorSymbol);
134
+
} else if (s_p_status == 'no' && thouSeparator == 'yes') {
135
+
updateChartSetting(myChart, thouSeparator, separatorSymbol);
136
+
} else {
137
+
138
+
}
139
+
// end update
140
+
141
+
},{
142
+
root: null, // Use the viewport as the root
143
+
rootMargin: '0px', // No margin around the root
144
+
threshold: 0.8 // 80% visibility (1 - 0.8)
145
+
});
146
+
147
+
};
148
+
149
+
jQuery(window).on('elementor/frontend/init', function () {
150
+
elementorFrontend.hooks.addAction('frontend/element_ready/bdt-chart.default', widgetChart);
151
+
});
152
+
153
+
}(jQuery, window.elementorFrontend));
154
+
155
+
/**
156
+
* End chart widget script
157
+
*/