Highcharts stuck on panning - javascript

I'm trying to open highcharts on new browser windows so i'm doing something like this.
let chartWindow = window.open("", "_blank", "left=0,top=0,width=600,height=450");
let chartContainer = $("<div />", {
class: "chart-container"
});
$(chartWindow.document.body).append(chartContainer);
Highcharts.chart(chartContainer[0], chartOptions);
But if more than one window is open and if you try to zoom on other windows apart from the first one the click get stuck. Seems like some event is not firing properly. So if you try to select the chart to zoom it gets stuck and you have to go to the first chart that was opened and click there to fix it. I'm sure is because of opening the charts on new windows but i need to do it.
What could be the problem here?
Edit: code sample

This problem looks like a bug, so I reported it on Highcharts github: https://github.com/highcharts/highcharts/issues/9748
As a workaround you can edit Highcharts Pointer methods setDOMEvents:
if (!H.unbindDocumentMouseUp) {
H.unbindDocumentMouseUp = [];
}
H.unbindDocumentMouseUp.push(addEvent(
ownerDoc,
'mouseup',
pointer.onDocumentMouseUp
));
and destroy:
H.unbindDocumentMouseUp.forEach(function(unbind) {
unbind();
});
Live demo: http://jsfiddle.net/BlackLabel/cxz7hugp/

Related

Lazy loading on gantt charts

