Hammer.js breaks vertical scroll when horizontal pan - scroll

I'm using Hammer.js to look for horizontal pan gestures, I've devised a simple function to clicks a button when panned left or right. It works okay, except the vertical scroll doesn't do anything on a touch device, or it's really glitchy and weird.
Here's the function:
var panelSliderPan = function() {
// Pan options
myOptions = {
// possible option
};
var myElement = document.querySelector('.scroll__inner'),
mc = new Hammer.Manager(myElement);
mc.add(new Hammer.Pan(myOptions));
// Pan control
var panIt = function(e) {
// I'm checking the direction here, my common sense says it shouldn't
// affect the vertical gestures, but it blocks them somehow
// 2 means it's left pan
if (e.direction === 2) {
$('.controls__btn--next').click();
// 4 == right
} else if (e.direction === 4) {
$('.controls__btn--prev').click();
}
};
// Call it
mc.on("panstart", function(e) {
panIt(e);
});
};
I've tried to add a horizontal direction to the recognizer but it didn't really help (not sure if I did it even right):
mc = new Hammer.Manager(myElement, {
recognizers: [
[Hammer.Pan,{ direction: Hammer.DIRECTION_HORIZONTAL }],
]
});
Thanks!

Try setting the touch-action property to auto.
mc = new Hammer.Manager(myElement, {
touchAction: 'auto',
recognizers: [
[Hammer.Pan,{ direction: Hammer.DIRECTION_HORIZONTAL }],
]
});
From the hammer.js docs:
When you set the touchAction to auto it doesnt prevent any defaults, and Hammer would probably break. You have to call preventDefault manually to fix this. You should only use this if you know what you're doing.

User patforna is correct. You need to adjust the touch-action property. This will fix scrolling not working when you have hammer bound on a big element in mobile.
You create a Hammer instance like so
var h = new Hammer(options.contentEl, {
touchAction : 'auto'
});
I was working on a pull to refresh feature, so I need the pan event.
Add the recognizers.
h.get( 'pan' ).set({
direction : Hammer.DIRECTION_VERTICAL,
});
h.on('panstart pandown panup panend', eventHandler);
Inside the eventhandler, you'd look at the event that was triggered and manually call on event.preventDefault() when you require it. This is applicable for hammer 2.0.6.
For anyone who's looking the pull to refresh code was taken from - https://github.com/apeatling/web-pull-to-refresh

My problem was that vertical scroll was toggling a sidebar that was supposed to show/hide on horizontal pan/swipe. After looking at the event details, I realized that Hammer probably triggers panleft and panright event based on X delta and doesn't consider Y delta, so my quick solution was to check the pan direction in my handler:
this.$data.$hammer.on('panleft', (e) => {
if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) {
return;
}
this.isVisible = true;
});

I was stuck on this for several days. Hope this will fix your problem.
mc = new Hammer(myElement, {
inputClass: Hammer.SUPPORT_POINTER_EVENTS ? Hammer.PointerEventInput : Hammer.TouchInput,
touchAction: 'auto',
});
When the relevant gesture is triggered, we applied a css class to the element, that would set the touch-action to none.
mc.on('panmove panstart', event => {
mc.addClass('is-dragging');
}
);
.is-dragging {
touch-action: none !important;
}

Hammer 2.x does not support vertical swipe/pan. Documentation says:
Notes:
When calling Hammer() to create a simple instance, the pan and swipe recognizers are configured to only detect horizontal gestures
You can however use older 1.1.x version, which supports vertical gestures
——
Clarification: this refers to a ‘simple instance’ which is when you don’t pass in any recognizer configuration as the second parameter. In other words these are the defaults but can (and usually should) be overridden.

Related

Vue-Chartjs onComplete custom labels - prevent blinking

