Skip to content

Commit

Permalink
Merge branch 'master' into proxy-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain authored Jan 4, 2018
2 parents b43f6e7 + ed43866 commit a9158c8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
'react/no-unused-prop-types': 0,

// Not for us ;-)
'no-plusplus': 0,
'jsx-a11y/label-has-for': 0,
'no-console': 0,
'import/no-named-as-default-member': 0,
Expand Down
12 changes: 10 additions & 2 deletions src/IO/Core/QueryDataModel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default class QueryDataModel {
this.mouseListener = null;
this.dataMetadata = {};
this.lazyFetchRequest = null;
this.registeredURLs = [];

this.playNext = () => {
if (this.keepAnimating) {
Expand Down Expand Up @@ -224,6 +225,7 @@ export default class QueryDataModel {

// Register data handler + listener
dataManager.registerURL(dataId, (dataEntry.absolute ? '' : basepath) + dataEntry.pattern, dataEntry.type, dataEntry.mimeType);
this.registeredURLs.push(dataId);
dataManager.on(dataId, dataHandler);
this.dataCount[dataId] = 0;
});
Expand Down Expand Up @@ -589,6 +591,7 @@ export default class QueryDataModel {
/* eslint-disable no-bitwise */
if (item.modifier & event.modifier || item.modifier === event.modifier) {
eventHandled = true;
event.preventDefault(); // Consume event
const delta = event[deltaName] - item.lastCoord;
self.lastTime[event.topic] = time;

Expand Down Expand Up @@ -636,10 +639,15 @@ export default class QueryDataModel {
}

destroy() {
this.off();

this.explorationSubscription.unsubscribe();
this.explorationSubscription = null;

// Remove links to dataManager
while (this.registeredURLs.length) {
dataManager.unregisterURL(this.registeredURLs.pop());
}

this.off();
}

// Data exploration -----------------------------------------------------------
Expand Down
11 changes: 7 additions & 4 deletions src/IO/Core/QueryDataModel/tests/testQueryDataModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import QueryDataModel from '..';

// ----------------------------------------------------------------------------

test('Query Data Model - Fetch/Notification', t => {
test('Query Data Model - Fetch/Notification', (t) => {
const dataDescription = {
type: ['tonic-query-data-model', 'slice-prober'],
arguments: {
Expand Down Expand Up @@ -59,12 +59,15 @@ test('Query Data Model - Fetch/Notification', t => {
let notificationCount = 0;

queryDataModel.onDataChange((data, envelope) => {
notificationCount++;
notificationCount += 1;
t.ok(data && !data.error, `callback ${notificationCount}`);

// Finish test
if (numberOfRequests === notificationCount) {
// console.log('Fetch/Notification: done with success');
// Make sure we can destroy the queryDataModel
queryDataModel.destroy();
t.ok(true, 'QueryDataModel deleted');
t.end();
}
});
Expand All @@ -73,15 +76,15 @@ test('Query Data Model - Fetch/Notification', t => {

let count = numberOfRequests;
while (count--) {
fetchCount++;
fetchCount += 1;
t.comment(`fetch ${fetchCount}`);
queryDataModel.fetchData();
}
});

// ----------------------------------------------------------------------------

test('Query Data Model - API/Query/Validation', t => {
test('Query Data Model - API/Query/Validation', (t) => {
const dataDescription = {
type: ['tonic-query-data-model'],
arguments: {
Expand Down
30 changes: 17 additions & 13 deletions src/Interaction/Core/MouseHandler/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Hammer from 'hammerjs';
import merge from 'mout/src/object/merge';
import Monologue from 'monologue.js';

// Module dependencies and constants
Expand Down Expand Up @@ -40,12 +39,14 @@ function getRelative(el, event) {
};
}

function broadcast(ctx, topic, event) {
function broadcast(ctx, topic, event, preventDefault = true) {
if (!ctx.mouseEnabled) {
return;
}

event.preventDefault();
if (preventDefault) {
event.preventDefault();
}

event.button = 0;
event.topic = topic;
Expand All @@ -59,14 +60,15 @@ export default class MouseHandler {

constructor(domElement, options) {
var defaultOptions = {
preventDefault: true,
pan: {
threshold: 0,
},
pinch: {
threshold: 0,
},
};
var optionsWithDefault = merge(defaultOptions, options);
const optionsWithDefault = Object.assign(defaultOptions, options);

this.Modifier = Modifier;

Expand Down Expand Up @@ -105,7 +107,9 @@ export default class MouseHandler {
this.inRightClickHandling = true;
}

e.preventDefault();
if (optionsWithDefault.preventDefault) {
e.preventDefault();
}

const event = {
srcEvent: e,
Expand Down Expand Up @@ -186,41 +190,41 @@ export default class MouseHandler {

// Listen to hammer events
this.hammer.on('tap', (e) => {
broadcast(this, 'click', e);
broadcast(this, 'click', e, optionsWithDefault.preventDefault);
});

this.hammer.on('doubletap', (e) => {
broadcast(this, 'dblclick', e);
broadcast(this, 'dblclick', e, optionsWithDefault.preventDefault);
});

this.hammer.on('pan', (e) => {
broadcast(this, 'drag', e);
broadcast(this, 'drag', e, optionsWithDefault.preventDefault);
});

this.hammer.on('panstart', (e) => {
e.isFirst = true;
broadcast(this, 'drag', e);
broadcast(this, 'drag', e, optionsWithDefault.preventDefault);
});

this.hammer.on('panend', (e) => {
e.isFinal = true;
broadcast(this, 'drag', e);
broadcast(this, 'drag', e, optionsWithDefault.preventDefault);
});

this.hammer.on('pinch', (e) => {
broadcast(this, 'zoom', e);
broadcast(this, 'zoom', e, optionsWithDefault.preventDefault);
});

this.hammer.on('pinchstart', (e) => {
console.log('zoom start');
e.isFirst = true;
broadcast(this, 'zoom', e);
broadcast(this, 'zoom', e, optionsWithDefault.preventDefault);
});

this.hammer.on('pinchend', (e) => {
e.isFinal = true;
console.log('zoom end');
broadcast(this, 'zoom', e);
broadcast(this, 'zoom', e, optionsWithDefault.preventDefault);
});

this.hammer.get('pinch').set({
Expand Down

0 comments on commit a9158c8

Please sign in to comment.