I'm trying to show huge series of work breakdown structure data from an API into GanttChart so it increase page loading time and becomes unresponsive sometimes. I think one of the solutions could be get data in lazy mood. I googled it and found this link on GitHub:
https://github.com/highcharts/highcharts/issues/14232
unfortunately I'm new in HighCharts and JavaScript and it seems it doesn't works or maybe I can't figure out how it works. The ideal scenario would be fetch child tasks within a series every time the parent is expanded.
I would appreciate any ideas.
You can simply add a click event on label and labelIcon SVG elements:
chart: {
events: {
load: function() {
const chart = this;
const ticks = chart.yAxis[0].ticks;
for (let key in ticks) {
if (ticks[key].treeGrid.labelIcon) {
[ticks[key].label, ticks[key].treeGrid.labelIcon].forEach(
element => element.on('click', () => handleLabelClick(ticks[key]))
);
}
}
}
}
But unfortunately, the stairs begin next. Currently, Highcharts gantt charts dont't play well with dynamic data, mostly because of this reported bug. The only way for now, but not very optimal, seems to be creating a new chart with partial data on each expand action.
Live demo: https://jsfiddle.net/BlackLabel/c8whg3kv/

Chart JS - Click not triggering until after mouse move

I'm struggling to understand why when you click on the chart the number in the middle does not get updated until the user moves their cursor after the chart has been clicked upon.
onClick: function(event, chart) {
var index = chart[0]._index;
var value = ~~percentages[index];
chart[0]._chart.config.options.elements.center.text = value;
},
https://jsfiddle.net/uL8L5ny9/
I've created a JS fiddle where you can see this happening.
From my experience this is a problem in Chrome and FF so far.
I am actually using NG2 charts on my project but the JS fiddle using just chart.js is doing the same thing.
I haven't found much on the internet about this issue.
Forgot to draw/update the chart on load. Using the chart.chart.update() fixes this.

OpenLayers zoom scroll events are ignored if no layers are visible

I've noticed that if all OpenLayers.Layers have visibility set to false, I can no longer zoom in and out using my mousewheel. I can still use the OpenLayers.Control.Zoom buttons, but no longer the mouse wheel.
Is there anyway to disable this 'feature'?
Edit:
Here is a jsfiddle link. Set the layer to invisible, then scroll, then set it back to visible. It doesn't change. Now set it invisible, use the zoom control button, then set it back visible.
http://jsfiddle.net/a8kK4/56/
Here's some code for how the map is instantiated because SO won't let me post jsfiddle without it:
var map = new OpenLayers.Map({
div: "map",
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
layers: [ new OpenLayers.Layer.OSM() ]
});
The issue is to do with the onWheelEvent of the MouseWheel handler, see the code here on github. The issue arises with the lines
if (!overScrollableDiv && overMapDiv) {
if (allowScroll) {
as with the map hidden, you will never get it so that all of these conditions are met and therefore the call to this.wheelZoom(e) which actually does the zoom in/out never gets called. The behavior you are seeing is, therefore, by design.
One, somewhat crude way to fix this, is to override the whole function and just set the line where allowScroll is initialized to true, ie, you put the the whole function into your code, after the main OpenLayers.js has downloaded, and just change that one line
OpenLayers.Handler.MouseWheel.prototype.onWheelEvent= function(e){
if (!this.map || !this.checkModifiers(e)) {
return;
}
var overScrollableDiv = false;
//CHANGE THIS LINE TO TRUE
var allowScroll = true;
var overMapDiv = false;
//rest of function .......
};
The problem of doing this is that a scroll will now happen if you use the mouse wheel anywhere. There is probably a more elegant way by changing the conditions under which the values of overMapDiv and allowScroll and overScrollableDiv get set. I could not get this to work on jsFiddle (I think due to version conflicts), but locally it worked as expected. I hope this helps.

Topcoat Side Menu on swipe

So I'm working on a phonegap app using topcoat and implemented a fly out menu as seen here. I'm using this script to open/close the menu
$(function () {
var slideMenuButton = document.getElementById('slide-menu-button');
slideMenuButton.onclick = function (e) {
var cl = document.body.classList;
if (cl.contains('left-nav')) {
cl.remove('left-nav');
} else {
cl.add('left-nav');
}
};
});
Now everything is working fine but what I want to add on is the ability to swipe to close the panel and to open it as well. I've seen touch library for jquery that seem to offer a solution (such as TouchSwipe) but I want to try to get this as close as possible to a 1:1 touch movement interaction.
Anyone have an idea on what direction I should go in to get this going or have any ideas? Any help is appreciated.
Found this and with some renaming of classes, I got a touch slide out menu that works how I want. Its called Bamboo.js
Here's a demo of it

ExtJS: starting HtmlEditor defaulting to source

I'm using ExtJS 3.2.1 and I need a component almost identical to the bundled HtmlEditor, with one exception: it must start editing the HTML source code directly. The reason I don't use a normal TextArea is that the user should be able to preview the result of his actions before submitting.
I've tried calling toggleSourceEdit(), as per ExtJS documentation, with no success. Debugging, I see that the editor object has the sourceEditMode property set to true, and the Source Edit button seems as if it was "pressed", but clicking on it does not render the typed HTML, and clicking it again goes to the Source Mode.
I've tried calling toggleSourceEdit() after the container show() method, on the container afterLayout listener and on the editor afterRender listener. I've tried also calling it on another button that I added to the container. The result is the same on every try.
The only other option I see is updating ExtJS to 3.3.0, but I haven't seem anything related on the changelogs. Either way, it's going to be my next step. EDIT: The app had another problems when updating, we'll make a bigger effort to update later. As of right now, we are using the HtmlEditor in its original setting.
Thanks!
ran into the same problem (using 3.3.0 by the way)
stumbled upon a fix by dumb luck. i have no idea why this works, but second time is the charm. call it twice in a row to achieve the desired effect..
HTMLEditor.toggleSourceEdit(true);
HTMLEditor.toggleSourceEdit(true);
hope that helps!
Rather calling toggleSourceEdit(), try to setup the configuration while you create HtmlEditor Object
Using toggleSourceEdit() caused some problems for me. One was that this seemed to put the editor somewhere in limbo between source edit and WYSIWYG mode unless I used a timeout of 250ms or so. It also puts the focus in that editor, and I don't want to start the form's focus in the editor, especially since it's below the fold and the browser scrolls to the focused html editor when it opens.
The only thing that worked for me was to extend Ext.form.HtmlEditor and then overwrite toggleSourceEdit, removing the focus command. Then adding a listener for toggling to the source editor when the component is initialized. This is for Ext 4.1 and up. For older versions, replace me.updateLayout() with me.doComponentLayout().
var Namespace = {
SourceEditor: Ext.define('Namespace.SourceEditor', {
extend: 'Ext.form.HtmlEditor',
alias: 'widget.sourceeditor',
initComponent: function() {
this.callParent(arguments);
},
toggleSourceEdit: function (sourceEditMode) {
var me = this,
iframe = me.iframeEl,
textarea = me.textareaEl,
hiddenCls = Ext.baseCSSPrefix + 'hidden',
btn = me.getToolbar().getComponent('sourceedit');
if (!Ext.isBoolean(sourceEditMode)) {
sourceEditMode = !me.sourceEditMode;
}
me.sourceEditMode = sourceEditMode;
if (btn.pressed !== sourceEditMode) {
btn.toggle(sourceEditMode);
}
if (sourceEditMode) {
me.disableItems(true);
me.syncValue();
iframe.addCls(hiddenCls);
textarea.removeCls(hiddenCls);
textarea.dom.removeAttribute('tabindex');
//textarea.focus();
me.inputEl = textarea;
} else {
if (me.initialized) {
me.disableItems(me.readOnly);
}
me.pushValue();
iframe.removeCls(hiddenCls);
textarea.addCls(hiddenCls);
textarea.dom.setAttribute('tabindex', -1);
me.deferFocus();
me.inputEl = iframe;
}
me.fireEvent('editmodechange', me, sourceEditMode);
me.updateLayout();
}
})
}
Then to use it:
Ext.create('Namespace.SourceEditor', {
/*regular options*/
listeners: {
initialize: function(thisEditor) {
thisEditor.toggleSourceEdit();
}
}
});
htmlEditor.toggleSourceEdit(true);
one time should be enough if you do this listening to the afterrender event of the editor.

Categories

Resources