fixes, added about page

This commit is contained in:
2016-03-31 03:42:53 +02:00
parent a778eb6d64
commit 46d861e0dc
44 changed files with 4217 additions and 416 deletions
@@ -42,8 +42,6 @@
options = Chartist.extend({}, defaultOptions, options);
console.log(options);
return function ctAxisTitle(chart) {
chart.on('created', function (data) {
+38 -33
View File
@@ -253,13 +253,13 @@ var Chartist = {
* @memberof Chartist.Core
* @type {Object}
*/
Chartist.escapingMap = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
'\'': '&#039;'
};
// Chartist.escapingMap = {
// '&': '&amp;',
// '<': '&lt;',
// '>': '&gt;',
// '"': '&quot;',
// '\'': '&#039;'
// };
/**
* This function serializes arbitrary data to a string. In case of data that can't be easily converted to a string, this function will create a wrapper object and serialize the data using JSON.stringify. The outcoming string will always be escaped using Chartist.escapingMap.
@@ -278,9 +278,11 @@ var Chartist = {
data = JSON.stringify({data: data});
}
return Object.keys(Chartist.escapingMap).reduce(function(result, key) {
return Chartist.replaceAll(result, key, Chartist.escapingMap[key]);
}, data);
return _.escape(data);
// return Object.keys(Chartist.escapingMap).reduce(function(result, key) {
// return Chartist.replaceAll(result, key, Chartist.escapingMap[key]);
// }, data);
};
/**
@@ -295,9 +297,10 @@ var Chartist = {
return data;
}
data = Object.keys(Chartist.escapingMap).reduce(function(result, key) {
return Chartist.replaceAll(result, Chartist.escapingMap[key], key);
}, data);
// data = Object.keys(Chartist.escapingMap).reduce(function(result, key) {
// return Chartist.replaceAll(result, Chartist.escapingMap[key], key);
// }, data);
data = _.unescape(data);
try {
data = JSON.parse(data);
@@ -770,24 +773,24 @@ var Chartist = {
return bounds;
};
/**
* Calculate cartesian coordinates of polar coordinates
*
* @memberof Chartist.Core
* @param {Number} centerX X-axis coordinates of center point of circle segment
* @param {Number} centerY X-axis coordinates of center point of circle segment
* @param {Number} radius Radius of circle segment
* @param {Number} angleInDegrees Angle of circle segment in degrees
* @return {{x:Number, y:Number}} Coordinates of point on circumference
*/
Chartist.polarToCartesian = function (centerX, centerY, radius, angleInDegrees) {
var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
return {
x: centerX + (radius * Math.cos(angleInRadians)),
y: centerY + (radius * Math.sin(angleInRadians))
};
};
// /**
// * Calculate cartesian coordinates of polar coordinates
// *
// * @memberof Chartist.Core
// * @param {Number} centerX X-axis coordinates of center point of circle segment
// * @param {Number} centerY X-axis coordinates of center point of circle segment
// * @param {Number} radius Radius of circle segment
// * @param {Number} angleInDegrees Angle of circle segment in degrees
// * @return {{x:Number, y:Number}} Coordinates of point on circumference
// */
// Chartist.polarToCartesian = function (centerX, centerY, radius, angleInDegrees) {
// var angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
//
// return {
// x: centerX + (radius * Math.cos(angleInRadians)),
// y: centerY + (radius * Math.sin(angleInRadians))
// };
// };
/**
* Initialize chart drawing rectangle (area where chart is drawn) x1,y1 = bottom left / x2,y2 = top right
@@ -907,8 +910,10 @@ var Chartist = {
positionalData[axis.counterUnits.len] = axisOffset - 10;
var lblText = labels[index];
//round (!! will break for non-numeric)
lblText = Math.round(+lblText*100)/100;
if (_.isNumber(lblText)) {
lblText = Chartist.roundWithPrecision(lblText, 2);
}
if(useForeignObject) {
// We need to set width and height explicitly to px as span will not expand with width and height being
+243 -230
View File
@@ -1,272 +1,285 @@
(function (root, factory) {
// if (typeof define === 'function' && define.amd) {
// // AMD. Register as an anonymous module.
// define([], function () {
// return (root.returnExportsGlobal = factory());
// });
// } else if (typeof exports === 'object') {
// // Node. Does not work with strict CommonJS, but
// // only CommonJS-like enviroments that support module.exports,
// // like Node.
// module.exports = factory();
// } else {
root['Chartist.plugins.zoom'] = factory();
// }
// if (typeof define === 'function' && define.amd) {
// // AMD. Register as an anonymous module.
// define([], function () {
// return (root.returnExportsGlobal = factory());
// });
// } else if (typeof exports === 'object') {
// // Node. Does not work with strict CommonJS, but
// // only CommonJS-like enviroments that support module.exports,
// // like Node.
// module.exports = factory();
// } else {
root['Chartist.plugins.zoom'] = factory();
// }
}(this, function () {
/**
* Chartist.js zoom plugin.
*
*/
(function (window, document, Chartist) {
'use strict';
/**
* Chartist.js zoom plugin.
*
*/
(function (window, document, Chartist) {
'use strict';
var defaultOptions = {
// onZoom
// resetOnRightMouseBtn
};
var defaultOptions = {
// onZoom
// resetOnRightMouseBtn
};
Chartist.plugins = Chartist.plugins || {};
Chartist.plugins.zoom = function (options) {
Chartist.plugins = Chartist.plugins || {};
Chartist.plugins.zoom = function (options) {
options = Chartist.extend({}, defaultOptions, options);
options = Chartist.extend({}, defaultOptions, options);
return function zoom(chart) {
return function zoom(chart) {
if (!(chart instanceof Chartist.Line)) {
return;
}
if (!(chart instanceof Chartist.Line)) {
return;
}
var rect, svg, axisX, axisY, chartRect;
var downPosition;
var onZoom = options.onZoom;
var ongoingTouches = [];
var rect, svg, axisX, axisY, chartRect;
var downPosition;
var onZoom = options.onZoom;
var ongoingTouches = [];
chart.on('draw', function (data) {
var type = data.type;
if (type === 'line' || type === 'bar' || type === 'area' || type === 'point') {
data.element.attr({
'clip-path': 'url(#zoom-mask)'
});
}
});
chart.on('draw', function (data) {
var type = data.type;
if (type === 'line' || type === 'bar' || type === 'area' || type === 'point') {
data.element.attr({
'clip-path': 'url(#zoom-mask)'
});
}
});
chart.on('created', function (data) {
axisX = data.axisX;
axisY = data.axisY;
chartRect = data.chartRect;
svg = data.svg._node;
rect = data.svg.elem('rect', {
x: 10,
y: 10,
width: 100,
height: 100,
}, 'ct-zoom-rect');
hide(rect);
chart.on('created', function (data) {
axisX = data.axisX;
axisY = data.axisY;
chartRect = data.chartRect;
svg = data.svg._node;
rect = data.svg.elem('rect', {
x: 10,
y: 10,
width: 100,
height: 100,
}, 'ct-zoom-rect');
hide(rect);
var defs = data.svg.querySelector('defs') || data.svg.elem('defs');
var width = chartRect.width();
var height = chartRect.height();
var defs = data.svg.querySelector('defs') || data.svg.elem('defs');
var width = chartRect.width();
var height = chartRect.height();
defs
.elem('clipPath', {
id: 'zoom-mask'
})
.elem('rect', {
x: chartRect.x1,
y: chartRect.y2,
width: width,
height: height,
fill: 'white'
});
defs
.elem('clipPath', {
id: 'zoom-mask'
})
.elem('rect', {
x: chartRect.x1,
y: chartRect.y2,
width: width,
height: height,
fill: 'white'
});
svg.addEventListener('mousedown', onMouseDown);
svg.addEventListener('mouseup', onMouseUp);
svg.addEventListener('mousemove', onMouseMove);
svg.addEventListener('touchstart', onTouchStart);
svg.addEventListener('touchmove', onTouchMove);
svg.addEventListener('touchend', onTouchEnd);
svg.addEventListener('touchcancel', onTouchCancel);
});
svg.addEventListener('mousedown', onMouseDown);
svg.addEventListener('mouseup', onMouseUp);
svg.addEventListener('mousemove', onMouseMove);
svg.addEventListener('touchstart', onTouchStart);
svg.addEventListener('touchmove', onTouchMove);
svg.addEventListener('touchend', onTouchEnd);
svg.addEventListener('touchcancel', onTouchCancel);
});
function copyTouch(touch) {
var p = position(touch, svg);
p.id = touch.identifier;
return p;
}
function copyTouch(touch) {
var p = position(touch, svg);
p.id = touch.identifier;
return p;
}
function ongoingTouchIndexById(idToFind) {
for (var i = 0; i < ongoingTouches.length; i++) {
var id = ongoingTouches[i].id;
if (id === idToFind) {
return i;
}
}
return -1;
}
function ongoingTouchIndexById(idToFind) {
for (var i = 0; i < ongoingTouches.length; i++) {
var id = ongoingTouches[i].id;
if (id === idToFind) {
return i;
}
}
return -1;
}
function onTouchStart(event) {
var touches = event.changedTouches;
for (var i = 0; i < touches.length; i++) {
ongoingTouches.push(copyTouch(touches[i]));
}
function onTouchStart(event) {
var touches = event.changedTouches;
for (var i = 0; i < touches.length; i++) {
ongoingTouches.push(copyTouch(touches[i]));
}
if (ongoingTouches.length > 1) {
rect.attr(getRect(ongoingTouches[0], ongoingTouches[1]));
show(rect);
}
}
if (ongoingTouches.length > 1) {
rect.attr(getRect(ongoingTouches[0], ongoingTouches[1]));
show(rect);
}
}
function onTouchMove(event) {
var touches = event.changedTouches;
for (var i = 0; i < touches.length; i++) {
var idx = ongoingTouchIndexById(touches[i].identifier);
ongoingTouches.splice(idx, 1, copyTouch(touches[i]));
}
function onTouchMove(event) {
var touches = event.changedTouches;
for (var i = 0; i < touches.length; i++) {
var idx = ongoingTouchIndexById(touches[i].identifier);
ongoingTouches.splice(idx, 1, copyTouch(touches[i]));
}
if (ongoingTouches.length > 1) {
rect.attr(getRect(ongoingTouches[0], ongoingTouches[1]));
show(rect);
event.preventDefault();
}
}
if (ongoingTouches.length > 1) {
rect.attr(getRect(ongoingTouches[0], ongoingTouches[1]));
show(rect);
event.preventDefault();
}
}
function onTouchCancel(event) {
removeTouches(event.changedTouches);
}
function onTouchCancel(event) {
removeTouches(event.changedTouches);
}
function removeTouches(touches) {
for (var i = 0; i < touches.length; i++) {
var idx = ongoingTouchIndexById(touches[i].identifier);
if (idx >= 0) {
ongoingTouches.splice(idx, 1);
}
}
}
function removeTouches(touches) {
for (var i = 0; i < touches.length; i++) {
var idx = ongoingTouchIndexById(touches[i].identifier);
if (idx >= 0) {
ongoingTouches.splice(idx, 1);
}
}
}
function onTouchEnd(event) {
if (ongoingTouches.length > 1) {
zoomIn(getRect(ongoingTouches[0], ongoingTouches[1]));
}
removeTouches(event.changedTouches);
hide(rect);
}
function onTouchEnd(event) {
if (ongoingTouches.length > 1) {
zoomIn(getRect(ongoingTouches[0], ongoingTouches[1]));
}
removeTouches(event.changedTouches);
hide(rect);
}
function onMouseDown(event) {
if (event.button === 0) {
downPosition = position(event, svg);
rect.attr(getRect(downPosition, downPosition));
show(rect);
event.preventDefault();
}
}
function onMouseDown(event) {
if (event.button === 0) {
downPosition = position(event, svg);
rect.attr(getRect(downPosition, downPosition));
show(rect);
event.preventDefault();
}
}
var reset = function () {
chart.options.axisX.highLow = null;
chart.options.axisY.highLow = null;
chart.update(chart.data, chart.options);
};
var reset = function () {
chart.options.axisX.highLow = null;
chart.options.axisY.highLow = null;
chart.update(chart.data, chart.options);
};
function onMouseUp(event) {
if (event.button === 0) {
var box = getRect(downPosition, position(event, svg));
zoomIn(box);
downPosition = null;
hide(rect);
event.preventDefault();
}
else if (options.resetOnRightMouseBtn && event.button === 2) {
reset();
event.preventDefault();
}
}
function onMouseUp(event) {
if (event.button === 0) {
var box = getRect(downPosition, position(event, svg));
zoomIn(box);
downPosition = null;
hide(rect);
event.preventDefault();
}
else if (options.resetOnRightMouseBtn && event.button === 2) {
reset();
event.preventDefault();
}
}
function zoomIn(rect) {
if (rect.width > 5 && rect.height > 5) {
var x1 = rect.x - chartRect.x1;
var x2 = x1 + rect.width;
var y2 = chartRect.y1 - rect.y;
var y1 = y2 - rect.height;
function zoomIn(rect) {
if (rect.width > 5 && rect.height > 5) {
var x1 = rect.x - chartRect.x1;
var x2 = x1 + rect.width;
var y2 = chartRect.y1 - rect.y;
var y1 = y2 - rect.height;
chart.options.axisX.highLow = { low: project(x1, axisX), high: project(x2, axisX) };
chart.options.axisY.highLow = { low: project(y1, axisY), high: project(y2, axisY) };
var xLow = project(x1, axisX);
var xHigh = project(x2, axisX);
var yLow = project(y1, axisY);
var yHigh = project(y2, axisY);
chart.update(chart.data, chart.options);
onZoom && onZoom(chart, reset);
}
}
var explb = chart.options.explicitBounds;
if (!_.isUndefined(explb)) {
if (!_.isUndefined(explb.xLow)) xLow = Math.max(explb.xLow, xLow);
if (!_.isUndefined(explb.xHigh)) xHigh = Math.min(explb.xHigh, xHigh);
if (!_.isUndefined(explb.yLow)) yLow = Math.max(explb.yLow, yLow);
if (!_.isUndefined(explb.yHigh)) yHigh = Math.min(explb.yHigh, yHigh);
}
function onMouseMove(event) {
if (downPosition) {
var point = position(event, svg);
rect.attr(getRect(downPosition, point));
event.preventDefault();
}
}
};
chart.options.axisX.highLow = {low: xLow, high: xHigh};
chart.options.axisY.highLow = {low: yLow, high: yHigh};
};
chart.update(chart.data, chart.options);
onZoom && onZoom(chart, reset);
}
}
function hide(rect) {
rect.attr({ style: 'display:none' });
}
function onMouseMove(event) {
if (downPosition) {
var point = position(event, svg);
rect.attr(getRect(downPosition, point));
event.preventDefault();
}
}
};
function show(rect) {
rect.attr({ style: 'display:block' });
}
};
function getRect(firstPoint, secondPoint) {
var x = firstPoint.x;
var y = firstPoint.y;
var width = secondPoint.x - x;
var height = secondPoint.y - y;
if (width < 0) {
width = -width;
x = secondPoint.x;
}
if (height < 0) {
height = -height;
y = secondPoint.y;
}
return {
x: x,
y: y,
width: width,
height: height
};
}
function hide(rect) {
rect.attr({style: 'display:none'});
}
function position(event, svg) {
return transform(event.clientX, event.clientY, svg);
}
function show(rect) {
rect.attr({style: 'display:block'});
}
function transform(x, y, svgElement) {
var svg = svgElement.tagName === 'svg' ? svgElement : svgElement.ownerSVGElement;
var matrix = svg.getScreenCTM();
var point = svg.createSVGPoint();
point.x = x;
point.y = y;
point = point.matrixTransform(matrix.inverse());
return point || { x: 0, y: 0 };
}
function getRect(firstPoint, secondPoint) {
var x = firstPoint.x;
var y = firstPoint.y;
var width = secondPoint.x - x;
var height = secondPoint.y - y;
if (width < 0) {
width = -width;
x = secondPoint.x;
}
if (height < 0) {
height = -height;
y = secondPoint.y;
}
return {
x: x,
y: y,
width: width,
height: height
};
}
function project(value, axis) {
var max = axis.bounds.max;
var min = axis.bounds.min;
if (axis.scale && axis.scale.type === 'log') {
var base = axis.scale.base;
return Math.pow(base,
value * baseLog(max / min, base) / axis.axisLength) * min;
}
return (value * axis.bounds.range / axis.axisLength) + min;
}
function position(event, svg) {
return transform(event.clientX, event.clientY, svg);
}
function baseLog(val, base) {
return Math.log(val) / Math.log(base);
}
function transform(x, y, svgElement) {
var svg = svgElement.tagName === 'svg' ? svgElement : svgElement.ownerSVGElement;
var matrix = svg.getScreenCTM();
var point = svg.createSVGPoint();
point.x = x;
point.y = y;
point = point.matrixTransform(matrix.inverse());
return point || {x: 0, y: 0};
}
} (window, document, Chartist));
return Chartist.plugins.zoom;
function project(value, axis) {
var max = axis.bounds.max;
var min = axis.bounds.min;
if (axis.scale && axis.scale.type === 'log') {
var base = axis.scale.base;
return Math.pow(base,
value * baseLog(max / min, base) / axis.axisLength) * min;
}
return (value * axis.bounds.range / axis.axisLength) + min;
}
function baseLog(val, base) {
return Math.log(val) / Math.log(base);
}
}(window, document, Chartist));
return Chartist.plugins.zoom;
}));
File diff suppressed because it is too large Load Diff