Browse Source

Fix legend

pull/1/head
Masayuki Tanaka 12 years ago committed by masayuki
parent
commit
0ac85b56df
  1. 37
      c3.js

37
c3.js

@ -1028,10 +1028,10 @@
.attr("class", function(d,i){ return "target-bar target-bar-" + i }) .attr("class", function(d,i){ return "target-bar target-bar-" + i })
.attr("x", barX).attr("y", height).attr("width", barW).attr("height", 0) .attr("x", barX).attr("y", height).attr("width", barW).attr("height", 0)
.style("opacity", 0) .style("opacity", 0)
.transition() .transition().duration(withTransition ? 100 : 0)
.attr('y', barY).attr('height', barH) .attr('y', barY).attr('height', barH)
.style('opacity', 1) .style('opacity', 1)
mainBar.exit().transition() mainBar.exit().transition().duration(withTransition ? 100 : 0)
.attr('y', height).attr('height', 0) .attr('y', height).attr('height', 0)
.style('opacity', 0) .style('opacity', 0)
.remove() .remove()
@ -1177,6 +1177,7 @@
function updateLegend (targets) { function updateLegend (targets) {
var ids = getTargetIds(targets), l var ids = getTargetIds(targets), l
var padding = width/2 - __legend_item_width*Object.keys(targets).length/2
// Define g for legend area // Define g for legend area
l = legend.selectAll('.legend-item') l = legend.selectAll('.legend-item')
@ -1200,37 +1201,25 @@
.style('opacity', 1) .style('opacity', 1)
c3.revert() c3.revert()
}) })
l.append('rect')
l.append('rect').classed("legend-item-event",true).attr('x', -200) .attr("class", "legend-item-event")
l.append('rect').classed("legend-item-tile",true).attr('x', -200)
l.append('text').attr('x', -200)
legend.selectAll('rect.legend-item-event')
.data(ids)
.style('fill-opacity', 0) .style('fill-opacity', 0)
.attr('x', -200)
.attr('y', function(){ return legendHeight/2 - 16 })
.attr('width', __legend_item_width) .attr('width', __legend_item_width)
.attr('height', 24) .attr('height', 24)
.attr('y', function(d,i){ return legendHeight/2 - 16 }) l.append('rect')
.attr("class", "legend-item-tile")
legend.selectAll('rect.legend-item-tile')
.data(ids)
.style('fill', function(d){ return color(d) }) .style('fill', function(d){ return color(d) })
.attr('x', -200)
.attr('y', function(){ return legendHeight/2 - 9 })
.attr('width', 10) .attr('width', 10)
.attr('height', 10) .attr('height', 10)
.attr('y', function(d,i){ return legendHeight/2 - 9 }) l.append('text')
legend.selectAll('text')
.data(ids)
.text(function(d){ return __data_names[d] }) .text(function(d){ return __data_names[d] })
.attr('x', -200)
.attr('y', function(d,i){ return legendHeight/2 }) .attr('y', function(d,i){ return legendHeight/2 })
updateLegend(targets)
}
function updateLegend (targets) {
var ids = getTargetIds(targets),
padding = width/2 - __legend_item_width*Object.keys(targets).length/2
legend.selectAll('rect.legend-item-event') legend.selectAll('rect.legend-item-event')
.data(ids) .data(ids)
.transition() .transition()

Loading…
Cancel
Save