Sha256: 9e7f0658200d08c2e06052961728a70fb626aad4f65ae4a2bd4a42084f76f7c2
Contents?: true
Size: 1.79 KB
Versions: 3
Compression:
Stored size: 1.79 KB
Contents
function legend(parent, data) { legend(parent, data, null); } function legend(parent, data, chart) { parent.className = 'o-chart-legend'; var datas = data.hasOwnProperty('datasets') ? data.datasets : data; // remove possible children of the parent while(parent.hasChildNodes()) { parent.removeChild(parent.lastChild); } var show = chart ? showTooltip : noop; datas.forEach(function(d, i) { //span to div: legend appears to all element (color-sample and text-node) var title = document.createElement('div'); title.className = 'o-chart-legend__title'; parent.appendChild(title); var colorSample = document.createElement('div'); colorSample.className = 'o-chart-legend__color-sample'; colorSample.style.backgroundColor = d.hasOwnProperty('strokeColor') ? d.strokeColor : d.color; colorSample.style.borderColor = d.hasOwnProperty('fillColor') ? d.fillColor : d.color; title.appendChild(colorSample); var text = document.createTextNode(d.label); text.className = 'text-node'; title.appendChild(text); show(chart, title, i); }); } //add events to legend that show tool tips on chart function showTooltip(chart, elem, indexChartSegment){ var helpers = Chart.helpers; var segments = chart.segments; //Only chart with segments if(typeof segments != 'undefined'){ helpers.addEvent(elem, 'mouseover', function(){ var segment = segments[indexChartSegment]; segment.save(); segment.fillColor = segment.highlightColor; chart.showTooltip([segment]); segment.restore(); }); helpers.addEvent(elem, 'mouseout', function(){ chart.draw(); }); } } function noop() {}
Version data entries
3 entries across 3 versions & 1 rubygems