javascript - Google Timeline memory-leak when redrawing chart -
here chart https://jsfiddle.net/damiantt/t2skaegg/2/
<script type="text/javascript" src="//www.google.com/jsapi"></script> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <input id="draw" type="button" value="draw" onclick="drawchart();" /> <div id="chart_div_container" style="overflow-x: auto;min-height:0%;"> <div id="chart_div" style="overflow: visible;min-height:0%;"></div> </div> <script type="text/javascript"> google.charts.load('current', { 'packages': ['timeline', 'table'] }); var initwidth = $('#chart_div').innerwidth(); var colormap; function drawchart() { $('#chart_div').off(); $('#chart_div').empty(); var data = google.visualization.arraytodatatable([ ['maszyna', 'kolor', { type: 'string', role: 'tooltip', 'p': { 'html': true } }, 'start time', 'end time'], ['one', 'pi1', 'brr', new date(2014, 10, 15, 12, 30, 0), new date(2014, 10, 15, 12, 30, 20) ], ['one', 'pu3', 'brr', new date(2014, 10, 15, 12, 30, 20), new date(2014, 10, 15, 12, 30, 45) ], ['one', 'pu3', 'brr', new date(2014, 10, 15, 12, 30, 45), new date(2014, 10, 15, 12, 30, 55) ], ['two', 'g2', 'brr1', new date(2014, 10, 15, 12, 30, 35), new date(2014, 10, 15, 12, 30, 55) ], ['two', 'pi1', 'brr2', new date(2014, 10, 15, 12, 30, 55), new date(2014, 10, 15, 14, 31, 55) ], ['three', 'pu3', 'brr', new date(2014, 10, 15, 12, 29, 30), new date(2014, 10, 15, 14, 30, 0) ], ['three', 'pi1', 'brr', new date(2014, 10, 15, 14, 30, 0), new date(2014, 10, 15, 14, 35, 0) ], ['three', 'g2', 'zbrr', new date(2014, 10, 15, 14, 35, 0), new date(2014, 10, 15, 15, 25, 10) ], ['three', 'pu3', 'kr1', new date(2014, 10, 15, 15, 25, 10), new date(2014, 10, 15, 15, 26, 00) ], ['three', 'g2', 'kr2', new date(2014, 10, 15, 15, 26, 00), new date(2014, 10, 15, 15, 26, 45) ], ['three', 'pi1', 'kr3', new date(2014, 10, 15, 15, 26, 45), new date(2014, 10, 15, 15, 27, 15) ], ['three', 'pu3', 'brr', new date(2014, 10, 15, 15, 27, 15), new date(2014, 10, 15, 20, 30, 1) ], ['three', 'pi1', 'brr', new date(2014, 10, 15, 20, 30, 1), new date(2014, 10, 16, 10, 30, 10) ], ['three', 'pu3', 'brr', new date(2014, 10, 16, 10, 30, 10), new date(2014, 10, 16, 18, 30, 10) ], ]); var colors = []; colormap = { // should contain map of category -> color every category pi1: '#e63b6f', g2: '#19c362', pu3: '#592df7', c4: '#000000', '000000': '#000000' } (var = 0; < data.getnumberofrows(); i++) { colors.push(colormap[data.getvalue(i, 1)]); } var options = { enableinteractivity: false, height: 210, width: initwidth, colors: colors, avoidoverlappinggridlines: false, timeline: { showbarlabels: false }, haxis: { format: 'dd/mm\nhh:mm' }, tooltip: { ishtml: true } }; var chart = new google.visualization.timeline(document.getelementbyid('chart_div')); chart.draw(data, options); afterdraw(data, colors); $(document).ready(function() { var zoom = 1000; var leftspace = $('rect:first-child+path').position().left - $('#chart_div svg').position().left; var svgoffset = $('#chart_div svg').offset().left; var $chartdivcont = $('#chart_div_container'); var x, left, down; $('#chart_div').on({ 'mousemove': function(evt) { if (down) { var newx = evt.pagex; $chartdivcont.scrollleft(left - newx + x); } }, 'mousedown': function(evt) { $('html').css('cursor', 'col-resize'); evt.preventdefault(); down = true; x = evt.pagex; left = $chartdivcont.scrollleft(); }, 'mouseup': function() { down = false; $('html').css('cursor', 'auto'); }, 'mousewheel dommousescroll': function(evt) { evt.preventdefault(); if (evt.originalevent.wheeldelta > 0 || evt.originalevent.detail < 0) { if (options.width < 31000) { options.width += zoom; var prevscrollleft = $chartdivcont.scrollleft(); var prop = ($chartdivcont.scrollleft() + evt.originalevent.clientx - leftspace - svgoffset) / ($('#chart_div svg').width() - leftspace); chart.draw(data, options); afterdraw(data, colors); $chartdivcont.scrollleft(prevscrollleft + (prop * 1000)); } } else { if (options.width >= initwidth + zoom) { options.width -= zoom; var prevscrollleft = $chartdivcont.scrollleft(); var prop = ($chartdivcont.scrollleft() + evt.originalevent.clientx - leftspace - svgoffset) / ($('#chart_div svg').width() - leftspace); chart.draw(data, options); afterdraw(data, colors); $chartdivcont.scrollleft(prevscrollleft - (prop * 1000)); } } } }); }); } function afterdraw(data, colors) { $rects = $('#chart_div svg > g:nth-child(5) > rect'); (var = 0; < $rects.length; i++) { $('#chart_div svg > g:nth-child(5) > rect:nth-child(' + (i + 1) + ')').css({ "fill": colors[i] }); } }
when run on chrome, memory usage ~75k. after draw , max zoom in (zoom mouse scroll) memory meter shows 140k, max zoom out - 180k memory usage, zoom in - 225k, zoom out - 265k.
is way free memory after every draw()? tried delete html elements, null variables, nothing helps me
Comments
Post a Comment