visualdatatools.com Forum Index visualdatatools.com
Discussion for DataTank and DataGraph
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Programatically show error bars on plot

 
Post new topic   Reply to topic    visualdatatools.com Forum Index -> DataGraph Framework
View previous topic :: View next topic  
Author Message
GWilliam



Joined: 18 Nov 2009
Posts: 73

PostPosted: Sat Nov 02, 2013 9:33 pm    Post subject: Programatically show error bars on plot Reply with quote

Dear,

I am new user of the dataGraph framework and I should admit that I encounter some difficulties to use it, especially to set some plot properties programatically.

I understand that to programatically set properties to command, I should used the [DGCommand setX: (id) forEntry:(NSString*)] where X stand for Number, String, Color, ….

But, I tryed each of them and I was not able to display my errors on a scatter plot. So, how can I programatically show errors on a scatter plot (and eventually on other command)

This is my piece of code:
Code:

DGCommand *cmd;
   
   if([dgraph howManyDrawingCommands] == 0)
      cmd = [dgraph addDrawingCommandWithType:@"Points"];
   else
      cmd = [dgraph drawingCommand:0];

NSDictionary *_data;
   
   _data = [_file getTH1:_name]; // Contain information on the data as well as their value organized into NSArray
   
   [[dgraph dataColumnAtIndex:1] setDataFromArray:[_data valueForKey:@"Center"]];
   [[dgraph dataColumnAtIndex:2] setDataFromArray:[_data valueForKey:@"Content"]];
   [[dgraph dataColumnAtIndex:3] setDataFromArray:[_data valueForKey:@"LowEdge"]];
   [[dgraph dataColumnAtIndex:4] setDataFromArray:[_data valueForKey:@"UpEdge"]];
   [[dgraph dataColumnAtIndex:5] setDataFromArray:[_data valueForKey:@"EyLow"]];
   [[dgraph dataColumnAtIndex:6] setDataFromArray:[_data valueForKey:@"EyUp"]];
   
   [cmd selectColumn:[dgraph dataColumnAtIndex:1] forEntry:@"X"];
   [cmd selectColumn:[dgraph dataColumnAtIndex:2] forEntry:@"Y"];
   [cmd selectColumn:[dgraph dataColumnAtIndex:3] forEntry:@"Negative X Error"];
   [cmd selectColumn:[dgraph dataColumnAtIndex:4] forEntry:@"Positive X Error"];
   [cmd selectColumn:[dgraph dataColumnAtIndex:5] forEntry:@"Negative Y Error"];
   [cmd selectColumn:[dgraph dataColumnAtIndex:6] forEntry:@"Positive Y Error"];
      
   [cmd setColor:[cmd getColorForEntry:@"Point Color"] forEntry:@"Error Color”];

[cmd setX:(id) forEntry:@"Error Style”];


and bellow are the various errors message I obtained :
Code:

setTokens:forEntry:  Doesn't work for "Error Style”
setString:forEntry:  Doesn't work for "Error Style”
setNumber:forEntry: Only works for Number and List of Numbers inputs


So, what should I use ?
Back to top
View user's profile Send private message
GWilliam



Joined: 18 Nov 2009
Posts: 73

PostPosted: Sat Nov 02, 2013 11:09 pm    Post subject: Reply with quote

I have a similar question for the Plot>Connections and Plot>Step Style Entry. I do not know wich data type I should used.
Back to top
View user's profile Send private message
klaxamazoo



Joined: 17 Jul 2009
Posts: 47
Location: Artic

PostPosted: Wed Nov 06, 2013 10:41 pm    Post subject: Reply with quote

I don't have time to test it out myself but I did verify that the plots command has entryNames for error bars. You will have to play around to find out which number/name to change to get the error bars to appear/disappear.

You might/should be able to use the method:


Code:
-(BOOL)setString:(NSString *)str forEntry:(NSString *)name; // For a token field, can use the convention
// <Parameter>ParameterName</Parameter>
// <Label>LabelName</Label>
// in the string.  This will be split into tokens.  Or use the setTokens: method
// The ParameterName and LabelName are the same names as you see in DataGraph

This description is found in the headers for DGCommand in DGCommand.h of the framework.


Call the entryNames method on the Command (i.e. the plot) to get a list of entryNames:
Code:
-(NSArray *) entryNames

NOTE: the entryNames can be different from the plist names in the .dgraph file.


To test these types of things I usually:
- open up one of the example graphs that came with the framework (i.e. Interaction)
- make a new plot with the feature I'm trying to find (i.e. one with error bars)
- save it
- right click on the .dgraph or .dplot and select "Show Package Contents"
- navigate to: "Content.plist"
- navigate to : Commands
- start looking at the commands structure, find which command has the feature I'm interested in understanding (i.e. Error bars)
- Next I would go to the example code and get it compiling for my system
- put debug break at the end of awakeFromNib
- start exploring the controller, commands, etc.
- methods like propertyNames, and entryNames are very useful while just
- calling the po nameOfItemOfInterest will give good information such as each command's integer
- also, [controller drawingCommand: int] is one way to get your drawing commands
Back to top
View user's profile Send private message
GWilliam



Joined: 18 Nov 2009
Posts: 73

PostPosted: Thu Nov 07, 2013 4:35 am    Post subject: Reply with quote

Thanks for all this details.
I will take a look at it this evening.
Back to top
View user's profile Send private message
GWilliam



Joined: 18 Nov 2009
Posts: 73

PostPosted: Thu Nov 07, 2013 5:47 pm    Post subject: Reply with quote

I created a dgraph file with scatter plot and 'Error Style' set to 'No Bar' according the the content.plits file in the dgraph package, their is, in the Commands section an entry Error Style (or X Error Type and Y Error Type. All of them take Number as value.

Therefore, I tried to programmatically set each of this entry to the value I fund in the Content.plits file :
Quote:
[cmd setNumber:[NSNumber numberWithInt:5] forEntry:@"Y Error Type"];
[cmd setNumber:[NSNumber numberWithInt:5] forEntry:@"X Error Type"];
[cmd setNumber:[NSNumber numberWithInt:5] forEntry:@"Error Style"];


and, as return, I received the errors :
Code:
setNumber:forEntry: Only works for Number and List of Numbers inputs
setNumber:forEntry: Only works for Number and List of Numbers inputs
setNumber:forEntry: Only works for Number and List of Numbers inputs
.

Then, in the debug, I did not have much information regarding the content of my command (See picture):
Code:
DGCommand *cmd = [(DGController*) dgraph drawingCommand:0];



Back to top
View user's profile Send private message
klaxamazoo



Joined: 17 Jul 2009
Posts: 47
Location: Artic

PostPosted: Fri Nov 08, 2013 12:02 pm    Post subject: Reply with quote

Dealing with Entries can be confusing.

I figured it out sometime last year but haven't had to deal with it since. I'll try and track down what I did.

In the mean time, try going through the example projects and searching "setString", "setNumber", and "error". Maybe one of the projects has an example.
Back to top
View user's profile Send private message
klaxamazoo



Joined: 17 Jul 2009
Posts: 47
Location: Artic

PostPosted: Sun Nov 10, 2013 1:23 am    Post subject: Reply with quote

Okay, so it look like there are some issues with getting and setting entryNames.

Nothing works except "Error Bar Color" and "Error Bar Size".

I wrote a quick method to test which of the getXWithEntry methods work:
Code:
DGCommand *drawingCommand = [controller drawingCommand: 2];
   
    NSArray *entryNames = [drawingCommand entryNames];
   
   
    // Loop through all entryNames for drawingCommand
    for (NSString *nextEntryName in entryNames) {
       
        // Only check entryNames that contain the work "Error"
        NSRange rangeCheck = [nextEntryName rangeOfString: @"Error"];
       
        BOOL printNextEntryName = NO;
        if (rangeCheck.length != 0) {
            printNextEntryName = YES;
        }
       
        // Try all possible getXForEntry methods where X = String, Tag, Tokens, Color, or Number
        if (printNextEntryName) {
            NSLog(@"%@", nextEntryName);
            /*
             - (NSColor *)getColorForEntry:(NSString *)name;
             - (NSNumber *)getNumberForEntry:(NSString *)name;
             - (NSString *)getStringForEntry:(NSString *)name;
             - (NSArray *)getTokensForEntry:(NSString *)name; // Array of DGToken objects
             - (int)selectedTagForEntry:(NSString *)name;
             */
           
           
            id entryQueryResult = nil;      // use entryQueryResult as an intermediate so that only one DCallBackError is made per entryName
           
            // COLOR
            entryQueryResult = [drawingCommand getColorForEntry: nextEntryName];
            if (entryQueryResult) {
                NSLog(@"COLOR  :  %@ = %@", nextEntryName, entryQueryResult);
            }
           
            // NUMBER
            entryQueryResult = [drawingCommand getNumberForEntry: nextEntryName];
            if (entryQueryResult) {
                NSLog(@"NUMBER:   %@ = %@", nextEntryName, entryQueryResult);
            }
           
            // STRING
            entryQueryResult = [drawingCommand getStringForEntry: nextEntryName];
            if (entryQueryResult) {
                NSLog(@"STRING:   %@ = %@", nextEntryName, [drawingCommand getStringForEntry: nextEntryName]);
            }
           
            // TOKEN
            entryQueryResult = [drawingCommand getTokensForEntry: nextEntryName];
            if (entryQueryResult) {
                NSLog(@"TOLKINS:  %@ = %@", nextEntryName, entryQueryResult);
            }
           
           
            // TAG
            int integerEntryQueryResult = [drawingCommand selectedTagForEntry: nextEntryName];
            if (integerEntryQueryResult) {
                NSLog(@"TAG:      %@ = %i", nextEntryName, integerEntryQueryResult);
            }
           
           
            NSLog(@"\n\n\n\n");
        }
    }


And this is the result:
Code:
2013-11-09 21:13:51.512 Interaction[45760:303] Error Bar Size
2013-11-09 21:13:51.513 Interaction[45760:303] NUMBER:   Error Bar Size = 0.5
2013-11-09 21:13:51.514 Interaction[45760:303] STRING:   Error Bar Size = 0.5
2013-11-09 21:13:51.514 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "Error Bar Size"
2013-11-09 21:13:51.514 Interaction[45760:303] CALLBACK ERROR: = selectedTagForEntry:  "Error Bar Size" needs to be a menu or segmented input
2013-11-09 21:13:51.515 Interaction[45760:303] TAG:      Error Bar Size = -1
2013-11-09 21:13:51.515 Interaction[45760:303]



2013-11-09 21:13:51.515 Interaction[45760:303] Error Color
2013-11-09 21:13:51.516 Interaction[45760:303] COLOR  :  Error Color = NSCalibratedRGBColorSpace 1 0 0 1
2013-11-09 21:13:51.516 Interaction[45760:303] CALLBACK ERROR: = getNumberForEntry:  "Error Color" needs to be a number input input
2013-11-09 21:13:51.516 Interaction[45760:303] CALLBACK ERROR: = getStringForEntry:  "Error Color" needs to be one of {token, number list, number, point, range, function, text}
2013-11-09 21:13:51.517 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "Error Color"
2013-11-09 21:13:51.517 Interaction[45760:303] CALLBACK ERROR: = selectedTagForEntry:  "Error Color" needs to be a menu or segmented input
2013-11-09 21:13:51.518 Interaction[45760:303] TAG:      Error Color = -1
2013-11-09 21:13:51.518 Interaction[45760:303]



2013-11-09 21:13:51.518 Interaction[45760:303] Error Style
2013-11-09 21:13:51.519 Interaction[45760:303] CALLBACK ERROR: = getNumberForEntry:  "Error Style" needs to be a number input input
2013-11-09 21:13:51.519 Interaction[45760:303] CALLBACK ERROR: = getStringForEntry:  "Error Style" needs to be one of {token, number list, number, point, range, function, text}
2013-11-09 21:13:51.519 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "Error Style"
2013-11-09 21:13:51.520 Interaction[45760:303] TAG:      Error Style = 2
2013-11-09 21:13:51.520 Interaction[45760:303]



2013-11-09 21:13:51.520 Interaction[45760:303] Negative X Error
2013-11-09 21:13:51.521 Interaction[45760:303] CALLBACK ERROR: = getNumberForEntry:  "Negative X Error" needs to be a number input input
2013-11-09 21:13:51.521 Interaction[45760:303] CALLBACK ERROR: = getStringForEntry:  "Negative X Error" needs to be one of {token, number list, number, point, range, function, text}
2013-11-09 21:13:51.521 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "Negative X Error"
2013-11-09 21:13:51.522 Interaction[45760:303] CALLBACK ERROR: = selectedTagForEntry:  "Negative X Error" needs to be a menu or segmented input
2013-11-09 21:13:51.522 Interaction[45760:303] TAG:      Negative X Error = -1
2013-11-09 21:13:51.522 Interaction[45760:303]



2013-11-09 21:13:51.523 Interaction[45760:303] Negative Y Error
2013-11-09 21:13:51.523 Interaction[45760:303] CALLBACK ERROR: = getNumberForEntry:  "Negative Y Error" needs to be a number input input
2013-11-09 21:13:51.523 Interaction[45760:303] CALLBACK ERROR: = getStringForEntry:  "Negative Y Error" needs to be one of {token, number list, number, point, range, function, text}
2013-11-09 21:13:51.524 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "Negative Y Error"
2013-11-09 21:13:51.524 Interaction[45760:303] CALLBACK ERROR: = selectedTagForEntry:  "Negative Y Error" needs to be a menu or segmented input
2013-11-09 21:13:51.525 Interaction[45760:303] TAG:      Negative Y Error = -1
2013-11-09 21:13:51.525 Interaction[45760:303]



2013-11-09 21:13:51.525 Interaction[45760:303] Positive X Error
2013-11-09 21:13:51.526 Interaction[45760:303] CALLBACK ERROR: = getNumberForEntry:  "Positive X Error" needs to be a number input input
2013-11-09 21:13:51.526 Interaction[45760:303] CALLBACK ERROR: = getStringForEntry:  "Positive X Error" needs to be one of {token, number list, number, point, range, function, text}
2013-11-09 21:13:51.526 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "Positive X Error"
2013-11-09 21:13:51.527 Interaction[45760:303] CALLBACK ERROR: = selectedTagForEntry:  "Positive X Error" needs to be a menu or segmented input
2013-11-09 21:13:51.527 Interaction[45760:303] TAG:      Positive X Error = -1
2013-11-09 21:13:51.528 Interaction[45760:303]



2013-11-09 21:13:51.528 Interaction[45760:303] Positive Y Error
2013-11-09 21:13:51.528 Interaction[45760:303] CALLBACK ERROR: = getNumberForEntry:  "Positive Y Error" needs to be a number input input
2013-11-09 21:13:51.529 Interaction[45760:303] CALLBACK ERROR: = getStringForEntry:  "Positive Y Error" needs to be one of {token, number list, number, point, range, function, text}
2013-11-09 21:13:51.529 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "Positive Y Error"
2013-11-09 21:13:51.529 Interaction[45760:303] CALLBACK ERROR: = selectedTagForEntry:  "Positive Y Error" needs to be a menu or segmented input
2013-11-09 21:13:51.530 Interaction[45760:303] TAG:      Positive Y Error = -1
2013-11-09 21:13:51.530 Interaction[45760:303]



2013-11-09 21:13:51.530 Interaction[45760:303] X Error Type
2013-11-09 21:13:51.531 Interaction[45760:303] CALLBACK ERROR: = getNumberForEntry:  "X Error Type" needs to be a number input input
2013-11-09 21:13:51.531 Interaction[45760:303] CALLBACK ERROR: = getStringForEntry:  "X Error Type" needs to be one of {token, number list, number, point, range, function, text}
2013-11-09 21:13:51.532 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "X Error Type"
2013-11-09 21:13:51.532 Interaction[45760:303] TAG:      X Error Type = 1
2013-11-09 21:13:51.532 Interaction[45760:303]



2013-11-09 21:13:51.533 Interaction[45760:303] Y Error Type
2013-11-09 21:13:51.533 Interaction[45760:303] CALLBACK ERROR: = getNumberForEntry:  "Y Error Type" needs to be a number input input
2013-11-09 21:13:51.533 Interaction[45760:303] CALLBACK ERROR: = getStringForEntry:  "Y Error Type" needs to be one of {token, number list, number, point, range, function, text}
2013-11-09 21:13:51.534 Interaction[45760:303] CALLBACK ERROR: = getTokensForEntry:  Doesn't work for "Y Error Type"
2013-11-09 21:13:51.534 Interaction[45760:303] TAG:      Y Error Type = 1
2013-11-09 21:13:51.534 Interaction[45760:303]



Something is either wrong with the framework or our understanding of the framework.
Back to top
View user's profile Send private message
GWilliam



Joined: 18 Nov 2009
Posts: 73

PostPosted: Wed Nov 13, 2013 7:15 am    Post subject: Reply with quote

Hi,

I did not received notification that a reply have been posted, therefore, I just see your additional comment and test.

Your test is very usefull. I think I will repeat similar test for different DGcommand. Many thanks for sharing it.

And, actually, for Error Type and Style, the TAG seems to be working. Unfortunatly, I do not see methods
Code:
setTag:(int) tag forEntry:(NSString*) name
in the DGcommand.h file. Maybe I should have a look at
Code:
selectTag:(int)tag forEntry:(NSString *)name
.

I will let you know later if it is working.
Back to top
View user's profile Send private message
GWilliam



Joined: 18 Nov 2009
Posts: 73

PostPosted: Wed Nov 13, 2013 8:35 am    Post subject: Reply with quote

Yes, the method
Code:
selectTag:(int)tag forEntry:(NSString *)name
allow me to programaticaly show/hide the error bars.

After, I need to have a little guess and many test to find out which tag value I need to use for the available style.

It is a little be difficult to identify the type (i.e. TAG, NSNumber, NSString, … ) that need to be used for the different entry and I think that the test shared by klaxamazoo will be very helpfull.
Back to top
View user's profile Send private message
klaxamazoo



Joined: 17 Jul 2009
Posts: 47
Location: Artic

PostPosted: Wed Nov 13, 2013 5:00 pm    Post subject: Reply with quote

That is working for me also.


I guess it would be nice if some more of the enumerated tags were included in the header files of the framework.

i.e. DGCommandConstants.h has enumerators for _DGSimpleLineStyle, _DGSimplePointStyle, etc.
Back to top
View user's profile Send private message
klaxamazoo



Joined: 17 Jul 2009
Posts: 47
Location: Artic

PostPosted: Wed Nov 13, 2013 9:00 pm    Post subject: Reply with quote

In case David doesn't put the enumerators in the next framework update I ended up making my own enum for the Error Styles to make things easier. I used HN as the prefix to avoid namespace conflicts.


Code:
// Menu Tags
typedef enum _HNErrorStyle {
    HNErrorStyleNoError     = 1,
    HNErrorStyleSmallBars   = 2,
    HNErrorStyleMediumBars  = 3,
    HNErrorStyleWideBars    = 4,
    HNErrorStyleNoBars      = 5,
    HNErrorStyleSingeLine   = 6,
    HNErrorStyleTinyBars    = 7   
} HNErrorStyle;


Last edited by klaxamazoo on Thu Nov 14, 2013 1:53 am; edited 1 time in total
Back to top
View user's profile Send private message
David
Site Admin


Joined: 25 Nov 2006
Posts: 1961
Location: Chapel Hill, NC

PostPosted: Wed Nov 13, 2013 10:54 pm    Post subject: Reply with quote

I should absolutely do that.

One thing you can do is to create a simple DataGraph file with the settings you want, then dig into the file wrapper, open the Content.plist file and navigate down to the setting entry. The tag numbers are the same.

David
Back to top
View user's profile Send private message Send e-mail
GWilliam



Joined: 18 Nov 2009
Posts: 73

PostPosted: Thu Nov 14, 2013 4:05 am    Post subject: Reply with quote

Yes, I agree, enumerator for TAG value is a very good idea. It will be very helpfull for use to identify the different styles.

David wrote:
One thing you can do is to create a simple DataGraph file with the settings you want, then dig into the file wrapper, open the Content.plist file and navigate down to the setting entry. The tag numbers are the same.


Yes, it is possible, but, with all the possibilities that offer DataGraph, it can be painful to dig out all possible combination from the file wrapper.[/code]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    visualdatatools.com Forum Index -> DataGraph Framework All times are GMT - 3 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group