1/* ========================================================= 2 * jquery.vc_chart.js v1.0 3 * ========================================================= 4 * Copyright 2013 Wpbakery 5 * 6 * Jquery chart plugin for the Visual Composer. 7 * ========================================================= */ 8(function($){ 9 /** 10 * Pie chart animated. 11 * @param element - DOM element 12 * @param options - settings object. 13 * @constructor 14 */ 15 var VcChart = function(element, options) { 16 this.el = element; 17 this.$el = $(this.el); 18 this.options = $.extend({ 19 color: 'wpb_button', 20 units: '', 21 label_selector: '.vc_pie_chart_value', 22 back_selector: '.vc_pie_chart_back', 23 responsive: true 24 }, options); 25 this.init(); 26 }; 27 VcChart.prototype = { 28 constructor: VcChart, 29 _progress_v: 0, 30 animated: false, 31 colors: { 32 'wpb_button': 'rgba(247, 247, 247, 1)', 33 'btn-primary': 'rgba(0, 136, 204, 1)', 34 'btn-info': 'rgba(88, 185, 218, 1)', 35 'btn-success': 'rgba(106, 177, 101, 1)', 36 'btn-warning': 'rgba(255, 153, 0, 1)', 37 'btn-danger': 'rgba(255, 103, 91, 1)', 38 'btn-inverse': 'rgba(85, 85, 85, 1)' 39 }, 40 init: function() { 41 this.setupColor(); 42 this.value = this.$el.data('pie-value')/100; 43 this.label_value = this.$el.data('pie-label-value') || this.$el.data('pie-value'); 44 this.$wrapper = $('.vc_pie_wrapper', this.$el); 45 this.$label = $(this.options.label_selector, this.$el); 46 this.$back = $(this.options.back_selector, this.$el); 47 this.$canvas = this.$el.find('canvas'); 48 this.draw(); 49 this.setWayPoint(); 50 if(this.options.responsive === true) this.setResponsive(); 51 52 }, 53 setupColor: function() { 54 if(typeof this.colors[this.options.color] !== 'undefined') { 55 this.color = this.colors[this.options.color]; 56 } else if(typeof this.options.color === 'string') { 57 this.color = this.options.color; 58 } else { 59 this.color = 'rgba(247, 247, 247, 0.2)'; 60 } 61 }, 62 setResponsive: function() { 63 var that = this; 64 $(window).resize(function(){ 65 if(that.animated === true) that.circle.stop(); 66 //that.draw(true); 67 }); 68 }, 69 draw: function(redraw) { 70 var w = this.$el.addClass('vc_ready').width(), 71 border_w = this.$el.data('pie-border'), 72 border_color = this.$el.data('pie-border-back'), 73 radius; 74 if(!w) w = this.$el.parents(':visible').first().width()-2; 75 w = w/100*80; 76 radius = w/2 - border_w - 1; 77 border_w_black = border_w; 78 this.$wrapper.css({"width" : w + "px"}); 79 this.$label.css({"width" : w, "height" : w, "line-height" : w+"px"}); 80 this.$back.css({"width" : w, "height" : w}); 81 this.$canvas.attr({"width" : w + "px", "height" : w + "px"}); 82 this.$back.attr({"style" : "border-width:"+border_w_black + "px;border-color:"+border_color + ";"}); 83 this.$el.addClass('vc_ready'); 84 this.circle = new ProgressCircle({ 85 canvas: this.$canvas.get(0), 86 minRadius: radius, 87 arcWidth: border_w 88 }); 89 if(redraw === true && this.animated === true) { 90 this._progress_v = this.value; 91 this.circle.addEntry({ 92 fillColor: this.color, 93 progressListener: $.proxy(this.setProgress, this) 94 }).start(); 95 } 96 }, 97 setProgress: function() { 98 if (this._progress_v >= this.value) { 99 this.circle.stop(); 100 this.$label.text(this.label_value + this.options.units); 101 return this._progress_v; 102 } 103 this._progress_v += 0.005; 104 var label_value = this._progress_v/this.value*this.label_value; 105 var val = Math.round(label_value) + this.options.units; 106 this.$label.text(val); 107 return this._progress_v; 108 }, 109 animate: function() { 110 if(this.animated !== true) { 111 this.animated = true; 112 this.circle.addEntry({ 113 fillColor: this.color, 114 progressListener: $.proxy(this.setProgress, this) 115 }).start(5); 116 } 117 }, 118 setWayPoint: function() { 119 if (typeof $.fn.waypoint !== 'undefined') { 120 this.$el.waypoint($.proxy(this.animate, this), { offset: '85%' }); 121 } else { 122 this.animate(); 123 } 124 } 125 }; 126 /** 127 * jQuery plugin 128 * @param option - object with settings 129 * @return {*} 130 */ 131 $.fn.vcChat = function(option, value) { 132 return this.each(function () { 133 var $this = $(this), 134 data = $this.data('vc_chart'), 135 options = typeof option === 'object' ? option : { 136 color: $this.data('pie-color'), 137 units: $this.data('pie-units') 138 }; 139 if (typeof option == 'undefined') $this.data('vc_chart', (data = new VcChart(this, options))); 140 if (typeof option == 'string') data[option](value); 141 }); 142 }; 143 /** 144 * Allows users to rewrite function inside theme. 145 */ 146 if ( typeof window['vc_pieChart'] !== 'function' ) { 147 window.vc_pieChart = function() { 148 $('.vc_pie_chart:visible').vcChat(); 149 } 150 } 151 $(document).ready(function(){ 152 !window.vc_iframe && vc_pieChart(); 153 }); 154 155})(window.jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.