|
@ -1,5 +1,8 @@ |
|
|
var util = require('../../util'); |
|
|
var util = require('../../util'); |
|
|
var DOMutil = require('../../DOMutil'); |
|
|
var DOMutil = require('../../DOMutil'); |
|
|
|
|
|
var Bars = require('./graph2d_types/bar'); |
|
|
|
|
|
var Lines = require('./graph2d_types/line'); |
|
|
|
|
|
var Points = require('./graph2d_types/points'); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* /** |
|
|
* /** |
|
@ -120,79 +123,6 @@ GraphGroup.prototype.update = function (group) { |
|
|
this.setOptions(group.options); |
|
|
this.setOptions(group.options); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: move these render functions into the type specific files and call them from LineGraph
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* draw the icon for the legend. |
|
|
|
|
|
* |
|
|
|
|
|
* @param x |
|
|
|
|
|
* @param y |
|
|
|
|
|
* @param JSONcontainer |
|
|
|
|
|
* @param SVGcontainer |
|
|
|
|
|
* @param iconWidth |
|
|
|
|
|
* @param iconHeight |
|
|
|
|
|
*/ |
|
|
|
|
|
GraphGroup.prototype.drawIcon = function (x, y, JSONcontainer, SVGcontainer, iconWidth, iconHeight) { |
|
|
|
|
|
var fillHeight = iconHeight * 0.5; |
|
|
|
|
|
var path, fillPath; |
|
|
|
|
|
|
|
|
|
|
|
var outline = DOMutil.getSVGElement("rect", JSONcontainer, SVGcontainer); |
|
|
|
|
|
outline.setAttributeNS(null, "x", x); |
|
|
|
|
|
outline.setAttributeNS(null, "y", y - fillHeight); |
|
|
|
|
|
outline.setAttributeNS(null, "width", iconWidth); |
|
|
|
|
|
outline.setAttributeNS(null, "height", 2 * fillHeight); |
|
|
|
|
|
outline.setAttributeNS(null, "class", "vis-outline"); |
|
|
|
|
|
|
|
|
|
|
|
if (this.options.style == 'line') { |
|
|
|
|
|
path = DOMutil.getSVGElement("path", JSONcontainer, SVGcontainer); |
|
|
|
|
|
path.setAttributeNS(null, "class", this.className); |
|
|
|
|
|
if (this.style !== undefined) { |
|
|
|
|
|
path.setAttributeNS(null, "style", this.style); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
path.setAttributeNS(null, "d", "M" + x + "," + y + " L" + (x + iconWidth) + "," + y + ""); |
|
|
|
|
|
if (this.options.shaded.enabled == true) { |
|
|
|
|
|
fillPath = DOMutil.getSVGElement("path", JSONcontainer, SVGcontainer); |
|
|
|
|
|
if (this.options.shaded.orientation == 'top') { |
|
|
|
|
|
fillPath.setAttributeNS(null, "d", "M" + x + ", " + (y - fillHeight) + |
|
|
|
|
|
"L" + x + "," + y + " L" + (x + iconWidth) + "," + y + " L" + (x + iconWidth) + "," + (y - fillHeight)); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
fillPath.setAttributeNS(null, "d", "M" + x + "," + y + " " + |
|
|
|
|
|
"L" + x + "," + (y + fillHeight) + " " + |
|
|
|
|
|
"L" + (x + iconWidth) + "," + (y + fillHeight) + |
|
|
|
|
|
"L" + (x + iconWidth) + "," + y); |
|
|
|
|
|
} |
|
|
|
|
|
fillPath.setAttributeNS(null, "class", this.className + " vis-icon-fill"); |
|
|
|
|
|
if (this.options.shaded.style !== undefined && this.options.shaded.style !== "") { |
|
|
|
|
|
fillPath.setAttributeNS(null, "style", this.options.shaded.style); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.options.drawPoints.enabled == true) { |
|
|
|
|
|
var groupTemplate = { |
|
|
|
|
|
style: this.options.drawPoints.style, |
|
|
|
|
|
styles: this.options.drawPoints.styles, |
|
|
|
|
|
size: this.options.drawPoints.size, |
|
|
|
|
|
className: this.className |
|
|
|
|
|
}; |
|
|
|
|
|
DOMutil.drawPoint(x + 0.5 * iconWidth, y, groupTemplate, JSONcontainer, SVGcontainer); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
var barWidth = Math.round(0.3 * iconWidth); |
|
|
|
|
|
var bar1Height = Math.round(0.4 * iconHeight); |
|
|
|
|
|
var bar2Height = Math.round(0.75 * iconHeight); |
|
|
|
|
|
|
|
|
|
|
|
var offset = Math.round((iconWidth - (2 * barWidth)) / 3); |
|
|
|
|
|
|
|
|
|
|
|
DOMutil.drawBar(x + 0.5 * barWidth + offset, y + fillHeight - bar1Height - 1, barWidth, bar1Height, this.className + ' vis-bar', JSONcontainer, SVGcontainer, this.style); |
|
|
|
|
|
DOMutil.drawBar(x + 1.5 * barWidth + offset + 2, y + fillHeight - bar2Height - 1, barWidth, bar2Height, this.className + ' vis-bar', JSONcontainer, SVGcontainer, this.style); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* return the legend entree for this group. |
|
|
* return the legend entree for this group. |
|
|
* |
|
|
* |
|
@ -200,10 +130,29 @@ GraphGroup.prototype.drawIcon = function (x, y, JSONcontainer, SVGcontainer, ico |
|
|
* @param iconHeight |
|
|
* @param iconHeight |
|
|
* @returns {{icon: HTMLElement, label: (group.content|*|string), orientation: (.options.yAxisOrientation|*)}} |
|
|
* @returns {{icon: HTMLElement, label: (group.content|*|string), orientation: (.options.yAxisOrientation|*)}} |
|
|
*/ |
|
|
*/ |
|
|
GraphGroup.prototype.getLegend = function (iconWidth, iconHeight) { |
|
|
|
|
|
var svg = document.createElementNS('http://www.w3.org/2000/svg', "svg"); |
|
|
|
|
|
this.drawIcon(0, 0.5 * iconHeight, [], svg, iconWidth, iconHeight); |
|
|
|
|
|
return {icon: svg, label: this.content, orientation: this.options.yAxisOrientation}; |
|
|
|
|
|
|
|
|
GraphGroup.prototype.getLegend = function (iconWidth, iconHeight, framework, x, y) { |
|
|
|
|
|
if (framework == undefined || framework == null) { |
|
|
|
|
|
var svg = document.createElementNS('http://www.w3.org/2000/svg', "svg"); |
|
|
|
|
|
framework = {svg: svg, svgElements:{}, options: this.options, groups: [this]} |
|
|
|
|
|
} |
|
|
|
|
|
if (x == undefined || x == null){ |
|
|
|
|
|
x = 0; |
|
|
|
|
|
} |
|
|
|
|
|
if (y == undefined || y == null){ |
|
|
|
|
|
y = 0.5 * iconHeight; |
|
|
|
|
|
} |
|
|
|
|
|
switch (this.options.style){ |
|
|
|
|
|
case "line": |
|
|
|
|
|
Lines.drawIcon(this, x, y, iconWidth, iconHeight, framework); |
|
|
|
|
|
break; |
|
|
|
|
|
case "points": |
|
|
|
|
|
Points.drawIcon(this, x, y, iconWidth, iconHeight, framework); |
|
|
|
|
|
break; |
|
|
|
|
|
case "bar": |
|
|
|
|
|
Bars.drawIcon(this, x, y, iconWidth, iconHeight, framework); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
return {icon: framework.svg, label: this.content, orientation: this.options.yAxisOrientation}; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
GraphGroup.prototype.getYRange = function (groupData) { |
|
|
GraphGroup.prototype.getYRange = function (groupData) { |
|
|