Configure vis network diagrams to zoom only on pinch not on mouse scroll - vis.js

I have a large network diagram created by vis.js which is 100% wide in the browser and very tall, thus requires scrolling down the page to see it all - I want my page to operate like most other web pages in the world - but vis.js zooms when I scroll, instead of scrolling the page. How do I turn off zooming for the scroll but still allow it for say, pinch (or hold a key + scroll)?
Sure I can switch off zooming with this option - and add some built in zoom buttons instead:
var options = {
interaction: {
zoomView: false,
navigationButtons: true,
}
};
but this is not ideal. It requires the user to scroll to the bottom of the page to access the zoom controls. Plus I want a more accessing zoom feature (yeah, I know, I just turned that more accessible zoom feature off). Vis timeline diagrams seem to have more methods re zooming than network diagrams.
To summarise: I want mousewheel/trackpad scroll to be disabled for the diagram thus giving a natural whole page scrolling behaviour, plus a pinch (or holding a key down + scroll) to zoom.

The pinch zooming function is handled in the onwheel listener and can be detected with the ctrlKey property. You can override the handler with your own, immediately returning if a pinch is not detected and otherwise performing as usual.
this.network = container ? new Network(container, data, options) : {};
const { interactionHandler } = this.network;
if (interactionHandler) {
interactionHandler.body.eventListeners.onMouseWheel = (event) => {
if (!event.ctrlKey) return; // ctrlKey detects a mac touchpad pinch in onwheel event
interactionHandler.onMouseWheel(event);
};
}

I don't think there's some vis-network specific solution. You have to detect mouse scroll and handle it accordingly, something like this:
container.addEventListener("wheel", function(e){
if (e.stopPropagation) e.stopPropagation();
return false;
})
For supporting old browsers, you should use DOMMouseScroll and mousewheel events.
Unfortunatelly, I don't have a mouse at hand so can't really test this for you, but here's a playground where you can do this yourself: https://jsfiddle.net/9m433scr/8/

Related

Here api, javascript 3.0

Using this example: https://developer.here.com/api-explorer/maps-js/infoBubbles/open-infobubble . I have a new map with two points.If I change the div of map adding width:100%;height:100% and position:absolute. I have a full screen map, but in this versión if i load the first time the page without full screen and a click a full screen windows i have a grey backgroud color. The same issue with a movile browswer when change the screen orientation. In the other API it didnt happened, all time the map is in full screen. ¿How can i fix it?
And the other question in this api, how i can close a infobubbles ??.
Regards and sorry for my english.
If I understand you correctly...
When you change the size of the map's container you need to call a refresh to the map.
For example - create your map:
var map = new H.Map(
document.getElementById(map_div),
defaultLayers.normal.map,
{
zoom: 4,
center: { lat: 45.3367, lng: -95.4492 },
});
Then add a listener for a window resize:
window.addEventListener('resize', function () {
map.getViewPort().resize();
});
Or call the resize method whenever you change the size of your div map container.
As for dealing with closing info bubbles, I am assuming you already have your HERE Maps UI object setup for adding/showing info bubbles.
To close the open one use the HERE Maps UI object:
ui.removeBubble(bubble);
if your issue is keeping track of what is currently open, trying assigning it to a script wide variable anytime you add a bubble:
//show info bubble
ui.addBubble(bubble);
openInfoBubble = bubble;
Then when you need to close the open InfoBubble:
if (openInfoBubble != null)
ui.removeBubble(openInfoBubble);
Hopefully, that answers your questions... good luck.

Google Maps API V3 - Zoom animation behavior

Is it possible to detect and hook into the events "like"
onBeforeZoomChange and
onAfterZoomChange(="zoom_changed")
There is the problem with hundreds of DIVs (labels) layered on the map
and bound to the appropriate markers. When the map animates (zoom-out),
DIVs changed their size twice and then are animated to be smaller.
It seems to be a great performance problem and very poor behavior.
Is it possible to hide these DIVs before zoom starts and show them
in the zoom_changed ?
There is no way to intercept the methods that redraw the map, but there is a way to intercept the drawing of custom Overlays, because you define the function that draws the Overlay on your own.
The draw-method of a cutom Overlay will be called automatically anytime it is necessary.
Simple approach: don't redraw the Overlay until the map is idle:
YourOverlayClass.prototype.draw = function(idle) {
if(!idle){
var _this=this;
google.maps.event.addListenerOnce(this.map,'idle',
function(){_this.draw(true);});
/*optionally you may hide the overlay here*/
return;
}
/**
* your drawing-instructions here
**/
/*show the overlay here when it has been hidden before*/
}
The automatically call of draw will be done without an argument, the suggestion checks if there was an argument provided,
when yes: it redraws the overlay.
When no: it adds a listener to the idle-event of the map, where the draw-method will be called with an argument(what will redraw the overlay)

Is there a way to disable the scrollbar / list bounce effect in flex 4.5 (mobile)?

