Drawing colored circles according to number ranges

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
pnoah
Posts: 17
Joined: 04 Aug 2016 16:36

Drawing colored circles according to number ranges

Post by pnoah »

Hey, I may need a helpful hand here finding a more elegant solution for the following problem:

As you may see I try to show a colored circle [Q2] according to a value I have in the last column [Q] which is simply an automated overall quality estimation by ffmpeg of the video-file within a movie database.
2017-03-22 _colored_circles.jpg
2017-03-22 _colored_circles.jpg (36.24 KiB) Viewed 2126 times
The value ranges would be:

85-100 = blue circle
70-84 = green circle
55-69 = orange circle
2-54 = red circle
no value should return nothing

Well, don't laugh please ;), I came up with the following code and it works for now but of course its far from being elegant:

Code: Select all

$quality = tagitems("ex3", , <cc_item>);
if (abs($quality, "Q2") ) >= 85) {
  return ">draw.circle , 0c00ff, 150";
} elseif (abs($quality, "Q2") == 70) {
  return ">draw.circle , 00fe0f, 150";  
} elseif (abs($quality, "Q2") == 71) {
  return ">draw.circle , 00fe0f, 150";
  ...
  } elseif (abs($quality, "Q2") <= 54) {
  return ">draw.circle , fe0000, 150";
}
...and so on.

Instead of defining many single values one by one I'd really like to have clear ranges of numbers (lets say 70-84 and 55-68 ...) returning/drawing circles in different colors giving an impression about the Video quality at first glance. (including the special case of having no value returning nothing)

So I humbly ask if anyone may have some idea I could work with.

Thank you

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Drawing colored circles according to number ranges

Post by TheQwerty »

You could do something like this:

Code: Select all

$quality = tagitems('ex3',, <cc_item>);
switch (true) {
	case $quality >= 85: return ">draw.circle , 0c00ff, 150"; //High
	case $quality >= 70: return ">draw.circle , 00fe0f, 150"; //Good
	case $quality >= 55: return ">draw.circle , fefe0c, 150"; //Average 
	case $quality >=  2: return ">draw.circle , fe0000, 150"; //Poor
	default:
		return '';
}
It will work down the cases within the switch statement and return the first that evaluates true.

pnoah
Posts: 17
Joined: 04 Aug 2016 16:36

Re: Drawing colored circles according to number ranges

Post by pnoah »

Great! It works. That's all I was asking for. Thanks so much! :appl:

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Drawing colored circles according to number ranges

Post by bdeshi »

Code: Select all

/* format of table - spaces are optional, purely for visual alignment
min|max|color    */
$table = <<<TABLE
2  |54 |fe0000
55 |69 |00fe0f
70 |84 |00fe0f
85 |100|0c00ff
TABLE;

  $quality = tagitems("ex3",, <cc_item>);
  end ($quality*1 != $quality);
  foreach ($line, $table, <crlf>) {
    if $quality >= gettoken($line, 1, '|', 't') &&
       $quality <= gettoken($line, 2, '|', 't') {
      $color     = gettoken($line, 3, '|', 't') ;
      break;
    }
  }
  if isset($color) { return ">draw.circle , $color, 150"; }
ed. simplyfy
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Drawing colored circles according to number ranges

Post by bdeshi »

This would be equivalent to TheQwerty's solution.

Code: Select all

/* format of table is given below
spaces are optional, purely for visual alignment
must be listed in descending order
min|color    */
$table = <<<TABLE
85 |0c00ff
70 |00fe0f
55 |00fe0f
2  |fe0000
TABLE;

  $quality = tagitems("ex3",, <cc_item>);
  end ($quality*1 != $quality);
  foreach ($line, $table, <crlf>) {
    if $quality >= gettoken($line, 1, '|', 't') {
      $color     = gettoken($line, 2, '|', 't') ;
      break;
    }
  }
  if isset($color) { return ">draw.circle , $color, 150"; }
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Drawing colored circles according to number ranges

Post by admin »

I wonder about the vertical centering of the circles in the row. Does not look so good in Thumbnails with Details view, does it?

pnoah
Posts: 17
Joined: 04 Aug 2016 16:36

Re: Drawing colored circles according to number ranges

Post by pnoah »

admin wrote:I wonder about the vertical centering of the circles in the row. Does not look so good in Thumbnails with Details view, does it?
As far as I am concerned no complaints here. On the contrary I am happy as a clam right now. Thanks for that wonderful feature! :tup:

admin
Site Admin
Posts: 60357
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Drawing colored circles according to number ranges

Post by admin »

Changed it anyway. :) Hope you will still like it.

pnoah
Posts: 17
Joined: 04 Aug 2016 16:36

Re: Drawing colored circles according to number ranges

Post by pnoah »

admin wrote:Changed it anyway. :) Hope you will still like it.
Checking out the latest beta I wanted to show you the results of the new circle alignment in details view.
XYplorer 17.80.0003 - upgraded from v17.80..jpg
XYplorer 17.80.0003 - upgraded from v17.80..jpg (28.09 KiB) Viewed 2075 times
Yes, looking somewhat better, assuming a user-defined vertical offset instead of the given alignments (top/center) would complicate things too much, right? Anyway, I still like it and it's really fast. Thanks again!

Post Reply