Browse Source

fixed stacking of positive and negative bars. #616

flowchartTest
Alex de Mulder 9 years ago
parent
commit
8d48a9d5bf
3 changed files with 37 additions and 13 deletions
  1. +17
    -6
      dist/vis.js
  2. +1
    -1
      examples/graph2d/10_barsSideBySide.html
  3. +19
    -6
      lib/timeline/component/graph2d_types/bar.js

+ 17
- 6
dist/vis.js View File

@ -18777,8 +18777,13 @@ return /******/ (function(modules) { // webpackBootstrap
intersections[key].resolved += 1;
if (group.options.barChart.handleOverlap === 'stack') {
heightOffset = intersections[key].accumulated;
intersections[key].accumulated += group.zeroPosition - combinedData[i].y;
if (combinedData[i].y < group.zeroPosition) {
heightOffset = intersections[key].accumulatedNegative;
intersections[key].accumulatedNegative += group.zeroPosition - combinedData[i].y;
} else {
heightOffset = intersections[key].accumulatedPositive;
intersections[key].accumulatedPositive += group.zeroPosition - combinedData[i].y;
}
} else if (group.options.barChart.handleOverlap === 'sideBySide') {
drawData.width = drawData.width / intersections[key].amount;
drawData.offset += intersections[key].resolved * drawData.width - 0.5 * drawData.width * (intersections[key].amount + 1);
@ -18816,7 +18821,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
if (coreDistance === 0) {
if (intersections[combinedData[i].x] === undefined) {
intersections[combinedData[i].x] = { amount: 0, resolved: 0, accumulated: 0 };
intersections[combinedData[i].x] = { amount: 0, resolved: 0, accumulatedPositive: 0, accumulatedNegative: 0 };
}
intersections[combinedData[i].x].amount += 1;
}
@ -18886,13 +18891,19 @@ return /******/ (function(modules) { // webpackBootstrap
yMin = yMin > combinedData[i].y ? combinedData[i].y : yMin;
yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
} else {
intersections[key].accumulated += combinedData[i].y;
if (combinedData[i].y < 0) {
intersections[key].accumulatedNegative += combinedData[i].y;
} else {
intersections[key].accumulatedPositive += combinedData[i].y;
}
}
}
for (var xpos in intersections) {
if (intersections.hasOwnProperty(xpos)) {
yMin = yMin > intersections[xpos].accumulated ? intersections[xpos].accumulated : yMin;
yMax = yMax < intersections[xpos].accumulated ? intersections[xpos].accumulated : yMax;
yMin = yMin > intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMin;
yMin = yMin > intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMin;
yMax = yMax < intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMax;
yMax = yMax < intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMax;
}
}

+ 1
- 1
examples/graph2d/10_barsSideBySide.html View File

@ -40,7 +40,7 @@
{x: '2014-06-14', y: 10},
{x: '2014-06-15', y: 15},
{x: '2014-06-16', y: 30},
{x: '2014-06-11', y: 12},
{x: '2014-06-11', y: -12},
{x: '2014-06-14', y: 24},
{x: '2014-06-15', y: 5},
{x: '2014-06-16', y: 12}

+ 19
- 6
lib/timeline/component/graph2d_types/bar.js View File

@ -100,8 +100,14 @@ Bargraph.draw = function (groupIds, processedGroupData, framework) {
intersections[key].resolved += 1;
if (group.options.barChart.handleOverlap === 'stack') {
heightOffset = intersections[key].accumulated;
intersections[key].accumulated += group.zeroPosition - combinedData[i].y;
if (combinedData[i].y < group.zeroPosition) {
heightOffset = intersections[key].accumulatedNegative;
intersections[key].accumulatedNegative += group.zeroPosition - combinedData[i].y;
}
else {
heightOffset = intersections[key].accumulatedPositive;
intersections[key].accumulatedPositive += group.zeroPosition - combinedData[i].y;
}
}
else if (group.options.barChart.handleOverlap === 'sideBySide') {
drawData.width = drawData.width / intersections[key].amount;
@ -138,7 +144,7 @@ Bargraph._getDataIntersections = function (intersections, combinedData) {
}
if (coreDistance === 0) {
if (intersections[combinedData[i].x] === undefined) {
intersections[combinedData[i].x] = {amount: 0, resolved: 0, accumulated: 0};
intersections[combinedData[i].x] = {amount: 0, resolved: 0, accumulatedPositive: 0, accumulatedNegative: 0};
}
intersections[combinedData[i].x].amount += 1;
}
@ -214,13 +220,20 @@ Bargraph._getStackedBarYRange = function (intersections, combinedData) {
yMax = yMax < combinedData[i].y ? combinedData[i].y : yMax;
}
else {
intersections[key].accumulated += combinedData[i].y;
if (combinedData[i].y < 0) {
intersections[key].accumulatedNegative += combinedData[i].y;
}
else {
intersections[key].accumulatedPositive += combinedData[i].y;
}
}
}
for (var xpos in intersections) {
if (intersections.hasOwnProperty(xpos)) {
yMin = yMin > intersections[xpos].accumulated ? intersections[xpos].accumulated : yMin;
yMax = yMax < intersections[xpos].accumulated ? intersections[xpos].accumulated : yMax;
yMin = yMin > intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMin;
yMin = yMin > intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMin;
yMax = yMax < intersections[xpos].accumulatedNegative ? intersections[xpos].accumulatedNegative : yMax;
yMax = yMax < intersections[xpos].accumulatedPositive ? intersections[xpos].accumulatedPositive : yMax;
}
}

Loading…
Cancel
Save