I am using Flot successfully to chart usage for a project I am working on with a time series. The flot graph starts with the last 24 hours and allows panning and zooming.
The data is being sampled on the server every 15 minutes, converted to json and downloaded by the flot graph via busy-polling with AJAX (it checks for changes).
After a couple of months I have so much data (of course) that the array has become rather large. I would like to limit the json downloaded from the server to only contain the visible spectrum of the flot graph. To limit the initial download is easy, but I don't know how to handle the panning and zooming. I already have event handlers bound to panning and zooming, but they fire for every move (panning in particular).
Is it possible to detect when panning starts and ends?
[Edited because I missed the fact that you already have handlers bound]
If you're already trapping plotpan events, you can just debounce it. Add a timer that fires a certain amount of time (500 milliseconds, for example) after a pan, and is reset each time plotpan fires. This way the action only runs once at the end of many consecutive events.
A very simple example:
var delay = null;
element.on("plotpan", function() {
if (delay) clearTimeout(delay);
delay = setTimeout(function() {
// do your stuff here
delay = null;
}, 500);
});
Related
In a Gtk::DrawingArea I have a pixbuf showing the layout of my house. I draw the measured room temperatures on it. I also would like to draw the state of my shutters on it with some lines. When and only when a shutter changes its state, I would love to make these lines blink with a time offset of 1 second. I assume, I would have to make use of a timeout triggered every second to redraw the lines for the shutters. I am already making use of a timeout every 2 minutes to fetch new data from the internet to be shown on my screen. I could set up the timeout to get called every second and then I would have to remember, when my last 2-minute fetch was accomplished, to trigger the next one on time. Also, if my shutters are not changing state like in 99.9 percent of their lifetime, I do not need blinking. It feels over engineered to me to call a method every second just to make a line blink. Is there a smarter way to do this?
I could post a lot of code here, but I think that would not help anybody understand my question. I am helpful for any hint.
I found in manim there are two kinds of way to display animation, one way is to useself.play()and by adding run_time = Xin kwargs, the speed of animation can be set and the animation will finish in X seconds.
But I found another way to display by first adding an object with updater using self.add() and wait it to display using self.wait().
How to control the speed if use self.add() and self.wait()?
There is a demo to show the case
BTW, I'm using manimgl instead of community version in order to achieve real time rendering.
I am running a realtime WebGL animation in the Chrome web browser. I am using requestAnimationFrame, which attempts to trigger frame drawing at the monitor's vsync rate (60Hz). However on some lower power machines (Intel graphics laptops), the webGL rendering cannot run at that framerate - running flat out it manages around 20 fps.
A framerate of 20fps would be fine - except for the fact that in this situation, my mouseEvents seem to be quite seriously delayed / lagging. For example, I print out "mouse" to the console in my mouseEvent handler, and it appears around 0.5 seconds after I tap the laptop's touchpad button. This is a serious delay for a realtime application, and results in my 3D scene lagging behind the mouse movement.
So far, the only way I have found to get around this lag is by using a "debounce" i.e. calling the next RequestAnimationFrame from a timed callback of between 50 - 70 milliseconds. This backing off eliminates the delay in mouse events being processed, but obviously results in a reduced fps. (For example a timer of 70 milliseconds reduces my fps from 20 to 10, which is no good, and a smaller delay does not solve the lagging).
I feel like there must be a better way of managing this per-frame synchronisation. My working theory is that RequestAnimationFrames are being queued up ahead of my mouse events, however I am not sure how to solve this. I know that Chrome passes webGL drawing off to another process, and I have tried to wait for drawing to complete by using gl.finish() - however this seems to have no affect.
Many thanks for any help / advice
I'm trying to implement a countdown feature for my program. It's a second-timer, so I use a NSTimer object with a time interval of 1.0 second to update the UI. But in order not to accumulate error (every 1.0-second interval will incur a little bit of lag), the program caculates the absolute difference between current time and beginning time for the remaining time displayed in the UI.
The problem is, after the NSTimer object runs for a significant time (say half an hour), it's no longer "synced" with the absolute time due to accumulated error: the UI update happens between two "absolute" seconds. For example, if the countdown starts at 00:00:00.000, at first UI updates at 00:00:01.000, 00:00:02.000 ... but after a while it becomes 00:30:03.567 or something like that.
Any idea how I can deal with this? Are there any other better ways to implement this? Thanks!
One high level idea is to detect when the timer is getting too far out of sync based on your absolute time calculation. When it gets past a specific threshold, say 0.01 seconds or whatever you desire, cancel the current timer and start a new one after an appropriate delay that gets it back "in sync".
I am creating a game using cocos2dx 2.1.4. Its FPS drops continuously , and never recover.
Please find the details as follows
Background about the way I am doing things:-
Its game about scrolling down some shapes, each shape is made up of some square blocks.I have 7 kind of blocks. All loaded in a Sprite Sheet and using these blocks from this sprite sheet I create a shape.
A level file is consist of these shapes. I load two levels at the same time one onscreen and another off screen to make it seamless scrolling. For loading two levels at the same time I used two different CCSprite game batch nodes as :-
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("56blackglow.plist");
_gameBatchNode1 = CCSpriteBatchNode::create("56blackglow.png", 200);
_gameBatchNode1->retain();
this->addChild(_gameBatchNode1,kForeground);
_gameBatchNode2= CCSpriteBatchNode::create("56blackglow.png", 200);
_gameBatchNode2->retain();
this->addChild(_gameBatchNode2,kForeground);
The problem I am facing is that as I keep on playing the game frame rate drops continuously , from 60 fps till 10 fps and never recovers or might recover in near future , as I observed for 20 minutes but its too much time to wait.
My observations:-
1> I used Time profiler it shows maximum time is in draw() calls. Also if I play game very fast the peak of time increases in track, that should be fine as I am giving more work to do, but once a peak is attained it remains approximately at that height only, even if I leave the game Idle. Is it normal ? According to me it should have returned to its normal peak once the current work is done.
2> Some where I thought its happening because I used two batch nodes and removing its children on a user touch immediately might causing it slow but then after removing the children it should run normal. to give an idea is it ok to remove 10 children from batch node immediately ? some guys say its very slow process. Just to check if this causing problem , I did :-
Instead of removing them I just set visibility of the children to false.But still FPS drops and never recovers.
Please share your thoughts on this.
Though SpriteBatchNodes are generally quite good for drawing a lot of elements efficiently, I think there are best used for static/not-so-dynamic elements. In your case, if you have a lot of elements which go out of the screen but are still alive the draw() function will have to make some checks, thus hogging your performance (even if you set isVisible(false); explicitly, it still nedds to be checked).
In your case I think it would be better if you simply added new shapes outside of screen via some time-based function, and if they scroll outside of view simply remove them from scene, without using batchNodes.
Just found that with every touch, I am adding 8 new sprites to the layer, and its adding every time I touch . So with time I am giving more and more work to do. This is the problem
Actually I wanted to replace the sprite at 8 places with a touch, the way I was doing every time :-
_colorBottom1=CCSprite::createWithSpriteFrameName(png[0]);
this->addChild(_colorBottom1,kForeground);
_colorBottom1->setPosition(ccp((_colorPanelLeftPad)*_blockWidth,_blockWidth));
It was causing this sprite to be added with every touch.
but it should have been (Replace the texture instead of creating the Sprite again):-
CCSpriteFrame *frame1=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(png0);
_colorBottom1->setDisplayFrame(frame1);