Logic Machine Forum
How change objects color at visu - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: How change objects color at visu (/showthread.php?tid=1976)

Pages: 1 2


RE: How change objects color at visu - Trond Hoyem - 10.06.2021

(10.06.2021, 06:30)admin Wrote: Use this, make sure that all lower/upper limit objects are defined and they all follow the naming scheme as you've posted.
Code:
$(function() {
  $('.color-by-value').each(function(_, el) {
    var addr = $(el).data('object');
    if (addr) {
      grp.listen(addr, function(obj) {
        var value = obj.value;
        var name = obj.name;
        var color = 'green';
        var lname = name.replace('ACTUAL_TEMP', 'LOWER_LIMIT');
        var uname = name.replace('ACTUAL_TEMP', 'UPPER_LIMIT');
        var llimit = grp.getvalue(lname);
        var ulimit = grp.getvalue(uname);

        if (value < llimit) {
          color = 'blue';
        }
        else if (value > ulimit) {
          color = 'red';
        }

        $(el).css('color', color);
      });
    }
  });
});

Fantastic!

Will try this out during the day.


RE: How change objects color at visu - oyvindnordbo - 04.08.2022

I want to change the color of a value 2 byte floating point if the value is the following I want it to change, does anyone have suggestions on how this can be solved?

0-3000 color #00991E
3001-5000 color #FF8C00
above5000 color #FF0000


RE: How change objects color at visu - admin - 04.08.2022

Use this, set additional class to color-by-value. Note that this only works in the actual visualization, not in the editor.
Code:
$(function() {
  $('.color-by-value').each(function(_, el) {
    var addr = $(el).data('object');

    if (addr) {
      grp.listen(addr, function(obj) {
        var value = obj.value, color;

        if (value <= 3000) {
          color = '#00991E';
        }
        else if (value <= 5000) {
          color = '#FF8C00';
        }
        else {
          color = '#FF0000';
        }

        $(el).css('color', color);
      });
    }
  });
});



RE: How change objects color at visu - oyvindnordbo - 12.08.2022

Hi, thanks for the help, but can't get it to work as expected, is this a Custom Javascript or a custom CSS?


RE: How change objects color at visu - Daniel - 12.08.2022

JavaScript


RE: How change objects color at visu - victor.back - 22.05.2023

If I want to set the color of an object dependent on the value of another specific groupaddress, is it just to change from this?
Code:
var addr = $(el).data('object');

To this?
Code:
var addr = "32/3/25";



RE: How change objects color at visu - admin - 22.05.2023

If you make this change then all elements with "color-by-value" class will follow this object value. This is fine if you only need one such element. Otherwise you need to create a copy of the script with a different class name for each instance.