Browse Source

Introducing "point" style as new label for "points", consistency in naming.

Some fixes and cleanups after the large rewrite.
codeClimate
Ludo Stellingwerff 8 years ago
parent
commit
95d46a3d54
4 changed files with 47 additions and 20 deletions
  1. +2
    -1
      lib/timeline/component/GraphGroup.js
  2. +5
    -3
      lib/timeline/component/LineGraph.js
  3. +40
    -15
      lib/timeline/component/graph2d_types/bar.js
  4. +0
    -1
      lib/timeline/component/graph2d_types/points.js

+ 2
- 1
lib/timeline/component/GraphGroup.js View File

@ -134,7 +134,8 @@ GraphGroup.prototype.getLegend = function (iconWidth, iconHeight, framework, x,
case "line": case "line":
Lines.drawIcon(this, x, y, iconWidth, iconHeight, framework); Lines.drawIcon(this, x, y, iconWidth, iconHeight, framework);
break; break;
case "points":
case "points": //explicit no break
case "point":
Points.drawIcon(this, x, y, iconWidth, iconHeight, framework); Points.drawIcon(this, x, y, iconWidth, iconHeight, framework);
break; break;
case "bar": case "bar":

+ 5
- 3
lib/timeline/component/LineGraph.js View File

@ -333,8 +333,8 @@ LineGraph.prototype.setGroups = function (groups) {
// remove all drawn groups // remove all drawn groups
ids = this.groupsData.getIds(); ids = this.groupsData.getIds();
this.groupsData = null; this.groupsData = null;
for (var i = 0; i < groupIds.length; i++) {
this._removeGroup(groupIds[i]);
for (var i = 0; i < ids.length; i++) {
this._removeGroup(ids[i]);
} }
} }
@ -733,8 +733,10 @@ LineGraph.prototype._updateGraph = function () {
} }
Lines.draw(paths[groupIds[i]], group, this.framework); Lines.draw(paths[groupIds[i]], group, this.framework);
//explicit no break; //explicit no break;
case "point":
//explicit no break;
case "points": case "points":
if (group.options.style == "points" || group.options.drawPoints.enabled == true) {
if (group.options.style == "point" || group.options.style == "points" || group.options.drawPoints.enabled == true) {
Points.draw(groupsData[groupIds[i]], group, this.framework); Points.draw(groupsData[groupIds[i]], group, this.framework);
} }
break; break;

+ 40
- 15
lib/timeline/component/graph2d_types/bar.js View File

