In chartjs (v3) I'm programmatically zooming and panning by setting the min and max values for a series.
This works great, except if the series has a logarithmic scale ... this method doesn't seem to work, and has some strange results.
Any ideas on how I can achieve programmatic panning and zoom with logarithmic scales? Simply adding/subtracting the min/max values doesn't work correctly
EDIT: I see that the zoom plugin API has a zoomScale() function, but setting the min and max has the same effect... should min and max be calculated differently for logarithmic scales?
EDIT2: I'm trying to call the pan() function, which accepts Scale[] as a parameter ... I'm strugging to work out how to pass one of my scales, any ideas?
For zooming and panning, I'm using Zoom plugin: https://github.com/chartjs/chartjs-plugin-zoom
You can also find a specific sample on log axis: https://www.chartjs.org/chartjs-plugin-zoom/latest/samples/wheel/log.html
For anyone with a similar problem, I've got it working ...
I simply need to call the pan function like this:
mychart.pan(10, [mychart.scales['yMyScale']], 'none');
Related
I'm currently developing a Qt desktop application using the Q3DScatter class. I'm inspecting Qt's 3D Scatter example project and I tried to modify the data item set to plot my own data. The data is plotted except that one axis is not well scaled and my 3D plot looks really messy. I'm looking for a way to adjust this axis. I've tried to change the range and the segment count of the axis, I even tried to set the "AutoAdjustRange" of the axis to true, but nothing seemed to solve the problem.
Would really appreciate some help.
PS: Here's a screen capture of what my 3D scatter graph looks like (the "messy" axis is shown with the red arrow)
I figured this out by creating a CustomFormatter class by subclassing QValue3DAxisFormatter and reimplementing some of its functions (I followed this tutorial). Then I set up my axis formatter to my custom formatter (m_graph->axisZ()->setFormatter(cf);).
Subclassing QValue3DAxisFormatter will not work: it determines where ticks and labels are placed, but not how large the axex actually are.
To do that, you can set the (horizontal) aspect ratio, that is a property of Q3DScatter. The following settings will make the data into a cube volume:
plot->setAspectRatio(1.0);
plot->setHorizontalAspectRatio(1.0);
I have a CListCtrl which has about 100,000+ entries. The user is presented with a search box to search among these entries. On finding a match, I set that as a selection and scroll to it using EnsureVisible.
This scroll happens instantaneously. I wanted to try and code an animation that looks similar to the ones demoed here (especially the 'Go Top - Easing 2' animation).
I'm thinking, for a basic animation,
Get current selection.
Get target selection.
Compute difference.
Get the pixel height of one item.
Mutiply results of step 3 and 4.
Scroll by an increment of 1 (or some other more optimal value) with a delay until increment = result of step 5.
I tried this and I got incredibly confused. Firstly, is my algorithm okay? Secondly, is there another, better way to achieve this (preferably similar to animation 2 in the link above)?
Your algorithm seems ok for a simple linear scroll. However your link points to scrolls using various easing functions.
Easing functions do not scroll by the same amount each time, but increase or decrease is order to look like they're speeding up, or slowing down.
A common way to work out easing values is to use the result of a sine. If you picture a sine wave and imagine that you can only see one pixel of it at a time, as the wave progresses, the pixel will "ease" at the extremes and accelerate through the middle values.
Your Easing 2 animation is just adding a bit of bounce at the start and end, this is easily achievable by using the a bit of the sine wave past the extremes at each end. eg.
_
/ \
/
\_/
If you want some code, I answered a similar question here in C#.
In Google Earth you can use the "Sunlight" layer to view shadows cast by the terrain at any given DateTime: http://i.stack.imgur.com/YFGMj.png
However, I have not been able to find any way to access the sunlight/luminosity/shadow/etc values from the API.
I'm looking for a way to supply Lat, Long and DateTime to determine if an area is in sunlight (taking terrain shadows in to account, there are countless services that will provide simple Sunrise and Sunset times, but these do not consider terrain). This can be done manually with Google Earth, but I'm looking for a programatic method.
Thanks for any thoughts, ideas, leads...
I realise that this is an old question, but it surfaced in a google search I just did, and I liked the focus.
Since you're looking for a programmatic way of determining if a point on earth given by a longitude and latitude tuple is exposed to sun at a given time, I can't help you right now. However, I'm in a position to be able to set up such an API quite easily if we see that this is a feature that many people need. At suncurves.com we calculate sunrise and sunset times accounting for terrain. The solution we've set up so far is a web interface where a user can search for an address or drag and drop the icon on a map to get sunrise and sunset times through the year for that exact spot accounting for terrain. We want to create an API to our data, but we do not have a clear specification of the scope of this API yet. What you ask for requires that we need to:
Calculate the apparent horizon from the viewing point of the
longitude and latitude. This means scanning the terrain data in a
search radius of 30-50 km around your point.
Calculate the sun's position at the specified time.
Calculate the sun's position at the specified time. Determine if the
sun is under or over the horizon as given by the terrain surrounding
your point accounting for atmospheric refraction.
Here's an example from Chamonix, France where the common flat terrain versions of sunrise, sunset times are pretty worthless.
http://suncurves.com/v/7/
I am not sure about determining whether an AOI in in the sun or shade at a certain time, however you can set the SUN to be on or off in the API by using
GESun.setVisibility
Edit:
Using the GE-plugin, create a LookAt with your desired AOI lat/long where the view is directly above looking straight down. Depending on the size of you actual AOI I would keep the view as low to the ground as possible.
Then capture a screenshot/image - I do not think this is possible through GE (if anyone knows a way I would like to find out), so maybe use javascript to take it - I found this Q on SO that provides some insight.
Take a screenshot with GESun.setVisibility set ON and then another with it OFF
Compare the two images for darkness/lightness or something and determine if your AOI is in the shade or not. You might find it better to surround your AOI in a Polygon of some sort in order to help your program distinguish it from the rest of the image - depending on the height the LookAt was taken from etc etc....
I do not have any ideas on how to compare the images, but yet again another search on SO resulted in this (I would presume finding the values of COLOR_BLACK in PHP ImageMagick) and this (Color Buckets idea).
Depending on your method of choice, it might help to alter your images to black/white before doing the comparing.
I want Google chart to make better use of the vertical space available for this graph:
https://chart.googleapis.com/chart?chs=300x150&cht=bvs&chxt=x%2Cy&chd=t:7,8,5,6
QUESTION: How to make the vertical axis adapt to the range of values automatically?
For instance, 0→max value would be great.
Note: I could write a server-side algorithm to find the max value and use it as a parameter, but there is probably a better way to do this with Google Charts, right?
I ended up writing a server-side loop to check what is the maximum value, and then use it:
&chxr=1%2C0%2C" + max + "&chds=0," + max
Any better solution is welcome!
I want to show an effect of falling blocks which settle down at pre-determined position after some falling animation.
Can this be done without using physics engine?
I found a better and easier way to do this in cocos2d by using CCJumpTo action
CCActionInterval *jump1 = [CCJumpTo actionWithDuration:3 position:sp.position height:150 jumps:2];
sp.position = ccp(10,100);
[sp runAction:jump1];
Where sp is the CCSprite for the block.
All you need is to simulate gravity, the acceleration of the object. This could be achieved quite easily with a custom animation curve. Please have a look at this QA "how-to-create-custom-easing-function-with-core-animation", which shows a way to create the curve you need. Here is some more about "Animation Types Timing" by Apple.
The function you are looking for is called
functionWithControlPoints, which has four input parameteres, so yes you can put in any random element you wish with a custom curve.
"Easing" is your answer. You can choose the method that you need visually from the links below.
Tim Groleau's easing generator
jQuery Easing Demos