Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for webgazer #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
a.appendChild(r);
}(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv='));
</script>

</head>
<body>
<script src="https://rawgithub.com/brownhci/WebGazer/master/build/webgazer.js" type="text/javascript" ></script>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"shelljs": "^0.7.6",
"url-loader": "^0.5.8",
"vue": "^2.5.2",
"vue-content-placeholders": "^0.2.1",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
Expand Down
19 changes: 18 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<div id="app">
<div v-heatmap="showHeatmap">
<img src="./assets/logo.png">
<div class="articles">
<content-placeholders :rounded="true" v-for="index in 6">
<content-placeholders-text :lines="3" />
<content-placeholders-img />
<content-placeholders-heading :img="true" />
<content-placeholders-text />
</content-placeholders>
</div>
</div>
<button @click="showHeatmap = !showHeatmap">Toggle Heatmap</button>
</div>
Expand Down Expand Up @@ -30,6 +38,15 @@ export default {
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
/* margin-top: 60px; */
}

.articles {
display: flex;
justify-content: space-around;
flex-wrap: wrap;
}
.articles > div {
min-width: 400px;
}
</style>
32 changes: 32 additions & 0 deletions src/heatmap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import h337 from 'heatmap.js';
import { Observable } from 'rxjs';

let webgazerStream = null;
let loaded = false;
window.addEventListener('load', () => { loaded = true; });

Expand All @@ -26,6 +27,31 @@ export default {
heatmap.addData(await Promise.resolve(options.heatmapPreload));
}

if (options.webgazer) {
const webgazerOptions = typeof options.webgazer === 'object' ? options.webgazer : {};

/* eslint-disable no-undef */
webgazerStream = Observable.interval(500)
.map(webgazer.getCurrentPrediction)
.filter(e => e)
.map(e => ({
layerX: e.x,
layerY: e.y,
value: 50,
}));

webgazer.setRegression(webgazerOptions.regression || 'ridge')
.setTracker(webgazerOptions.tracker || 'clmtrackr')
.begin()
.showPredictionPoints(binding.value);

window.addEventListener('unload', () => {
console.log('end');
webgazer.end();
});
/* eslint-enable */
}

const move = Observable.fromEvent(el, 'mousemove');
const touch = Observable.fromEvent(el, 'touchmove');
const click = Observable.fromEvent(el, 'click');
Expand All @@ -34,6 +60,7 @@ export default {
move.map(e => addValue(e, 5)),
touch.map(e => addValue(e, 5)),
click.map(e => addValue(e, 10)),
webgazerStream || Observable.never,
);

streams.debounceTime(10)
Expand Down Expand Up @@ -71,6 +98,11 @@ export default {
update(el, binding) {
/* eslint-disable no-param-reassign */
el.querySelector('canvas.heatmap-canvas').style.display = binding.value ? 'inherit' : 'none';

if (options.webgazer) {
/* eslint-disable no-undef */
webgazer.showPredictionPoints(binding.value);
}
},
});
},
Expand Down
7 changes: 7 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import { Subject } from 'rxjs';
import VueContentPlaceholders from 'vue-content-placeholders';

import Vueheatmap from './heatmap';
// import { debounce } from 'lodash';
import App from './App';

const stream = new Subject();
Vue.use(VueContentPlaceholders);

Vue.config.productionTip = false;
Vue.use(Vueheatmap, {
stream,
heatmapPreload: [{ x: 10, y: 10, value: 100 }],
webgazer: {
regression: 'ridge',
// tracker: 'js_objectdetect',
},
});

stream
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4772,6 +4772,10 @@ vm-browserify@0.0.4:
dependencies:
indexof "0.0.1"

vue-content-placeholders@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/vue-content-placeholders/-/vue-content-placeholders-0.2.1.tgz#5876bda4577c80ff6d396fb33b2dbbf8b8cc140f"

vue-hot-reload-api@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/vue-hot-reload-api/-/vue-hot-reload-api-2.2.0.tgz#9a21b35ced3634434a43ee80efb7350ea8fb206d"
Expand Down