To calculate custom labels for Vue-Chartjs the only solution I could find was via
animation: { onComplete: function () {
The problem that follows is that these labels are blinking on bar hover. I also saw the same behaviour in many other custom label examples/solutiond. Did anyone manage to solve this?
See example here fiddle
The blinking effect is caused because the animation is only triggered when the bars are hovered. You can use the onHover option to trigger whenever the chart canvas is hovered.
Here's an example logic:
(uses the plugin chartjs-plugin-datalabels to make it easier)
options : {
onHover : function (e) {
const display = e.type === 'mouseout' ? false : true
const labels = this.chart.options.plugins.datalabels
if (display&&labels.display) return //avoid updating if already set
labels.display = display
this.chart.update();
}
}
working example

How to detect double clicks or long clicks on points in Highcharts charts?

Highcharts offers the opportunity to detect clicks on chart points, but is it possible
to detect other events, such as the double click or mousedown event?
Thanks in advance
Each component only supports certain events, for example the Chart component will detect addSeries, click, load, redraw, and selection. I don't believe this set is extensible, so you can't capture a different event like mousedown.
You could try to inspect the source of your page and attach listeners to the elements that HighCharts generates, but this would be an undocumented work-around and would be liable to break in future releases. In addition, if you have to support < IE9 you would need handlers for both SVG and VML generated markup.
You can get creative with some events. Here's an example of detecting a double click using a click handler:
Working Demo
var clickDetected = false;
// create the chart
$('#container').highcharts({
chart: {
events: {
click: function(event) {
if(clickDetected) {
alert ('x: '+ event.xAxis[0].value +', y: '+ event.yAxis[0].value);
clickDetected = false;
} else {
clickDetected = true;
setTimeout(function() {
clickDetected = false;
}, 500);
}
}
}
},
...
It's possible, but in a different way. In Highcharts you can add event to each element using element.on. For example:
chart.series[0].data[0].graphic.on('dblclick', function() {
//callback here
});
And simple jsFiddle for you. Good thing is that you can add to all elements, and make sure work in all browsers.

How to control d3.brush (right click)

I was wondering how to have a better control of my d3.brush component.
I would like to have some extra controls on it, like:
right click (opens a special menu, instead of regular browser one - and instead of strange brush behavior )
been able to disable the resizable (i.e. allowing the user to only move the brush and not resizing it) brush feature (whenever I want to control it)
I've already read some older similar questions here but no luck so far.
I can already read when a right click happend on my brush area with:
//code from an older post
function rightClick() {
if (d3.event.sourceEvent.which == 3 || d3.event.sourceEvent.button
== 2) { //3==firefox, 2==ie
return true;
} else {
return false;
}
}
and here is my code that uses the rightClicl() return:
function brushed() {
if(rightClick()){
console.log("Right click : " + rightClick());
}
else {
console.log("Right click <false> : " + rightClick())
x.domain(brush.empty() ? x.domain() : brush.extent());
if(!brush.empty()){
//do something and redraw it
}
else{ //correctiong when brush.empty() restables x.domain to general value
resetView();
}
}//end-of first else
}
but every time rightClick() is true, I still have my brush acting "as a regular" left-click.
Any help / insight is appreciated.
Thank you for your time.
Context menu
I'm using this d3-context-menu for showing context menu on svg elements.
However the plugin can not be used on d3.brush rects directly. The right mousedown event will also trigger brush event. I tried event.stopImmediatePropagation(), it worked.
g.selectAll(".extent")
.on("mousedown", function() {
if (d3.event.button === 2) { // only enable for right click
d3.event.stopImmediatePropagation();
}
})
.on("contextmenu", d3.contextMenu(menu));
Disable resize
It seems that d3 has no explicit option for that feature.
But you can remove the resize rects in brush group.
// after call brush
brushG.selectAll(“.resize”).remove();

Pinch zoom event in openlayers

I'm using openlayers on an image and looking to have it so that if I zoom all the way out and it's off to the side a bit, that it will be automatically centered. I have the following code, but it is not working. It doesn't look like 'zoomEnd' is called on pinch, but what event is fired?
Is there a list of all the possible events to listen for in Openayers? I can't find something like that anywhere in the documentation..
map = new OpenLayers.Map('detailsdiv', {
projection : 'EPSG:3785',
units : 'm',
fractionalZoom : true,
eventListeners: {
"zoomend": recenterMap
},
maxResolution: Math.pow(2, graphic.numberOfTiers - 1),
numZoomLevels : graphic.numberOfTiers,
controls: [
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {
enableKinetic: true
}
})
]
});
==============================
function recenterMap(){
if (!map.centered){
if (map.getZoom() == 0){
map.centered = true;
map.zoomToMaxExtent();
map.zoomTo(0);
} else {
}
}
}
I believe you are better off using the moveend event. It gets fired when a drag, pan, or zoom ends...which is better. Also, here is a list of events:
http://dev.openlayers.org/releases/OpenLayers-2.12/doc/apidocs/files/OpenLayers/Map-js.html#OpenLayers.Map.events
You also might want to use map.setCenter() in your recenterMap() function

Sencha touch -> Scrolling x-y coordiate event activating

I have a small query with regards to Sencha Touch. i am trying to program some code which has an event kickstart as you scroll down the main panel (The end ideal experiment I am trying to achieve is to get the Panel to render images as you scroll down, but at the moment I am settling for just firing off a console.log from a function).
I was wondering if anyone knew of a method which would the program to detect how far down someone has scrolled vertically and fire off an event once you reach a certain y coordinate. I know of the scrollTo event, but I cannot seem to find any events which allow me to detect the x and y coordinate.
The basic coding for my panel is as follows:
headlinepanel = new Ext.Panel(
{
layout:
{
type:'vbox',
align:'stretch'
},
monitorOrientation: true,
scroll:
{
direction: 'vertical',
bounces: false,
outOfBoundRestrictFactor : 0,
threshold:20,
},
style: 'background-color:black;',
listeners:
{
afterrender: function()
{
if(headlinepanel.scroller.offsetBoundary.bottom == 500)
{
console.log("You are here!");
}
}
}
});
This is what I have at the moment and I tried to see if I could get the offsetBoundary property to work, but none of my programming friends has tried something like this before, so I am not very familar with this. I would appriciate any help, but I understand if this is not really possible with Sencha. Thank you for reading this.
This is how you listen for scroll events:
headlinepanel.scroller.on('scroll',function(me,offset){
console.log(offset.x);
console.log(offset.y);
});
This event is fire on every change, there are other events too. Check the API here: http://docs.sencha.com/touch/1-1/#!/api/Ext.util.Scroller-event-scroll
And here is an example: http://jsfiddle.net/sSyqF/14/

Resources