Current Path : /home/bitrix/ext_www/dev.ballu.in.ua/about/js/ |
Current File : /home/bitrix/ext_www/dev.ballu.in.ua/about/js/superlines.js |
/** * Created by Denis Khakimov <denisdude@gmail.com> on 14.12.2017. */ function SuperPoint(ox, oy, x, y) { this.ox = ox;// + $(window).width() / 250; this.oy = oy; this.x = x;// + $(window).width() / 250; this.y = y; } SuperPoint.prototype.setX = function(x) { this.x = x; }; SuperPoint.prototype.setY = function(x) { this.y = y; }; SuperPoint.prototype.setOX = function(ox) { this.ox = ox; }; SuperPoint.prototype.setOY = function(oy) { this.ox = oy; }; function SuperLine(canvas, callback, time) { this.canvas = canvas; this.cw = this.canvas.width(); this.ch = this.canvas.height(); this.callback = callback; //this.dots = dots; this.fillDots(); this.realDots = this.dots; this.lines = []; this.paper = null; this.time = time; } SuperLine.prototype.fillDots = function() { var d = this.canvas, path_str = d.data('path'), path = [], t = new String(path_str); path = t.split(','); this.dots = []; for (var i = 0; i < path.length; i++) { this.dots.push(parseFloat(path[i])); } }; SuperLine.prototype.fillLines = function(dots) { var ox = 0, oy = 0, x = 0, y = 0, index = 0, sp = null; this.lines = []; for (var i = 0; i < this.realDots.length; i++) { if (i % 2 == 1) { if (index == 0) { oy = this.realDots[i]; index++; } else { y = this.realDots[i]; sp = new SuperPoint(ox, oy, x, y); this.lines.push(sp); ox = x; oy = y; } } else { if (index == 0) { ox = this.realDots[i]; } else { x = this.realDots[i]; } } } }; SuperLine.prototype.refreshDots = function() { this.realDots = this.dots; for (var i = 0; i < this.dots.length; i++) { var v = 0, cv = parseInt(this.dots[i]); if (i % 2 == 1) { v = cv * this.ch / 100; } else { v = cv * this.cw / 100; } this.realDots[i] = Math.round(v); } //console.log(this.dots); //console.log(this.realDots); this.fillLines(this.realDots); }; SuperLine.prototype.paint = function() { if (this.paper) { this.paper.clear(); this.paper.remove(); } this.paper = Raphael(this.canvas.attr('id'), this.cw, this.ch); this.drawLine(0); }; SuperLine.prototype.clear = function() { if (this.paper) { this.paper.clear(); this.paper.remove(); } }; SuperLine.prototype.drawLine = function(index) { var i = index, sl = this; if (this.lines[index]) { var sp = this.lines[i]; var l = this.paper.path('M'+sp.ox+' '+sp.oy); l.attr('stroke', '#2f9b26'); l.attr('stroke-width', '2'); if (!sl.lines[i+1]) { // подгоняем последнюю точку к центру картинки города sl.lines[i].x = sl.lines[i].x + 102; sl.lines[i].y = sl.lines[i].y + 102; } l.animate( { path: 'M'+sp.ox+' '+sp.oy+' L'+sp.x+' '+sp.y } ,this.time ,function() { i++; if (sl.lines[i]) { sl.drawLine(i); } else { sl.callback(); } }); } }; SuperLine.prototype.resize = function() { this.clear(); this.fillDots(); //console.log('1: ' + this.dots); //console.log('2: ' + this.realDots); this.realDots = this.dots; this.cw = this.canvas.width(); this.ch = this.canvas.height(); //console.log(this.lines); this.refreshDots(); //console.log(this.dots); //console.log(this.cw + ' : ' + this.ch); //console.log(this.realDots); };