var element = evt.target var chart = element.shadowTree var bar = chart.getElementById("bar0") var label = chart.getElementById("lab0") var data = element.getAttribute("data").split(";") for (var i = 1;i < data.length;i++) { new_bar = bar.cloneNode("true") new_bar.setAttribute("id","bar" + i.toString()) chart.insertBefore(new_bar,chart.getElementById("x_axis")) new_label = label.cloneNode("true") new_label.setAttribute("id","lab" + i.toString()) chart.insertBefore(new_label,label) } var x = 0, y = 0, width = 200, height = 100, i = 0, nb_rect = 0, data1 ="", fill1 = "", title_data = ""; var nb_attributes = element.attributes.length, label_data = ""; for (i = 0;i < nb_attributes;i++) { attribute = element.attributes.item(i) switch(attribute.name) {case "x" : x = attribute.value - 0 ; break; case "y" : y = attribute.value - 0 ; break; case "width" : width = attribute.value - 0 ; break; case "height" : height = attribute.value - 0 ; break; case "data" : data1 = attribute.value; break; case "filled" : fill1 = attribute.value; break; case "title" : title_data = attribute.value; break; case "label" : label_data = attribute.value; break; case "onclick" : break; case "onmousedown" : break; case "onmousemove" : break; case "onmouseup" : break; case "onmousein" : break; case "onmouseout" : break; case "id" : break; case "cursor" : break; } } var data = data1.split(";") nb_rect = parseInt(data.length) var fill = fill1.split(";") var lab = label_data.split(";") var min_data = data[0] var max_data = data[0] for (i = 1;i < nb_rect;i++) { if (data[i] > max_data) max_data = data[i] if (data[i] < min_data) min_data = data[i] } var rect = chart.getElementById("rect0") rect.setAttributeNS(null,"x",x.toString()) rect.setAttributeNS(null,"y",y.toString()) rect.setAttributeNS(null,"width",width.toString()) rect.setAttributeNS(null,"height",height.toString()) rect.setAttributeNS(null,"fill",fill[0]) var width_rect = parseInt((width - 50) / nb_rect) var k = parseFloat((height - 70) / max_data) for (i = 0;i < nb_rect;i++) { bar = chart.getElementById("bar" + i.toString()) bar.setAttributeNS(null,"x",(x + 30 + width_rect * i).toString()) bar.setAttributeNS(null,"y",(y + height - 30).toString()) bar.setAttributeNS(null,"width",width_rect.toString()) bar.setAttributeNS(null,"height",(data[i] * k).toString()) bar.setAttributeNS(null,"fill",fill[i + 1]) label = chart.getElementById("lab" + i.toString()) label.setAttributeNS(null,"x",(x + 30 + width_rect / 2 + width_rect * i).toString()) label.setAttributeNS(null,"y",(y + height - 10).toString()) label.firstChild.data = lab[i] } var axis = chart.getElementById("x_axis") axis.setAttributeNS(null,"d","M" + (x + 30).toString() + " " + (y + height - 30).toString() + "h" + (width - 40).toString()) axis = chart.getElementById("y_axis") axis.setAttributeNS(null,"d","M" + (x + 30).toString() + " " + (y + height - 30).toString() + "v" + (40 - height).toString()) title = chart.getElementById("title") title.setAttribute("x",(x + width / 2).toString()) title.setAttribute("y",(y + 20).toString()) title.firstChild.data = title_data var ampli = Math.round(Math.log(max_data)/Math.LN10) - 1 var step = Math.pow(10,ampli) string_d = "M" + (x + 30).toString() + " " + (y + height - 30).toString() +"h-5 " i = 1 while (i * step * k< height - 30) { string_d += "M" + (x + 30).toString() + " " + (y + height - 30 - i * step * k).toString() +"h-5 " i ++ } axis = chart.getElementById("y_units") axis.setAttributeNS(null,"d",string_d) axis = chart.getElementById("origin") axis.setAttributeNS(null,"x",(x + 25).toString()) axis.setAttributeNS(null,"y",(y + height - 30).toString()) axis = chart.getElementById("y_unit") axis.setAttributeNS(null,"x",(x + 25).toString()) axis.setAttributeNS(null,"y",(y + height - 30 - step * k).toString()) axis.firstChild.data = step.toString() axis = chart.getElementById("y_max") axis.setAttributeNS(null,"x",(x + 25).toString()) axis.setAttributeNS(null,"y",(y + height - 30 - step * k * (i - 1)).toString()) axis.firstChild.data = (step * (i - 1 )).toString()