Option to mask x-axis

This commit is contained in:
Phyks 2014-03-28 20:52:04 +01:00
parent 91f719010d
commit 8ce80b2979
2 changed files with 21 additions and 13 deletions

View File

@ -7,7 +7,7 @@
} }
</style> </style>
</head> </head>
<body onload="SVG.init('holder', '100%', '100%', 'both', true); SVG.addPoints([{'x':50, 'y':50, 'label':'test'},{'x':100, 'y':100, 'label':'test2'},{'x':150,'y':25, 'label':'test3'},{'x':175, 'y':-200, 'label':'test4'}]); SVG.draw();"> <body onload="SVG.init('holder', '100%', '100%', 'both', true, true); SVG.addPoints([{'x':50, 'y':50, 'label':'test'},{'x':100, 'y':100, 'label':'test2'},{'x':150,'y':25, 'label':'test3'},{'x':175, 'y':-200, 'label':'test4'}]); SVG.draw();">
<div id="holder"></div> <div id="holder"></div>
<script type="text/javascript" src="../timeline.js"></script> <script type="text/javascript" src="../timeline.js"></script>
</body> </body>

View File

@ -6,20 +6,21 @@ SVG.marginBottom = 10;
SVG.marginTop = 10; SVG.marginTop = 10;
SVG.marginLeft = 10; SVG.marginLeft = 10;
SVG.marginRight = 10; SVG.marginRight = 10;
SVG.rounded = false;
SVG.x_axis = false;
SVG.holder = false; SVG.holder = false;
SVG.g = false; SVG.g = false;
SVG.axis = false; SVG.axis = false;
SVG.raw_points = []; SVG.raw_points = [];
SVG.labels = []; SVG.labels = [];
SVG.rounded = false;
/* Initialization : /* Initialization :
* id = id of the parent block * id = id of the parent block
* height / width = size of the svg * height / width = size of the svg
* grid = small / big / both * grid = small / big / both
*/ */
SVG.init = function (id, height, width, grid, rounded) SVG.init = function (id, height, width, grid, x_axis, rounded)
{ {
var holder = document.getElementById(id); var holder = document.getElementById(id);
@ -102,6 +103,7 @@ SVG.init = function (id, height, width, grid, rounded)
SVG.g.setAttribute('transform', 'translate(0, ' + holder.offsetHeight + ') scale(1, -1)'); SVG.g.setAttribute('transform', 'translate(0, ' + holder.offsetHeight + ') scale(1, -1)');
SVG.holder.appendChild(SVG.g); SVG.holder.appendChild(SVG.g);
if(x_axis === true) {
SVG.axis = document.createElementNS(SVG.ns, 'line'); SVG.axis = document.createElementNS(SVG.ns, 'line');
SVG.axis.setAttribute('x1', SVG.marginLeft); SVG.axis.setAttribute('x1', SVG.marginLeft);
SVG.axis.setAttribute('x2', holder.offsetWidth - 13 - SVG.marginRight); SVG.axis.setAttribute('x2', holder.offsetWidth - 13 - SVG.marginRight);
@ -109,8 +111,10 @@ SVG.init = function (id, height, width, grid, rounded)
SVG.axis.setAttribute('stroke-width', 3); SVG.axis.setAttribute('stroke-width', 3);
SVG.axis.setAttribute('marker-end', 'url("#markerArrow")'); SVG.axis.setAttribute('marker-end', 'url("#markerArrow")');
SVG.g.appendChild(SVG.axis); SVG.g.appendChild(SVG.axis);
}
SVG.rounded = rounded; SVG.rounded = rounded;
SVG.x_axis = x_axis;
} }
SVG.newCoordinates = function(value, min, max, minValue, maxValue) { SVG.newCoordinates = function(value, min, max, minValue, maxValue) {
@ -143,8 +147,10 @@ SVG.scale = function(data) {
} }
/* Draw axis */ /* Draw axis */
if(SVG.x_axis === true) {
SVG.axis.setAttribute('y1', SVG.newCoordinates(0, minY, maxY, SVG.marginBottom, SVG.holder.parentElement.offsetHeight - SVG.marginTop)); SVG.axis.setAttribute('y1', SVG.newCoordinates(0, minY, maxY, SVG.marginBottom, SVG.holder.parentElement.offsetHeight - SVG.marginTop));
SVG.axis.setAttribute('y2', SVG.newCoordinates(0, minY, maxY, SVG.marginBottom, SVG.holder.parentElement.offsetHeight - SVG.marginTop)); SVG.axis.setAttribute('y2', SVG.newCoordinates(0, minY, maxY, SVG.marginBottom, SVG.holder.parentElement.offsetHeight - SVG.marginTop));
}
var returned = new Array(); var returned = new Array();
returned['minX'] = minX; returned['minX'] = minX;
@ -336,7 +342,9 @@ window.onresize = function() {
old(); old();
if(SVG.g !== false) { if(SVG.g !== false) {
SVG.g.setAttribute('transform', 'translate(0, ' + SVG.holder.parentElement.offsetHeight + ') scale(1, -1)'); SVG.g.setAttribute('transform', 'translate(0, ' + SVG.holder.parentElement.offsetHeight + ') scale(1, -1)');
if(SVG.x_axis === true) {
SVG.axis.setAttribute('x2', holder.offsetWidth - 13 - SVG.marginRight); SVG.axis.setAttribute('x2', holder.offsetWidth - 13 - SVG.marginRight);
}
[].forEach.call(SVG.holder.querySelectorAll('.label, .over, .point, .line, .graph'), function(el) { [].forEach.call(SVG.holder.querySelectorAll('.label, .over, .point, .line, .graph'), function(el) {
el.parentElement.removeChild(el); el.parentElement.removeChild(el);
}); });