@fishawack/lab-d3
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -46,2 +46,5 @@ { | ||
{ | ||
"name": "BarStacked" | ||
}, | ||
{ | ||
"name": "Block" | ||
@@ -48,0 +51,0 @@ }, |
@@ -57,2 +57,16 @@ (function (root, factory) { | ||
}, | ||
BarStacked: { | ||
class: require('charts/barstacked.js'), | ||
data: { | ||
}, | ||
att: { | ||
min: { | ||
y: 0 | ||
}, | ||
margin: { | ||
left: 40, | ||
bottom: 0 | ||
} | ||
} | ||
}, | ||
Block: { | ||
@@ -59,0 +73,0 @@ class: require('charts/block.js'), |
@@ -120,2 +120,11 @@ (function (root, factory) { | ||
// LOCAL VARIABLES | ||
var defineLocalVariables = function(d, i, element){ | ||
var _ = localVariables[i]; | ||
if(!_){ | ||
_ = localVariables[i] = {}; | ||
} | ||
}; | ||
[enter, anim].forEach(function(d){ | ||
@@ -210,26 +219,23 @@ d.attr("transform", function(d, i){ | ||
// If autoAxis null just call regular calculate | ||
if(!local.pA){ | ||
return Chart.prototype._calculateAxis.call(this, scale); | ||
} else { | ||
var calcHeight = 0; | ||
var height = 0; | ||
local.axisHeight = 0; | ||
if(att.label[scale]){ | ||
local.axisHeight = Shared.textHeight(chart, att.label[scale], local[local.pD]) + local.padding.space; | ||
} | ||
local.plotHeight = 0; | ||
// Get data in flat structure, all level 0's at levelData[0] cominbed etc | ||
var levelData = Shared.flattenValuesLengths(data, [], data.length); | ||
// Loop over each level of data backwards (top to bottom) as each level need previous levels width to calculate its own | ||
for(var levelIndex = levelData.length; levelIndex--;){ | ||
var outerPad = 0; | ||
var innerPad = (local.padding[levelIndex] == null) ? local.padding.inner : local.padding[levelIndex]; | ||
// LevelWidth either level above or total width - outer padding | ||
var levelWidth = 0; | ||
// If top level, then apply outer padding as percentage of width/height | ||
if(levelIndex === local.levels){ | ||
outerPad = local[local.pD] * local.padding.outer; | ||
var outerPad = local[local.pD] * local.padding.outer; | ||
levelWidth = local[local.pD] - (outerPad * 2); | ||
// Else get previous width from level above | ||
} else { | ||
@@ -239,12 +245,20 @@ levelWidth = local.levelWidth[levelIndex + 1]; | ||
// Calculate inner padding as percentage of levelWidth | ||
innerPad *= levelWidth; | ||
// Used to find biggest dataset at current levelIndex | ||
var biggestDataset = 0; | ||
if(levelIndex !== local.levels){ | ||
for(var i = levelData[levelIndex + 1].length; i--;){ | ||
if(levelData[levelIndex + 1][i].values.length > biggestDataset){ | ||
biggestDataset = levelData[levelIndex + 1][i].values.length; | ||
// Find biggest dataset at current levelIndex, need to loop through parents to check all dataset lengths for parent.values | ||
if(levelIndex !== local.levels/* && levelIndex !== 0*/){ | ||
var prevLevel = levelData[levelIndex + 1]; | ||
for(var i = prevLevel.length; i--;){ | ||
var prevLength = prevLevel[i].values.length; | ||
if(prevLength > biggestDataset){ | ||
biggestDataset = prevLength; | ||
} | ||
} | ||
// If top level then no parent and can 100% say current dataset is the biggest | ||
} else { | ||
@@ -254,3 +268,5 @@ biggestDataset = data.length; | ||
local.levelWidth[levelIndex] = (levelWidth - (innerPad * (biggestDataset - 1))) / biggestDataset; | ||
// Level width is biggestDataset / currentLevel - inner padding | ||
local.levelWidth[levelIndex] = levelWidth - (innerPad * (biggestDataset - 1)); | ||
local.levelWidth[levelIndex] /= biggestDataset; | ||
@@ -281,9 +297,12 @@ var biggest = 0; | ||
} | ||
local.plotHeight += local.levelHeight[levelIndex]; | ||
height += local.levelHeight[levelIndex]; | ||
} | ||
calcHeight += local.axisHeight; | ||
calcHeight += local.plotHeight; | ||
// Calculate axis label height | ||
if(att.label[scale]){ | ||
height += Shared.textHeight(chart, att.label[scale], local[local.pD]) + local.padding.space; | ||
} | ||
return calcHeight; | ||
return height; | ||
} | ||
@@ -290,0 +309,0 @@ }; |
@@ -50,3 +50,2 @@ (function (root, factory) { | ||
draw: null, | ||
axisHeight : 0, | ||
axis: { | ||
@@ -391,10 +390,2 @@ x: null, | ||
if(this._shared){ | ||
this._shared(enter, update, inner, anim, selection, localData, localIndex, levelIndex, hide, localFull, $._); | ||
if(att.inject.shared){ | ||
att.inject.shared.call(this, $); | ||
} | ||
} | ||
if(this['_level' + levelIndex]){ | ||
@@ -408,2 +399,10 @@ this['_level' + levelIndex](enter, update, inner, anim, selection, localData, localIndex, levelIndex, hide, localFull, $._); | ||
if(this._shared){ | ||
this._shared(enter, update, inner, anim, selection, localData, localIndex, levelIndex, hide, localFull, $._); | ||
if(att.inject.shared){ | ||
att.inject.shared.call(this, $); | ||
} | ||
} | ||
var that = this; | ||
@@ -780,12 +779,10 @@ | ||
var calcHeight = 0; | ||
var height = 0; | ||
local.axisHeight = 0; | ||
if(att.label[scale]){ | ||
local.axisHeight = Shared.textHeight(chart, att.label[scale], local[(scale === 'x') ? 'width' : 'height']) + local.padding.space; | ||
height += Shared.textHeight(chart, att.label[scale], local[(scale === 'x') ? 'width' : 'height']) + local.padding.space; | ||
} | ||
if(att.axis[scale].tickSizeInner > 0){ | ||
local.axisHeight += att.axis[scale].tickSizeInner * ((att.axis[scale].ratio) ? att.width : 1); | ||
height += att.axis[scale].tickSizeInner * ((att.axis[scale].ratio) ? att.width : 1); | ||
} | ||
@@ -810,8 +807,5 @@ | ||
// Don't add spacing if height is 0 | ||
local.plotHeight = (biggest) ? biggest + local.padding.space : 0; | ||
height += (biggest) ? biggest + local.padding.space : 0; | ||
calcHeight += local.axisHeight; | ||
calcHeight += local.plotHeight; | ||
return calcHeight; | ||
return height; | ||
}; | ||
@@ -818,0 +812,0 @@ |
{ | ||
"name": "@fishawack/lab-d3", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Abstract layer built on top of d3", | ||
@@ -5,0 +5,0 @@ "vars": { |
Sorry, the diff of this file is not supported yet
2499958
146
79212