How to retrieve "Site Sizes" from my custom node source code

#1

Hello, I am creating a custom dashboard node (custom chart based on d3 library) by using addWidget API. To get my chart displayed correctly inside the group (meaning to avoid my chart being too big and displayed the scroll bars), I need to take into account the 1x1 Widget sizes (sx, sy), the Widget Spacing (cx, cy), and the group Padding (px, py) from the dashboard/Site panel. Today my chart is working fine only for default values, as I use hard coded default values(48x48, 6x6, 0x0) inside my custom chart code. Is there a way to retrieve these sizes to avoid using hard coded values ?

0 Likes

#2

Hi Thierry,

I'm not a layout expert, but I got some good feedback from the community some time ago. Perhaps you get a better understanding of your issue by reading that post …
Bart

0 Likes

#3

Hi Bart,

Thanks for the pointer, but it doesn't help me so much as I really need to retrieve the exact sizes in pixel to perform a svg drawing.
Thierry

0 Likes

#4

Hi,
as long as you have the ui object you should be able to both

    var sizes = ui.getSizes();
    var theme = ui.getTheme();
0 Likes

#5

Not really. For custom ui widgets what is exposed is only from node-red-dashboard/index.js

module.exports = function (RED) {
    return {
        addWidget: function (options) {
            return addWidget(RED, options);
        }
    };
};

Or I cant really understand anything :thinking:

0 Likes

#6

Ah right (paging memory back in)...

Yes maybe change that to

module.exports = function (RED) {
    return {
        addWidget: function (options) {
            return addWidget(RED, options);
        },
        getSizes: function() { return require("./ui")(RED).getSizes(); },
        getTheme: function() { return require("./ui")(RED).getTheme(); }
    };
};

If that is workable / makes sense, can make it permanent in next release :slight_smile:

0 Likes

#7

Tried it and it's working very well

if (ui === undefined) {
	ui = RED.require("node-red-dashboard")(RED);
}			
console.log("sizes -> ",ui.getSizes());
console.log("theme -> ",ui.getTheme());

And we get nice output :

sizes ->  { sx: 48, sy: 48, gx: 4, gy: 4, cx: 4, cy: 4, px: 4, py: 4 }
theme ->  { 'base-color': { default: '#097479', value: '#0b772e', edited: true },
  'page-titlebar-backgroundColor': { value: '#0b772e', edited: false },
  'page-backgroundColor': { value: '#111111', edited: false },
  'page-sidebar-backgroundColor': { value: '#000000', edited: false },
  'group-textColor': { value: '#11bd49', edited: false },
  'group-borderColor': { value: '#555555', edited: false },
  'group-backgroundColor': { value: '#333333', edited: false },
  'widget-textColor': { value: '#eeeeee', edited: false },
  'widget-backgroundColor': { value: '#0b772e', edited: false },
  'widget-borderColor': { value: '#333333', edited: false },
  'base-font':
   { value:
      '-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif' } }
0 Likes

#8

@hotNipi Hopefully that will help fix your colours issue ?

@Thierry does this work for you also ?

0 Likes

#9

Absolutely. :slight_smile:

0 Likes

#11

Yes it works also for me. Thanks

0 Likes

#12

Great, will make it part of master today, but you will need to code defensively around it for a while until released and people have had time to upgrade..

0 Likes

#13

Of course, thanks again.

0 Likes

#14

The last remaining issue I was still facing to correctly layout my custom node (and avoid scroll bar to be displayed) was due to the padding applied to the parent md-card coming from .nr-dashboard-template css rules from app.min.less file:

@nrUnitHeight: 24px;
 .nr-dashboard-template {
        padding: (@nrUnitHeight / 8) 6px;
}

@nrUnitHeight might also be computed from app.min.js to sizes.sy/2

Taking these paddings into account, my custom node layout is now correct.

1 Like

#15

@dceejay, is this going to work inside a function node? It could answer the question I raised in Custom icon color in dashboard switch widget.

0 Likes

#16

No. This is about creating custom ui_nodes for node-red-dashboard.
Github page with deep explanation here

0 Likes

#17

Correct. General function nodes no nothing about ui.

0 Likes

#18

:hammer_and_wrench: Category of this topic should be "Creating nodes"

0 Likes

#19

Got it, thanks. So I can imagine a custom ui node that gets theme information from the ui and sends it back to the runtime? Is that too weird?

0 Likes

#20

Lets pretend custom ui_widget, that shows nice sun image on daytime and moon image at night time and may be time in text form. That text must have some color. Dashboard has theme where is defined default text color (smart way as for dark theme the light text color is chosen). User can change theme. Custom node knows nothing about and can't predict this kind of changes. Also the node can not know what color other nodes use but for nice look they all usually use same color. So such kind of properties needs to be available to ask at the time the node initializes.

0 Likes