|
|
@ -379,8 +379,12 @@ |
|
|
|
function maxDataCount () { |
|
|
|
function maxDataCount () { |
|
|
|
return d3.max(c3.data.targets, function(t){ return t.values.length }) |
|
|
|
return d3.max(c3.data.targets, function(t){ return t.values.length }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function getTargetIds (targets) { |
|
|
|
|
|
|
|
targets = (typeof targets === 'undefined') ? c3.data.targets : targets |
|
|
|
|
|
|
|
return targets.map(function(d){ return d.id; }) |
|
|
|
|
|
|
|
} |
|
|
|
function hasTarget (id) { |
|
|
|
function hasTarget (id) { |
|
|
|
var ids = c3.data.targets.map(function(d){ return d.id }), i |
|
|
|
var ids = getTargetIds(), i |
|
|
|
for (i = 0; i < ids.length; i++) { |
|
|
|
for (i = 0; i < ids.length; i++) { |
|
|
|
if (ids[i] === id) return true |
|
|
|
if (ids[i] === id) return true |
|
|
|
} |
|
|
|
} |
|
|
@ -425,6 +429,12 @@ |
|
|
|
|
|
|
|
|
|
|
|
//-- Type --//
|
|
|
|
//-- Type --//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setTargetType (targets, type) { |
|
|
|
|
|
|
|
var targetIds = typeof targets === 'undefined' ? getTargetIds() : targets |
|
|
|
|
|
|
|
for (var i = 0; i < targetIds.length; i++) { |
|
|
|
|
|
|
|
__data_types[targetIds[i]] = type |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
function isLineType (d) { |
|
|
|
function isLineType (d) { |
|
|
|
var id = (typeof d === 'string') ? d : d.id |
|
|
|
var id = (typeof d === 'string') ? d : d.id |
|
|
|
return !(id in __data_types) || __data_types[id] === 'line' |
|
|
|
return !(id in __data_types) || __data_types[id] === 'line' |
|
|
@ -433,7 +443,6 @@ |
|
|
|
var id = (typeof d === 'string') ? d : d.id |
|
|
|
var id = (typeof d === 'string') ? d : d.id |
|
|
|
return __data_types[id] === 'bar' |
|
|
|
return __data_types[id] === 'bar' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function lineData (d) { |
|
|
|
function lineData (d) { |
|
|
|
return isLineType(d) ? d.values : [] |
|
|
|
return isLineType(d) ? d.values : [] |
|
|
|
} |
|
|
|
} |
|
|
@ -1244,8 +1253,7 @@ |
|
|
|
/*-- Draw Legend --*/ |
|
|
|
/*-- Draw Legend --*/ |
|
|
|
|
|
|
|
|
|
|
|
function drawLegend (targets) { |
|
|
|
function drawLegend (targets) { |
|
|
|
var ids = targets.map(function(d){ return d.id }) |
|
|
|
var ids = getTargetIds(targets), l |
|
|
|
var l |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Define g for legend area
|
|
|
|
// Define g for legend area
|
|
|
|
l = legend.selectAll('.legend-item') |
|
|
|
l = legend.selectAll('.legend-item') |
|
|
@ -1297,7 +1305,7 @@ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function updateLegend (targets) { |
|
|
|
function updateLegend (targets) { |
|
|
|
var ids = targets.map(function(d){ return d.id }), |
|
|
|
var ids = getTargetIds(targets), |
|
|
|
padding = width/2 - __legend_item_width*Object.keys(targets).length/2 |
|
|
|
padding = width/2 - __legend_item_width*Object.keys(targets).length/2 |
|
|
|
|
|
|
|
|
|
|
|
legend.selectAll('rect.legend-item-event') |
|
|
|
legend.selectAll('rect.legend-item-event') |
|
|
@ -1445,13 +1453,13 @@ |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
c3.toLine = function (target) { |
|
|
|
c3.toLine = function (targets) { |
|
|
|
__data_types[target] = 'line' |
|
|
|
setTargetType(targets, 'line') |
|
|
|
update(true, true, true) |
|
|
|
update(true, true, true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
c3.toBar = function (target) { |
|
|
|
c3.toBar = function (targets) { |
|
|
|
__data_types[target] = 'bar' |
|
|
|
setTargetType(targets, 'bar') |
|
|
|
update(true, true, true) |
|
|
|
update(true, true, true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|