fixes, added about page
This commit is contained in:
@@ -42,8 +42,6 @@
|
||||
|
||||
options = Chartist.extend({}, defaultOptions, options);
|
||||
|
||||
console.log(options);
|
||||
|
||||
return function ctAxisTitle(chart) {
|
||||
|
||||
chart.on('created', function (data) {
|
||||
|
||||
@@ -253,13 +253,13 @@ var Chartist = {
|
||||
* @memberof Chartist.Core
|
||||
* @type {Object}
|
||||
*/
|
||||
Chartist.escapingMap = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
'\'': '''
|
||||
};
|
||||
// Chartist.escapingMap = {
|
||||
// '&': '&',
|
||||
// '<': '<',
|
||||
// '>': '>',
|
||||
// '"': '"',
|
||||
// '\'': '''
|
||||
// };
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -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
@@ -2,50 +2,98 @@ var page_waveform = (function () {
|
||||
var wfm = {};
|
||||
|
||||
var zoomResetFn;
|
||||
var dataFormat;
|
||||
|
||||
function buildChart(obj, xlabel, ylabel) {
|
||||
var points = [];
|
||||
obj.samples.forEach(function (a, i) {
|
||||
points.push({x: i, y: a});
|
||||
});
|
||||
var readoutPending = false;
|
||||
var autoReload = false;
|
||||
var autoReloadTime = 1;
|
||||
var arTimeout = -1;
|
||||
|
||||
var zoomSavedX, zoomSavedY;
|
||||
|
||||
function buildChart(j) {
|
||||
// Build the chart
|
||||
var plugins = [];
|
||||
var mql = window.matchMedia('screen and (min-width: 544px)');
|
||||
var isPhone = !mql.matches;
|
||||
|
||||
if (!isPhone) {
|
||||
// larger than phone
|
||||
plugins.push(
|
||||
Chartist.plugins.ctAxisTitle({
|
||||
axisX: {
|
||||
axisTitle: xlabel,
|
||||
offset: {
|
||||
x: 0,
|
||||
y: 55
|
||||
}
|
||||
},
|
||||
axisY: {
|
||||
axisTitle: ylabel,
|
||||
flipText: true,
|
||||
offset: {
|
||||
x: 0,
|
||||
y: 15
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
var fft = (j.stats.format == 'FFT');
|
||||
|
||||
var xLabel, yLabel;
|
||||
if (fft) {
|
||||
xLabel = 'Frequency - [ Hz ]';
|
||||
yLabel = 'Magnitude - [ mA ]';
|
||||
} else {
|
||||
xLabel = 'Sample time - [ ms ]';
|
||||
yLabel = 'Current - [ mA ]';
|
||||
}
|
||||
|
||||
// zoom
|
||||
plugins.push(Chartist.plugins.zoom({
|
||||
resetOnRightMouseBtn:true,
|
||||
onZoom: function(chart, reset) {
|
||||
zoomResetFn = reset;
|
||||
}
|
||||
}));
|
||||
var peak = Math.max(-j.stats.min, j.stats.max);
|
||||
var displayPeak = Math.max(peak, 10);
|
||||
|
||||
var peak = obj.stats.peak;
|
||||
// Sidebar
|
||||
|
||||
$('#stat-count').html(j.stats.count);
|
||||
$('#stat-f-s').html(j.stats.freq);
|
||||
$('#stat-i-peak').html(peak);
|
||||
$('#stat-i-rms').html(j.stats.rms);
|
||||
$('.stats').removeClass('invis');
|
||||
|
||||
// --- chart ---
|
||||
|
||||
// Generate point entries
|
||||
// add synthetic properties
|
||||
var step = fft ? (j.stats.freq/j.stats.count) : (1000/j.stats.freq);
|
||||
var points = _.map(j.samples, function (a, i) {
|
||||
return {
|
||||
x: i * step,
|
||||
y: a
|
||||
};
|
||||
});
|
||||
|
||||
var plugins = [
|
||||
Chartist.plugins.zoom({
|
||||
resetOnRightMouseBtn: true,
|
||||
onZoom: function (chart, reset) {
|
||||
zoomResetFn = reset;
|
||||
|
||||
zoomSavedX = chart.options.axisX.highLow;
|
||||
zoomSavedY = chart.options.axisY.highLow;
|
||||
}
|
||||
})
|
||||
];
|
||||
|
||||
if (!isPhone) plugins.push( // larger than phone
|
||||
Chartist.plugins.ctAxisTitle({
|
||||
axisX: {
|
||||
axisTitle: xLabel,
|
||||
offset: {
|
||||
x: 0,
|
||||
y: 55
|
||||
}
|
||||
},
|
||||
axisY: {
|
||||
axisTitle: yLabel,
|
||||
flipText: true,
|
||||
offset: {
|
||||
x: 0,
|
||||
y: 15
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
var xHigh, xLow, yHigh, yLow;
|
||||
|
||||
if (zoomSavedX) {
|
||||
// we have saved coords of the zoom rect, restore the zoom.
|
||||
xHigh = zoomSavedX.high;
|
||||
xLow = zoomSavedX.low;
|
||||
yHigh = zoomSavedY.high;
|
||||
yLow = zoomSavedY.low;
|
||||
} else {
|
||||
yHigh = fft ? undefined : displayPeak;
|
||||
yLow = fft ? 0 : -displayPeak;
|
||||
}
|
||||
|
||||
new Chartist.Line('#chart', {
|
||||
series: [
|
||||
@@ -56,7 +104,7 @@ var page_waveform = (function () {
|
||||
]
|
||||
}, {
|
||||
showPoint: false,
|
||||
// showArea: true,
|
||||
showArea: fft,
|
||||
fullWidth: true,
|
||||
chartPadding: (isPhone ? {right: 20, bottom: 5, left: 0} : {right: 25, bottom: 30, left: 25}),
|
||||
series: {
|
||||
@@ -66,22 +114,32 @@ var page_waveform = (function () {
|
||||
},
|
||||
axisX: {
|
||||
type: Chartist.AutoScaleAxis,
|
||||
onlyInteger: true
|
||||
//onlyInteger: !fft // only for raw
|
||||
high: xHigh,
|
||||
low: xLow,
|
||||
},
|
||||
axisY: {
|
||||
type: Chartist.AutoScaleAxis,
|
||||
//onlyInteger: true
|
||||
high: peak,
|
||||
low: -peak,
|
||||
high: yHigh,
|
||||
low: yLow,
|
||||
},
|
||||
explicitBounds: {
|
||||
xLow: 0,
|
||||
yLow: fft ? 0 : undefined,
|
||||
xHigh: points[points.length-1].x
|
||||
},
|
||||
plugins: plugins
|
||||
});
|
||||
}
|
||||
|
||||
function onRxData(resp, status) {
|
||||
readoutPending = false;
|
||||
|
||||
if (status != 200) {
|
||||
// bad response
|
||||
alert("Request failed.");
|
||||
if (status != 0) { // 0 = aborted
|
||||
alert("Request failed.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,46 +149,84 @@ var page_waveform = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
j.stats.peak = Math.max(-j.stats.min, j.stats.max);
|
||||
if (autoReload)
|
||||
arTimeout = setTimeout(requestReload, autoReloadTime);
|
||||
|
||||
buildChart(j, 'Sample number', 'Current - mA');
|
||||
|
||||
$('#stat-count').html(j.stats.count);
|
||||
$('#stat-f-s').html(j.stats.freq);
|
||||
$('#stat-i-peak').html(j.stats.peak);
|
||||
$('#stat-i-rms').html(j.stats.rms);
|
||||
$('.stats').removeClass('invis');
|
||||
buildChart(j);
|
||||
}
|
||||
|
||||
wfm.init = function() {
|
||||
// var resp = {
|
||||
// "samples": [1878, 1883, 1887, 1897, 1906, 1915, 1926, 1940, 1955, 1970, 1982, 1996, 2012, 2026, 2038, 2049],
|
||||
// "success": true
|
||||
// };
|
||||
function requestReload() {
|
||||
if (readoutPending) return false;
|
||||
|
||||
function loadBtnClick() {
|
||||
var samples = $('#count').val();
|
||||
var freq = $('#freq').val();
|
||||
readoutPending = true;
|
||||
|
||||
//http://192.168.1.13
|
||||
$().get('/api/raw.json?n='+samples+'&fs='+freq, onRxData, true, true);
|
||||
}
|
||||
//http://192.168.1.13
|
||||
var url = '/api/{fmt}.json?n={n}&fs={fs}'.format({
|
||||
fmt: dataFormat,
|
||||
n: $('#count').val(),
|
||||
fs: $('#freq').val()
|
||||
});
|
||||
|
||||
$('#load').on('click', loadBtnClick);
|
||||
$().get(url, onRxData, true, true);
|
||||
|
||||
$('#count,#freq').on('keyup', function(e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
wfm.init = function (format) {
|
||||
// --- Load data ---
|
||||
dataFormat = format;
|
||||
|
||||
// initial
|
||||
// requestReload();
|
||||
|
||||
$('#load').on('click', requestReload);
|
||||
$('#count,#freq').on('keyup', function (e) {
|
||||
if (e.which == 13) {
|
||||
loadBtnClick();
|
||||
requestReload();
|
||||
}
|
||||
});
|
||||
|
||||
// chart zooming
|
||||
$('#chart').on('contextmenu', function(e) {
|
||||
// --- zooming ---
|
||||
|
||||
$('#chart').on('contextmenu', function (e) { // right click on the chart -> reset
|
||||
zoomResetFn && zoomResetFn();
|
||||
zoomResetFn = null;
|
||||
|
||||
zoomSavedX = null;
|
||||
zoomSavedY = null;
|
||||
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
// --- scroll the input box ---
|
||||
$('input[type=number]').on('mousewheel', function(e) {
|
||||
var val = +$(this).val();
|
||||
var step = +($(this).attr('step') || 1);
|
||||
if(e.wheelDelta > 0) {
|
||||
val += step;
|
||||
} else {
|
||||
val -= step;
|
||||
}
|
||||
$(this).val(val);
|
||||
});
|
||||
|
||||
// auto-reload button
|
||||
$('#ar-btn').on('click', function() {
|
||||
autoReloadTime = +$('#ar-time').val() * 1000; // ms
|
||||
|
||||
autoReload = !autoReload;
|
||||
if (autoReload) {
|
||||
requestReload();
|
||||
} else {
|
||||
clearTimeout(arTimeout);
|
||||
}
|
||||
|
||||
$('#ar-btn')
|
||||
.toggleClass('btn-blue')
|
||||
.toggleClass('btn-red')
|
||||
.val(autoReload ? 'Stop' : 'Auto');
|
||||
});
|
||||
};
|
||||
|
||||
return wfm;
|
||||
|
||||
@@ -50,7 +50,7 @@ var page_wifi = (function () {
|
||||
var inner = document.createElement('div');
|
||||
var $inner = $(inner).addClass('inner')
|
||||
.htmlAppend('<div class="rssi">{0}</div>'.format(ap.rssi_perc))
|
||||
.htmlAppend('<div class="essid" title="{0}">{0}</div>'.format(e(ap.essid)))
|
||||
.htmlAppend('<div class="essid" title="{0}">{0}</div>'.format(_.escape(ap.essid)))
|
||||
.htmlAppend('<div class="auth">{0}</div>'.format(authStr[ap.enc]));
|
||||
|
||||
$item.on('click', function () {
|
||||
@@ -76,7 +76,7 @@ var page_wifi = (function () {
|
||||
|
||||
/** Ask the CGI what APs are visible (async) */
|
||||
function scanAPs() {
|
||||
$().get('/wifi/scan.cgi', onScan, true, true); // no cache, no jsonp
|
||||
$().get('http://192.168.1.13/wifi/scan.cgi', onScan, true, true); // no cache, no jsonp
|
||||
}
|
||||
|
||||
function rescan(time) {
|
||||
|
||||
@@ -2,32 +2,8 @@ function bool(x) {
|
||||
return (x === 1 || x === '1' || x === true || x === 'true');
|
||||
}
|
||||
|
||||
/** html entities */
|
||||
function e(x) {
|
||||
return String(x)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>');
|
||||
}
|
||||
|
||||
/** Returns true if argument is array [] */
|
||||
function isArray(obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Array]';
|
||||
}
|
||||
|
||||
/** Returns true if argument is object {} */
|
||||
function isObject(obj) {
|
||||
return Object.prototype.toString.call(obj) === '[object Object]';
|
||||
}
|
||||
|
||||
/** escape a string to have no special meaning in regex */
|
||||
function regexEscape(s) {
|
||||
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
||||
}
|
||||
|
||||
/** Perform a substitution in the given string.
|
||||
/**
|
||||
* Perform a substitution in the given string.
|
||||
*
|
||||
* Arguments - array or list of replacements.
|
||||
* Arguments numeric keys will replace {0}, {1} etc.
|
||||
@@ -42,7 +18,7 @@ String.prototype.format = function () {
|
||||
|
||||
var repl = arguments;
|
||||
|
||||
if (arguments.length == 1 && (isArray(arguments[0]) || isObject(arguments[0]))) {
|
||||
if (arguments.length == 1 && (_.isArray(arguments[0]) || _.isObject(arguments[0]))) {
|
||||
repl = arguments[0];
|
||||
}
|
||||
|
||||
@@ -55,7 +31,7 @@ String.prototype.format = function () {
|
||||
}
|
||||
|
||||
// replace all occurrences
|
||||
var pattern = new RegExp(regexEscape(ph), "g");
|
||||
var pattern = new RegExp(_.escapeRegExp(ph), "g");
|
||||
out = out.replace(pattern, repl[ph_orig]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user