LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Legend Item on LEFT_CLICK

Does anyone know a good way to get the index of the Legend item from an EVENT_LEFT_CLICK (or any other event) for a stripchart control.
 
Using EVENT_INTERACTIVE_LEGEND isn't what I'm looking for.
 
Amoung other things,  I want to make a trace visible when the user simply clicks the legend item rather then having to navigate the full interactive menu.
 
I currently do this with a custom control that uses a tree control legend, but I'd like to use the stripchart legend if I can.
 
Greg
0 Kudos
Message 1 of 6
(3,729 Views)
Hi Greg,

As far as getting a trace to become visible when the user clicks the Legend/Chart. I edited the control, labeled the callback function "Legend", and generated the callback and added everything between "switch" and "return 0". So whenever I right-click the chart/legend the trace appears.

int CVICALLBACK Legend (int panel, int control, int event,
        void *callbackData, int eventData1, int eventData2)
{
    switch (event)
    {
        case EVENT_RIGHT_CLICK:
                SetTraceAttribute (panel, PANEL_CHART, 1, ATTR_TRACE_VISIBLE, 1);
            break;
    }   
    return 0;
}

With regards to your other question about getting the index of the Legend, I failed to find a call that would access that information. You mentioned that you did this with a custom control though, so I was wondering if you could explain further.
Jonathan F.
National Instruments
Applications Engineer
0 Kudos
Message 2 of 6
(3,688 Views)
Your example over simplifies what I want to do.  Your example works with only the trivial case when there is one trace. 
 
I want to make one or more traces visible by clicking on trace item in the Legend..without having to navigate the full menu to select "Visible".   As I mentioned, I currently do this with a custom control that looks and functions a lot like the new stripchart legend.  Since I duplicate a lot of the functions now built into the legend, I think it would be more efficient to use it.  However, it seems to be missing this (in my opinion) critical event callback.  I can get "user has selected a menu item" events, but nothing else.  I would like "user has clicked a legend item" events or a function to get the legend item from the mouse position similar to getting which table cell was clicked in a table callback.  I will post a suggestion to the feedback forum if no one has an existing solution.
 
Greg
 
0 Kudos
Message 3 of 6
(3,672 Views)
Hello Greg,

Although there is not a LEGEND_LEFT_CLICK event or something similar, the left click event for the graph does pass in the coordinates of the mouse at eventData1(Y-coordinate), and eventData2(X-Coordinate).  You can use this in conjunction with graph attributes such as ATTR_LEGEND_LEFT and ATTR_LEGEND_TOP to find where the user clicked and accordingly which plot to dim or show. 

NickB
National Instruments
0 Kudos
Message 4 of 6
(3,655 Views)

Greg,

There will be a way to get the trace number (for strip charts) and the plot handle (for graphs) from a legend coordinate point in the next version of CVI (which should be in beta soon, check out ni.com/beta to sign up for the beta program). This will make it easy to set trace attributes from a mouse click.

In the mean time, there currently isn't a perfect solution for you. I do have a couple of suggustions.

- You could guestimate the height of each item in the legend and calculate which legend item a point is over based on which legend items are visible and your estimate of each items' height. This solution could work pretty well if you have a good idea of what kinds of things you'll be plotting.

- I know you didn't want to have to navigate the full interactive menu, so you could hide all the other interactive menu entries except for visible using HideBuiltInCtrlMenuItem.

Hope this helps,

- jared

0 Kudos
Message 5 of 6
(3,594 Views)

Thanks Jared.

I'm glad to hear that the legend item will be available on events in the next CVI.  I will leave my plot controls the way they are until then.  Guestimating the height of each item is "iffy" at best and really messes up our customs who have high-res screens with "large fonts" set in windows (which messes up a lot of things).  Even with regular font I build too much error over my 48+ traces... Which brings up another issue... will there also be scroll bars on the next version of the legend?

I plan to run the Beta for 9 through a bunch of our apps since we were heavily affected by several bugs in 8.5. 

Greg

0 Kudos
Message 6 of 6
(3,579 Views)