graph drawing and value to coordinate functions

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
greggorob64
Posts: 183
Joined: Tue Mar 18, 2014 2:55 pm

graph drawing and value to coordinate functions

Post by greggorob64 » Thu Sep 22, 2016 7:47 pm

I'm running into a tricky situation. When the user zooms in, I have to do a few things, namely:

1) Show\Scrollbars
2) Update chart margins (on account of scrollbar visibility)

And then I also need to do something important:

1) move my annotations to the correct coordinates, based on the current x\y range and margins

In the screenshot below, You can see the triangles on top. They are called 'event markers' in my specific app. When you mouse-over them, I draw a vertical line down the screen to get more information.

The annotations locations are set via coordinates. I do coordinates over values because of the fact that I want to render them outside the graphing area.

However, they just aren't always rendering correctly, they can be a few pixels off in a given direction.

So what I wonder is happening is: when i call valuestocoord, it just int taking the most 'up to date' version of the chart, its getting the coordinates based off an old value or something.

I should also add, I'm doing my "adjust margins and redraw items" code inside the 'zoomed' event. I originally had it in my axes' rangechanged events, but it didn't make a difference

Originally my logic was all between the same begin\end update block, but I tried moving them to separate ones (with the hope that my chart would render between the two block). However, that doesn't seem to be working either.

What can I do to get my valuestocoord function to be correct? Do I need to do some code to manually force the graph to redraw before I can get correct values? I'm sure you'll need more information. Hopefully my question makes sense.

Screenshot A: Before zoom: note the vertical line perfectly lines up with the annotation (as well as serieseventmarker farther down)
Image

Screenshot B: After running my update function, you can see the annotation is a little off
Image

Here is the code im using for updating margins, and then drawing the stuff

Code: Select all

// These need to be a part of thier own update batch because they have the capability to adjust the screen margins
         this.ChartSetUpdate(true);
         try
         {
            this.ScrollbarUpdateVisiblity();
            this.ScrollbarsUpdateLocation();
            this.UpdateChartMargins();
         }
         finally
         {
            this.ChartSetUpdate(false);
         }

         this.ChartSetUpdate(true);
         try
         {
            this.ScrollbarUpdateRangeHorizontal();
            this.ScrollbarUpdateRangeVertical();
            this.EventMarkersUpdateCoordinates();
            this.TestpointMarkersUpdateCoordinates();
            this.DefineLimitsVisibilityAndTextUpdate();
         }
         finally
         {
            this.ChartSetUpdate(false);
         }

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: graph drawing and value to coordinate functions

Post by ArctionPasi » Fri Sep 23, 2016 5:49 am

So what I wonder is happening is: when i call valuestocoord, it just int taking the most 'up to date' version of the chart, its getting the coordinates based off an old value or something.
Correct. LC uses margins rectangle when converting values to coords and coords to value. In this case, the margins rectangle is from previous rendering round.

When you change margin, I would propose subscribing to chart.AfterRendering event temporarily. In the handler, use ValueToCoord and reposition the markers, and unsubscribe from the event. That way it should work. :P
LightningChart Support Team, PT

greggorob64
Posts: 183
Joined: Tue Mar 18, 2014 2:55 pm

Re: graph drawing and value to coordinate functions

Post by greggorob64 » Fri Sep 23, 2016 7:34 pm

I tried checking out the rendered event, and it seems liek its getting triggered a LOT. Shoudl I have concerns regarding perfomance if I (possibly) move a bunch of annotations around?

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: graph drawing and value to coordinate functions

Post by ArctionPasi » Sat Sep 24, 2016 7:16 am

When setting margins, subscribe to AfterRendering. In the handler UNSUBSCRIBE from it so it won't be firing every time the chart renders in the future. That way the overhead introduced by this handler doesn't get too high.
LightningChart Support Team, PT

Post Reply