@ -16,6 +16,8 @@ Bargraph.drawIcon = function (group, x, y, iconWidth, iconHeight, framework) {
outline.setAttributeNS(null, "class", "vis-outline"); outline.setAttributeNS(null, "class", "vis-outline");
var barWidth = Math.round(0.3 * iconWidth); var barWidth = Math.round(0.3 * iconWidth);
var originalWidth = group.options.barChart.width;
var scale = originalWidth / barWidth;
var bar1Height = Math.round(0.4 * iconHeight); var bar1Height = Math.round(0.4 * iconHeight);
var bar2Height = Math.round(0.75 * iconHeight); var bar2Height = Math.round(0.75 * iconHeight);
@ -28,7 +30,7 @@ Bargraph.drawIcon = function (group, x, y, iconWidth, iconHeight, framework) {
var groupTemplate = { var groupTemplate = {
style: group.options.drawPoints.style, style: group.options.drawPoints.style,
styles: group.options.drawPoints.styles, styles: group.options.drawPoints.styles,
size: Math.max(barWidth/5,group.options.drawPoints.size),
size: (group.options.drawPoints.size / scale),
className: group.className className: group.className
}; };
DOMutil.drawPoint(x + 0.5 * barWidth + offset, y + fillHeight - bar1Height - 1, groupTemplate, framework.svgElements, framework.svg); DOMutil.drawPoint(x + 0.5 * barWidth + offset, y + fillHeight - bar1Height - 1, groupTemplate, framework.svgElements, framework.svg);
@ -49,7 +51,7 @@ Bargraph.draw = function (groupIds, processedGroupData, framework) {
var coreDistance; var coreDistance;
var key, drawData; var key, drawData;
var group; var group;
var i,j;
var i, j;
var barPoints = 0; var barPoints = 0;
// combine all barchart data // combine all barchart data
@ -61,6 +63,8 @@ Bargraph.draw = function (groupIds, processedGroupData, framework) {
combinedData.push({ combinedData.push({
screen_x: processedGroupData[groupIds[i]][j].screen_x, screen_x: processedGroupData[groupIds[i]][j].screen_x,
screen_y: processedGroupData[groupIds[i]][j].screen_y, screen_y: processedGroupData[groupIds[i]][j].screen_y,
x: processedGroupData[groupIds[i]][j].x,
y: processedGroupData[groupIds[i]][j].y,
groupId: groupIds[i], groupId: groupIds[i],
label: processedGroupData[groupIds[i]][j].label label: processedGroupData[groupIds[i]][j].label
}); });
@ -70,7 +74,9 @@ Bargraph.draw = function (groupIds, processedGroupData, framework) {
} }
} }
if (barPoints === 0) {return;}
if (barPoints === 0) {
return;
}
// sort by time and by group // sort by time and by group
combinedData.sort(function (a, b) { combinedData.sort(function (a, b) {
@ -93,15 +99,23 @@ Bargraph.draw = function (groupIds, processedGroupData, framework) {
key = combinedData[i].screen_x; key = combinedData[i].screen_x;
var heightOffset = 0; var heightOffset = 0;
if (intersections[key] === undefined) { if (intersections[key] === undefined) {
if (i+1 < combinedData.length) {coreDistance = Math.abs(combinedData[i+1].screen_x - key);}
if (i > 0) {coreDistance = Math.min(coreDistance,Math.abs(combinedData[i-1].screen_x - key));}
if (i + 1 < combinedData.length) {
coreDistance = Math.abs(combinedData[i + 1].screen_x - key);
}
if (i > 0) {
coreDistance = Math.min(coreDistance, Math.abs(combinedData[i - 1].screen_x - key));
}
drawData = Bargraph._getSafeDrawData(coreDistance, group, minWidth); drawData = Bargraph._getSafeDrawData(coreDistance, group, minWidth);
} }
else { else {
var nextKey = i + (intersections[key].amount - intersections[key].resolved); var nextKey = i + (intersections[key].amount - intersections[key].resolved);
var prevKey = i - (intersections[key].resolved + 1); var prevKey = i - (intersections[key].resolved + 1);
if (nextKey < combinedData.length) {coreDistance = Math.abs(combinedData[nextKey].screen_x - key);}
if (prevKey > 0) {coreDistance = Math.min(coreDistance,Math.abs(combinedData[prevKey].screen_x - key));}
if (nextKey < combinedData.length) {
coreDistance = Math.abs(combinedData[nextKey].screen_x - key);
}
if (prevKey > 0) {
coreDistance = Math.min(coreDistance, Math.abs(combinedData[prevKey].screen_x - key));
}
drawData = Bargraph._getSafeDrawData(coreDistance, group, minWidth); drawData = Bargraph._getSafeDrawData(coreDistance, group, minWidth);
intersections[key].resolved += 1; intersections[key].resolved += 1;
@ -117,17 +131,23 @@ Bargraph.draw = function (groupIds, processedGroupData, framework) {
} }
else if (group.options.barChart.sideBySide === true) { else if (group.options.barChart.sideBySide === true) {
drawData.width = drawData.width / intersections[key].amount; drawData.width = drawData.width / intersections[key].amount;
drawData.offset += (intersections[key].resolved) * drawData.width - (0.5*drawData.width * (intersections[key].amount+1));
if (group.options.barChart.align === 'left') {drawData.offset -= 0.5*drawData.width;}
else if (group.options.barChart.align === 'right') {drawData.offset += 0.5*drawData.width;}
drawData.offset += (intersections[key].resolved) * drawData.width - (0.5 * drawData.width * (intersections[key].amount + 1));
if (group.options.barChart.align === 'left') {
drawData.offset -= 0.5 * drawData.width;
}
else if (group.options.barChart.align === 'right') {
drawData.offset += 0.5 * drawData.width;
}
} }
} }
DOMutil.drawBar(combinedData[i].screen_x + drawData.offset, combinedData[i].screen_y - heightOffset, drawData.width, group.zeroPosition - combinedData[i].screen_y, group.className + ' vis-bar', framework.svgElements, framework.svg, group.style); DOMutil.drawBar(combinedData[i].screen_x + drawData.offset, combinedData[i].screen_y - heightOffset, drawData.width, group.zeroPosition - combinedData[i].screen_y, group.className + ' vis-bar', framework.svgElements, framework.svg, group.style);
// draw points // draw points
if (group.options.drawPoints.enabled === true) { if (group.options.drawPoints.enabled === true) {
let pointData = { let pointData = {
screen_x:combinedData[i].screen_x,
screen_y:combinedData[i].screen_y - heightOffset,
screen_x: combinedData[i].screen_x,
screen_y: combinedData[i].screen_y - heightOffset,
x: combinedData[i].x,
y: combinedData[i].y,
groupId: combinedData[i].groupId, groupId: combinedData[i].groupId,
label: combinedData[i].label label: combinedData[i].label
}; };
@ -156,7 +176,12 @@ Bargraph._getDataIntersections = function (intersections, combinedData) {
} }
if (coreDistance === 0) { if (coreDistance === 0) {
if (intersections[combinedData[i].screen_x] === undefined) { if (intersections[combinedData[i].screen_x] === undefined) {
intersections[combinedData[i].screen_x] = {amount: 0, resolved: 0, accumulatedPositive: 0, accumulatedNegative: 0};
intersections[combinedData[i].screen_x] = {
amount: 0,
resolved: 0,
accumulatedPositive: 0,
accumulatedNegative: 0
};
} }
intersections[combinedData[i].screen_x].amount += 1; intersections[combinedData[i].screen_x].amount += 1;
} }
@ -201,13 +226,13 @@ Bargraph._getSafeDrawData = function (coreDistance, group, minWidth) {
return {width: width, offset: offset}; return {width: width, offset: offset};
}; };
Bargraph.getStackedYRange = function(combinedData, groupRanges, groupIds, groupLabel, orientation) {
Bargraph.getStackedYRange = function (combinedData, groupRanges, groupIds, groupLabel, orientation) {
if (combinedData.length > 0) { if (combinedData.length > 0) {
// sort by time and by group // sort by time and by group
combinedData.sort(function (a, b) { combinedData.sort(function (a, b) {
if (a.screen_x === b.screen_x) { if (a.screen_x === b.screen_x) {
return a.groupId < b.groupId ? -1 : 1; return a.groupId < b.groupId ? -1 : 1;
}
}
else { else {
return a.screen_x - b.screen_x; return a.screen_x - b.screen_x;
} }

+ 0
- 1
lib/timeline/component/graph2d_types/points.js View File

@ -66,7 +66,6 @@ function getCallback(framework, group) {
if (group.group.options && group.group.options.drawPoints && group.group.options.drawPoints.onRender && typeof group.group.options.drawPoints.onRender == 'function') { if (group.group.options && group.group.options.drawPoints && group.group.options.drawPoints.onRender && typeof group.group.options.drawPoints.onRender == 'function') {
callback = group.group.options.drawPoints.onRender; callback = group.group.options.drawPoints.onRender;
} }
return callback; return callback;
} }

Loading…
Cancel
Save