Validate values for line graph Widget

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderator: Klaus

Post Reply
trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Validate values for line graph Widget

Post by trevix » Sat Jul 20, 2024 3:43 pm

Hello.
I am having problems with the line graph Widget.
My code, for generating the graphData, sometimes fails (wow) and instead of generating some data like this
0,0,0
1,4,6
2,5,9
3,5,10
4,5,11
5,5,12
6
it misses a line and tData looks like this
0,0,0
1,4,6

3,5,10
4,5,11
5,5,12
6
No big deal to correct an empty line, you may say, but the widget error generates some kind of loop that keeps returning until you close the stack and I would prefer some bullet proof solution.

Error correction inside the widget must be rather thin and I have not the expertise do dig it.
What I know is that, using the wrong content for tData

Code: Select all

Try
set the graphData of widget "LineGraph1" to tData
catch errorVar
exit
End try
does not catch the error.
But if, after the code above I read the content

Code: Select all

Try
 put the graphData of widget "LineGraph1" into tTemp
catch errorVar
exit
End try
the error is caught !!
I wonder if anyone has some suggestion on safely validating the Widget input data before setting it.

Thanks all
Trevix
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Validate values for line graph Widget

Post by bn » Mon Jul 22, 2024 8:15 am

Hi Trevix,

I tried to paste your original data into the graphData field of the inspector and it works.

Then I made a button

Code: Select all

on mouseUp
   local tData
   put 0,0,0 & cr & 1,4,6 & cr & 2,5,9 & cr & 3,5,10 & cr & 4,5,11 & cr & 5,5,12 & cr & 6 into tData
   set the graphData of widget 1 to tData
end mouseUp
and it worked.

How do you generate your data?

Kind regards
Bernd

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Validate values for line graph Widget

Post by trevix » Mon Jul 22, 2024 10:41 am

I was doing like this:
put a breakpoint

Code: Select all

on mouseUp
   local tData
   put 0,0,0 & cr & 1,4,6 & cr & 2,5,9 & cr & 3,5,10 & cr & 4,5,11 & cr & 5,5,12 & cr & 6 into tData
   breakpoint
   set the graphData of widget 1 to tData
end mouseUp
then, on the code editor, clear line 3 and apply, so that tData looks like this
0,0,0
1,4,6

3,5,10
4,5,11
5,5,12
6
then let the script run.
An error should be thrown...
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Validate values for line graph Widget

Post by trevix » Mon Jul 22, 2024 10:46 am

Sorry:
to make it simpler, use this line:

Code: Select all

--note that 3 line is empty
 put 0,0,0 & cr & 1,4,6 & cr  & cr & 3,5,10 & cr & 4,5,11 & cr & 5,5,12 & cr & 6 into tData
If you use errorDialog to catch the error, you won't get useful info, except that the data is not valid
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Validate values for line graph Widget

Post by bn » Mon Jul 22, 2024 11:21 am

If it is a missing line that occurs in your data collection then you could do

Code: Select all

on mouseUp
   local tData, tNumLinesOrig, tNumLinesFiltered
   put 0,0,0 & cr & 1,4,6 & cr & 2,5,9 & cr & 3,5,10 & cr & cr & 4,5,11 & cr & 5,5,12 & cr & 6 into tData
   put the number of lines of tData into tNumLinesOrig
   filter tData without empty
   put the number of lines of tData into tNumLinesFiltered
   if tNumLinesOrig <> tNumLinesFiltered or tData is empty then
      answer "Malformed Data"
      exit mouseUp
   end if
   set the graphData of widget 1 to tData
end mouseUp
else you would have to parse your data according to your format and check if it is complete.

I do not see another option for widgets.

Kind regards
Bernd

trevix
Posts: 1077
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Re: Validate values for line graph Widget

Post by trevix » Mon Jul 22, 2024 11:44 am

Thanks, but, as I said, if the problem was only an empty line, I had no problem on cleaning up the data.

You see, in case my app doen't form the data correctly for the line widget, I cannot tell the user "Hey! Malformed data".
I must either provide a script the clean up the data of ANY possible error that can kaput the widget, before submitting the data to it, OR receive from the widget and error report, meaningfull enough to be handled by the app and useful for me to search for my bugs.
The widget, as of now, reports something like this:

Code: Select all

863,26,1,runtime
864,26,1,cannot convert value
865,26,1,lineGraph2.lcb
866,26,1,496
897,26,1,1
449,26,11
535,26,1
253,26,1
Debugging this, without being able to reproduce the error, is almost impossible.
Trevix
OSX 14.6.1 xCode 15 LC 10 RC1 iOS 15> Android 7>

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Validate values for line graph Widget

Post by bn » Mon Jul 22, 2024 12:19 pm

The structure of the data is determined by the widget and your requirements.

Suppose that you require this:
Each line has the same number of numerical items, it must be a numerical item, it must not be empty
the last line has only one numerical item.

Maybe something like this helps

Code: Select all

on mouseUp
   local tData, tNumLinesOrig, tNumLinesFiltered
   put 0,0,0 & cr & 1,4,6 & cr & 2,5,9 & cr & 3,5,10 & cr & 4,5,11 & cr & 5,5,12 & cr & 6 into tData
   put the number of lines of tData into tNumLinesOrig
   filter tData without empty
   put the number of lines of tData into tNumLinesFiltered
   if tNumLinesOrig <> tNumLinesFiltered or tData is empty then
      breakpoint -- empty line
   end if
   local tNumItems, tCurrentLine
   put the number of items of line 1 of tData into tNumItems
   repeat with i = 1 to the number of lines of tData - 1 -- last line is special case
      put line i of tData into tCurrentLine
      if the number of items of tCurrentline <> tNumItems then
         breakpoint -- mismatch items
      end if
      repeat for each item anItem in tCurrentLine
         if anItem is not a number then
            breakpoint -- not a number or empty
         end if
      end repeat
   end repeat
   put line -1 of tData into tCurrentline
   if the number of items of tCurrentline > 1 or item 1 of tCurrentLine is not a number then
      breakpoint -- last line only has one item and it should be a number
   end if
   set the graphData of widget 1 to tData
end mouseUp

This is just a suggestion and your requirements may vary but something along these lines.

Kind regards
Bernd

Post Reply