Skip to content

Commit

Permalink
add Hammer
Browse files Browse the repository at this point in the history
  • Loading branch information
bobpearson committed Mar 29, 2018
1 parent aa0fd2d commit d06aaa7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 38 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Bob Jamison
</author>
<content src="index.html" />
<icon src="src/img/icon.png" platform="ios" width="57" height="57" density="mdpi" />
<icon density="mdpi" height="57" platform="ios" src="src/img/icon.png" width="57" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
Expand Down
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const promisify = require("util").promisify;
const del = require("del");
const mkdirp = require("mkdirp");
const webpack = require("webpack");
const appIcon = require("app-icon");

const p_copyFile = promisify(fs.copyFile);
const p_mkdirp = promisify(mkdirp);
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"cordova-plugin-bluetooth-serial": "^0.4.7",
"cordova-plugin-toaster": "0.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"hammerjs": "^2.0.8",
"jquery": "^3.3.1",
"popper.js": "^1.14.1",
"rxjs": "^5.5.7",
Expand Down
64 changes: 28 additions & 36 deletions src/js/swrgraph.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* jshint esversion: 6 */

import Chart from "chart.js";
//make sure it is bundled
import annotationPlugin from "chartjs-plugin-annotation";

import Hammer from "hammerjs";

/**
* Alternate graph using Chart.js
*/
Expand Down Expand Up @@ -109,12 +111,19 @@ class SwrGraph {

}

startScan() {
adjustData() {
let range = this.par.range;
//this 'ticks' code duplicated below intentionally
let ticks = this.data.options.scales.xAxes[0].ticks;
let opts = this.data.options;
let ticks = opts.scales.xAxes[0].ticks;
ticks.min = range.start;
ticks.max = range.end;
opts.title.text = range.name;
}

startScan() {
let range = this.par.range;
//this 'ticks' code duplicated below intentionally
this.adjustData();
let ds = this.chart.data.datasets;
ds[0].data = [];
ds[1].data = [];
Expand Down Expand Up @@ -181,41 +190,24 @@ class SwrGraph {
setupEvents() {
let that = this;
let par = this.par;
let data = this.data;
let canvas = this.canvas;
let clicked = false;
this.canvas.addEventListener("click", (evt) => {
evt.preventDefault();
if (!clicked) {
clicked = true;
setTimeout(() => {
if (clicked) {
//single
let w = canvas.clientWidth;
let x = evt.clientX;
if (x < w / 2) {
par.prev();
} else {
par.next();
}
let range = par.range;
data.options.title.text = range.name;
let ticks = data.options.scales.xAxes[0].ticks;
ticks.min = range.start;
ticks.max = range.end;
that.redraw();
}
clicked = false;
}, 300);
} else {
//double
clicked = false;
par.checkConnectAndScan();
}
let hammer = new Hammer(this.canvas);
hammer.on("doubletap", (evt) => {
par.checkConnectAndScan();
});
hammer.on("swipeleft", (evt) => {
par.next();
that.adjustData();
that.redraw();
});
hammer.on("swiperight", (evt) => {
par.prev();
that.adjustData();
that.redraw();
});

}



}

export default SwrGraph;

0 comments on commit d06aaa7

Please sign in to comment.