Index: lams_central/web/includes/javascript/chart.js =================================================================== diff -u -r2011f2215e55cae81f3ee2108daa5949ad0ee74c -rd9bd1a0e26977326e557246c8440c8d13d2debc9 --- lams_central/web/includes/javascript/chart.js (.../chart.js) (revision 2011f2215e55cae81f3ee2108daa5949ad0ee74c) +++ lams_central/web/includes/javascript/chart.js (.../chart.js) (revision d9bd1a0e26977326e557246c8440c8d13d2debc9) @@ -4,18 +4,18 @@ function drawChart(type, chartID, dataSource, legendOnHover){ switch (typeof dataSource) { case 'string': - // get data with the given URL + // get data with the given URL d3.json(dataSource, function(error, response){ - if (error) { - // forward error to browser - throw error; - } - - if (!response || $.isEmptyObject(response)) { - // if there is no data to display - return; - } - + if (error) { + // forward error to browser + throw error; + } + + if (!response || $.isEmptyObject(response)) { + // if there is no data to display + return; + } + _drawChart(type, chartID, response.data, legendOnHover); }); break; @@ -29,48 +29,49 @@ * Prepares SVG area for drawing and runs concrete chart function. */ function _drawChart(type, chartID, rawData, legendOnHover) { - // clear previous chart + // clear previous chart var chartDiv = $('#' + chartID).empty().show(), - width = chartDiv.width(), - height = chartDiv.height(), - // add SVG elem - svg = d3.select(chartDiv[0]) - .append('svg') - .attr('width', width) - .attr('height', height); - // build domain out of keys - domainX = rawData.map(function(d) { return d.name }), - // 10 color palette - scaleColor = d3.scaleOrdinal(d3.schemeCategory10) - .domain(domainX), - legend = null; + width = chartDiv.width(), + //Changed for LDEV-4475 Missing information in Legend for Pie Chart when more than 7 items + height = chartDiv.height()*1.5, + // add SVG elem + svg = d3.select(chartDiv[0]) + .append('svg') + .attr('width', width) + .attr('height', height); + // build domain out of keys + domainX = rawData.map(function(d) { return d.name }), + // 10 color palette + scaleColor = d3.scaleOrdinal(d3.schemeCategory10) + .domain(domainX), + legend = null; + + if (!legendOnHover) { + legend = svg.append('g'); + // build legend first so we know how much space we've got for the chart + $.each(rawData, function(index, d){ + // a small rectangle with proper color + legend.append('rect') + .attr('x', 0) + .attr('y', index * 30) + .attr('width', 15) + .attr('height', 15) + .attr('fill', scaleColor(d.name)); + // label + legend.append('text') + .attr('x', 20) + .attr('y', index * 30 + 11) + .attr('text-anchor', 'start') + .text(d.name + ' (' + Math.round(+d.value) + ' %)'); + }); + } - if (!legendOnHover) { - legend = svg.append('g'); - // build legend first so we know how much space we've got for the chart - $.each(rawData, function(index, d){ - // a small rectangle with proper color - legend.append('rect') - .attr('x', 0) - .attr('y', index * 30) - .attr('width', 15) - .attr('height', 15) - .attr('fill', scaleColor(d.name)); - // label - legend.append('text') - .attr('x', 20) - .attr('y', index * 30 + 11) - .attr('text-anchor', 'start') - .text(d.name + ' (' + Math.round(+d.value) + '%)'); - }); - } - - // draw proper chart - if (type == 'bar') { + // draw proper chart + if (type == 'bar') { _drawBarChart(chartDiv, legend, width, height, rawData, domainX, scaleColor); - } else if (type == 'pie') { + } else if (type == 'pie') { _drawPieChart(chartDiv, legend, width, height, rawData, scaleColor); - } + } } // margins are needed so bar chart Y axis is not clipped @@ -135,7 +136,7 @@ tooltip.transition() .duration(200) .style('opacity', 1); - tooltip.text(d.name + ' (' + Math.round(+d.value) + '%)') + tooltip.text(d.name + ' (' + Math.round(+d.value) + ' %)') .style('left', +offset.left + box.width/2 - $(tooltip.node()).width()/2 - 22 + 'px') .style('top', +offset.top - 20 + 'px'); } @@ -201,7 +202,7 @@ tooltip.transition() .duration(200) .style('opacity', 1); - tooltip.text(d.data.name + ' (' + Math.round(+d.data.value) + '%)') + tooltip.text(d.data.name + ' (' + Math.round(+d.data.value) + ' %)') .style('left', +offset.left + box.width/2 + 'px') .style('top', +offset.top + box.height/2 + 'px'); } @@ -461,4 +462,5 @@ return focusbar; } -} \ No newline at end of file +} +