This is a migrated thread and some comments may be shown as answers.

Custom SnapMode

10 Answers 109 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Wouter
Top achievements
Rank 1
Wouter asked on 03 Apr 2014, 01:50 PM
My goal is to allow clients to place markers on a graph. They would like to select points of interest which are usually a local maximum on a LineSeries. The idea would be to use the ChartTrackBallBehavior to place custom annotations on the chart using the method described in the following post:

http://www.telerik.com/forums/trackball-position-hold-on-mouse-click

Selecting a local maximum is quite hard especially with the kind of mice our clients use (OzuPad). That is why we would like the TrackBall to snap to a local maximum. Unfortunately the only type of snap is snap to the closest point. Do you have any idea how we should implement snapping to a local maximum? Not using the ChartTrackBallBehavior is fine, but it would be a shame to let go of the features it already provides.

10 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 07 Apr 2014, 08:01 AM
Hello,

Unfortunately we do not have such a functionality built-in in the control. I will suggest exactly what you expected, to not use the track ball behavior. You can use annotations to build up a track-ball-like experience. I suggest you examine our TrackBallLikeAnnotations sdk example (you can use the sdk browser to browse more easily). You can see in the example one approach to mimicking the track-ball. You can see that you fully control the annotations in code, which will allow you to implement this snap-to-local-max logic you need. Let us know how it goes.

Regards,
Petar Marchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Wouter
Top achievements
Rank 1
answered on 07 Apr 2014, 08:44 AM
Hi Petar,

Sorry to hear but it won't be too hard to get to work using annotations, but it'll be easier to place a line marker annotation if the trackball itself is also a marker.

Do you have any suggestions how to keep the View and ViewModel separated? The sample you provided is tightly coupled. I guess attached behaviours would be the way to go?

Thanks,
Wouter
0
Wouter
Top achievements
Rank 1
answered on 07 Apr 2014, 10:18 AM
Just found the ChartCrosshairBehavior which is awesome, but sadly also lacks custom snapping.
0
Petar Marchev
Telerik team
answered on 07 Apr 2014, 10:31 AM
Hi Wouter,

I am not sure that I understand very well what you mean when you say "tightly coupled". I just examined the TrackBallLikeAnnotations sample and in it, the ChartUtilities class has no references to the PlotInfo and MainViewModel classes. The utility class is only interested in the DataPoints, not the actual data items. To build up your custom min-max logic, you also do not need information about the actual data items, only the data points.

I suggest you give it a try and see if you can easily incorporate such a utility class into your actual app.

Regards,
Petar Marchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Wouter
Top achievements
Rank 1
answered on 07 Apr 2014, 11:47 AM
Got it working using the sample you provided.

Something seems to go wrong though when you enable zooming. Parts of the chart will no longer get annotations while you move over it. Easiest way is to add ChartPanAndZoomBehavior to the TrackBallLikeAnnotations sample graphs, zoom in somewhat and pan a bit to the right. The annotations will then no longer work on the left side of the graph. I tried looking into a bit further and couldn't find out what the problem is.

There is another problem with the example. Line 125 in ChartUtilities.cs often throws a NullReferenceException when a chart is empty. ( DataTuple tuple = chart.ConvertPointToData(position); )
0
Wouter
Top achievements
Rank 1
answered on 07 Apr 2014, 11:48 AM
Sorry I didn't have a good look before I posted, its nicely decoupled. Also got the min/max functionality implemented rather easily.
0
Wouter
Top achievements
Rank 1
answered on 11 Apr 2014, 08:43 AM
Where can I submit bug reports? I believe that the first issue I reported is a bug in the ChartView control and the second one possibly is a bug in the 'xaml-sdk' sample project. The first one is critical for us, because we need to use 'annotation-like-trackballbehaviour' in our product.

Thanks,
Wouter
0
Petar Marchev
Telerik team
answered on 11 Apr 2014, 11:40 AM
Hello Wouter,

Perhaps I do not understand the issue very well.

1. I do not think that there is a bug in the sdk example. The sdk example does not include a pan zoom behavior. This is something that you need in your application and it is up to you to modify the code, or even create new code so that it fits your case. Perhaps in the future we may include a pan-zoom behavior and update the code accordingly, but currently the sample demonstrates synced track-ball-like annotations without zooming.

2. I tried calling this code chart.ConvertPointToData(position) when the chart is empty (when there was a series with no data points and when there was no series at all). I did not get an exception. Plus I looked around in the sdk sample and I think that this code is never executed on an empty chart. So this is again custom logic in your application that you should build-up on your own. If you think that there is a bug you can open a new support ticket and mark it as a bug report (you can also include a project that demonstrates this). 

Regards, Petar Marchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Wouter
Top achievements
Rank 1
answered on 11 Apr 2014, 12:01 PM
The problem was with the following check on line 115 in ChartUtilities.cs

    if (!chart.PlotAreaClip.Contains(position.X, position.Y))

This returns false for the left side of the graph when zoomed in and panned to the right.

I made a workaround which unfortunately needs to take a NullReferenceException hit every time the point is not on the graph.

https://github.com/frogger3d/xaml-sdk/commit/fdf221db4e498b076fad9f9abf36f5f400610e88
0
Petar Marchev
Telerik team
answered on 14 Apr 2014, 09:04 AM
Hi Wouter,

When working with a zoomed in chart, you need to account for the panned offset. So this chart.PlotAreaClip.Contains(position.X, position.Y) needs to be updated so that it takes the PanOffset.X in mind. Perhaps this would make a bit more sense (115th line in original ChartUtilities.cs)
if (!chart.PlotAreaClip.Contains(position.X - chart.PanOffset.X, position.Y - chart.PanOffset.X))
Note that the PanOffset of the chart is considered here. This is surely not the only line code that needs to be updated. I hope this helps.

Regards,
Petar Marchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ChartView
Asked by
Wouter
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Wouter
Top achievements
Rank 1
Share this question
or