I'm trying to implement custom gesture logic for a CombinedChart in MPAndroidChart. Effectively, what I want to accomplish is to have a long press 'enable' highlighting of values but a short press & swipe just control panning / translating the chart (when zoomed). This would allow you to highlight values in a zoomed viewport without translating the chart (by long pressing before scrolling), but would also allow you to translate the chart if you wish by scrolling the view before the long press registers. I have figured out how to do all of the gesture interactions I want however I cannot figure out how to translate the chart.
All I'm really looking for is a API that allows me to translate the chart viewport by (dX, dY) in pixels but I can't seem to find anything. The closest I can find is CombinedChart.centerViewTo(...) but this expects you to center over data point values which if used when translating creates a bit of a staggered translation (as you cannot center over a value in-between two data points.
I can include code if needed, but I figured the code may be overly verbose for a simple API query.
So, I'll delete this when / if a better answer arises, but I found a way that suits my needs (yet may not be 'idiomatic'). What I did was the following:
(Given an offset in pixels of (dX, dY) and a CombinedChart named mChart...)
ViewPortHandler vph = mChart.getViewPortHandler();
Matrix transformation = vph.getMatrixTouch();
transformation.postTranslate(-dX, -dY); // unset the negs to make x / y inverted
vph.refresh(transformation, mChart, true);
Related
Is it possible to generate a bar graph in jFreeChart where bars all start around a particular value instead of the zero axis? Our team has interest in this view.
Here is an example where the default behavior has the bars all between the value and the origin. We want the bars to be between the value and the mean (average).
I suppose a workaround is we calculate the offset from the mean and plot them in respect to the origin and then hide the axis but then we are not able to show the axis to our users.
Instead of having bar graphs stop at another value besides the origin we are just redefining the graph axis origin to be at the mean and offsetting everything. So instead of something like exposure level we now call the value axis distance from aggregate mean. Not exactly what I was originally looking in the OP but a cleaner solution overall. We'll let the user toggle between the two modes.
I want to make clickable cell of the palette in Vuforia (without Unity) by tap on screen:
I found Dominoes example with similar functionality and do that:
create one plate object and multiply cells objects
call isTapOnSetColor function with parameter x, y (click coordinates) on tap and get coordinates,
coordinates is correct, but get the id/name of part of objects is wrong
I think problem with this line:
boolean bool = checkIntersectionLine(matrix44F, lineStart, lineEnd);
In the Dominoes example this was:
bool intersection = checkIntersectionLine(domino->pickingTransform, lineStart, lineEnd);
But I don't know what does do domino->pickingTransform and paste instead of this line modelViewMatrix (Tool.convertPose2GLMatrix(trackableResult.getPose()).getData())
Full code of my touch function: http://pastebin.com/My4CkxHa
Can you help me to make clicks or may be another way (not Unity) to do that?
Basically, domino->pickingTransform is pretty much the final matrix that is being drawn for each domino object. The domino sample work in a way that for each object (domino), the app checks the projected point of the screen touch and sees if it intersects the matrix of the object. The picking matrix is not exactly the same, since you want to make the is more responsive, so you make it a little wider than the drawing matrix.
You said you are getting a wrong id, but the question is - is it always the same id for different cells? If not, this is probably some small calculation error you made in your matrix transformations. I would suggest to do a visual debugging - add some graphical indication for the detected id, so you will be able to see what cell the application thinks you have clicked. This should help you progress towards the solution.
I need to implement a Bar chart Where it reads values when the user touches the graph to move it vertically. The graph moves up, recording the value in accordance with the axis . With x axis being the value and the Y axis being the variables , i need to perform calculations. Example to understand
Take a look at this example. You can also do mChartView.addPanListener and handle this event for what you need.
A portion of my app involves the user drawing images that will be later strung together in a PDF. The user is free to use the entire screen to draw. Once the user is done drawing, I'd like to trim off all of the white space before adding the image to a PDF. This is where I am having problems. I've thought of two different methods to determine the location of trimmable white space and both seem clumsy.
My first thought was having the motion event of the stylus record if the event has gone outside of the box so far. If it has, I would expand the box to accommodate this. Unfortunately I could see polling every time there is a motion event being bad for performance. I can't just look at up and down events because the user could draw something like the letter V.
Then I thought I could look at all the pixels (using getPixel()) and see where the highest, lowest, rightmost and leftmost black pixels are. Again this seems like a really inefficient way to find the box. I'm sure I could skip some pixels to improve performance, but I can't skip too many.
Is there a standard way of doing what I want to do? I haven't been able to find anything.
You can inside your editor, where you record that this pixel has been drawn upon, update the maximum and minimum X and Y, and then use them later to crop the image.
If the user is drawing, aren't you already handling the onTouchEvent callback in order to capture the drawing events? If so, it shouldn't be a big deal to keep a minX, maxX, minY and maxY and check each recorded drawing event against these values.
I'm currently developing a game for android.
I have added buttons to allow the user to navigate the camera in the x-axis and zooming in and out.
To do this I'm using the following matrix code:
// c is the canvas..
Matrix m = c.getMatrix();
// Make sure that the ground is always at the bottom of the screen
m.setScale(zoom,zoom,0.0f,height);
m.preTranslate(camera_x, 0); // Change offset in x-direction
c.setMatrix(m);
This works on the emulator but gives me some weird results on my real device.
Can anyone tell me what's wrong with it? I find working with matrixes to be tricky, especially since there are many options available for the Matrix object (pre,post and set).
Thanks
The matrix you get from canvas.getMatrix() in a View's onDraw method already has some manipulations in it (to scale the view to your display size and translate the View's coordinates to the ViewRoot Surface coordinates.
By using matric.setScale(), rather than pre or postScale, you reset the matrix to the identity transform and then apply the scaling. This causes the initial transformation set up for onDraw to be lost. The matrix.preTranslate() is fine.
Alternatively, you could keep the setScale and use canvas.concat(m) to apply your matrix to the existing matrix.
(I can't keep the operation of pre and post applying transformations straight either.)