I'm trying to make my own component that behaves like a list and supports infinite scrolling (in 1-dimension : vertical or horizontal) - both directions. For eg, a vertically laid out list which the user can scroll up or down forever - without ever hitting the 'last' or 'first' item. A good use for this: a calendar that displays each month as a list item.
Anyway, there are a bunch of things to overcome. The first of which, I think, is to disable the scrollbar's bounce effects (introduced in the latest Flex 4.5 (mobile) SDK).
If I can disable the bounce effects, I'm guessing I can then add/remove items as needed to the list and it would scroll infinitely.
Any ideas?
Krishna
Personally, an infinite list would mean a lot of rework of the core List component. It's a lot of work to reverse engineer and you'll probably hit a wall. I think what you want to do is create a component from scratch and extends SkinnableContainer.
From here on out, you need to decide how to implement and what's the user interaction for an infinite list, then need to implement proper practices and reuse your item renderers.
From my experience, you can simply implement the lazy loading on the List component by adding property change event to the viewport of the list's dataGroup
list.dataGroup.addEventListener( PropertyChangeEvent.PROPERTY_CHANGE, onScrollPropertyChangeHandler );
Then in the event, listen to the vertical scroll position
if ( event.property == "verticalScrollPosition" ){
var listHeight:Number = itemList.height;
var curAnchorPoint:Number = event.newValue + listHeight;
var bottomPositionToLoad:Number = 200; // Start loading when the list nearly reach the bottom minus 200
var anchorToLoadNextPage:Number = itemList.dataGroup.contentHeight - bottomPositionToLoad;
if(curAnchorPoint >= anchorToLoadNextPage){
loadNextPage();
}
}
When loadNextPage() is running, remember to remove the property change event so the loadNextPage will not be called multiple times.

Sprites don't stop dragging on MOUSE_UP

I have Sprites that I want to have move around when I click and hold them and stop when I release them. I have methods that add Event listeners to the Sprites:
public function layOutEventListeners():void
{
var addSpriteEventListener:Function =
function(spr:Dictionary, index:int, vector:Vector.<Dictionary>)
{
spr["sprite"].addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
spr["sprite"].addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
gridVec.forEach(addSpriteEventListener);
}`
and methods to handle the events:
public function mouseDownHandler(me:MouseEvent):void
{
trace(me.target.toString());
trace(me.currentTarget.toString());
this.drawSprite(me.target);
this.growByTwo(me.target);
me.stopImmediatePropagation();
me.currentTarget.startDrag(me);
}
public function mouseUpHandler(me:MouseEvent):void
{
trace(me.target.toString());
trace(me.currentTarget.toString());
me.stopImmediatePropagation();
this.originalSize(me.target);
me.currentTarget.stopDrag();
}`
My problem is: when I click on the Sprites, as soon as I move the cursor, the Sprite's registration point snaps to the cursor, and when I release the mouse the Sprite doesn't stop following the cursor. I initially thought it was a problem with pixel collision. I thought the cursor wasn't touching anything on MOUSE_UP, but that proved to be false after I experimented. I even replicated the exact same Event adding and handling methods by starting another project and found that I wasn't having this problem. The test Sprite was simply dragging and dropping like usual, not snapping to the registration point, and being dragged by the point I clicked.
The only difference I can see, and also my only suspicion, is that the Sprites in my original code are being added to a Sprite, which is then being added to the stage, whereas the Sprite in the test project is being added to the root DisplayObject. I'm thinking that somehow the Event propagating down to the container Sprite and dragging and dropping that without dropping the other Sprite. The weird snapping I'm seeing might be the cursor snapping to the object behind the other sprite. Another important thing: when I drop a Sprite on top of another Sprite, that Sprite stops moving like I want it to, but still trails the registration point.
Regardless, I'm really stumped and I really don't know that I'm running over. Any ideas?
This is usually because sometimes the mouse is not over the clip when MOUSE_UP occurs, either because of other clips getting in the way or maybe the player is not refreshing the stage fast enough, etc...
I'm not sure this is your case, but either way it is often recommended to assign the MOUSE_UP event to the stage, so you can safely assure it is always triggered. Make sure to remove the listener on the mouseUp handler though ;)
spr["sprite"].addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
public function mouseDownHandler(me:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
public function mouseUpHandler(me:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
}
The down side is that you lose your clip reference on mouseUp, but you can create a reference by hand on mouseDown, or do the whole thing internally (within the sprite's code).

Flex : best way to avoid slide transition quirks

I have a custom viewstack that applies automatically a slide in/slide out effect when the view changes. Everything goes smoothly when the views are lightweight but becomes jumpy when the next view requires heavy rendering.
Here are the relevant parts of the code :
_showEffect = new Parallel();
_contentMove = new Move();
_imageMove = new Move();
_showEffect.addChild(_contentMove);
_showEffect.addChild(_imageMove);
_showEffect.addEventListener(EffectEvent.EFFECT_END, effectEndHandler);
I apply the parallel effect to the showEffect of every view :
vis.setStyle("showEffect", _showEffect);
I define the property of the moves depending on the direction of the animation, here to the left (where _views is my resident viewstack in the custom component) :
_contentMove.xFrom = _views.width;
_contentMove.xTo = 0;
_contentMove.yFrom = 0;
_contentMove.yTo = 0;
_imageMove.xFrom = 0;
_imageMove.xTo = -_views.width;
_imageMove.yFrom = 0;
_imageMove.yTo = 0;
_imageMove moves a screen image of the previous view which is set to visible when the animation starts and hidden when it ends.
I have tried some hacks like lengthening the duration of the animation when the next page has never been shown before but this is not quite generic as the required duration to have a smooth transition changes depending on the rendering requirements.
Isn't there any way like in other programming languages to force the layout/rendering process of the next page while it is still out of view ?
Thanks
Viewstack has a creationPolicy property. By default this is set to ContainerCreationPolicy.AUTO, which means the views are rendered as-needed. This explains why the view appears jumpy when switching to it. You can set the creationPolicy property to ContainerCreationPolicy.ALL and it will force the ViewStack to prerender all of its views before they are loaded.
This will solve your problem but note that it will increase overall initialization time of your application because it will now be forced to render everything ahead of time.

Resources