Auto-assign colors to pens on Power Chart

Hello everyone! My boss has asked me to find a way of assigning default colors and stroke size to a pen, so a use does not have to go through the burdensome task of selecting the pen, changing the color and the stroke size every time they delete and add a pen. What would be the best way of going about this? Thanks in advance!

1 Like

an onchange script on the pens? probably the best way

or a style that overwrites all color/stroke settings if you dont mind it never being editable again

1 Like

Do the defaults need to be per user (persistent across sessions for the user), per session (settable by the user in each session but reset), or just default values that all pens start with?

1 Like

This is my coworker. To answer the questions -

@lrose the colors don't have to be the same for each user, or even the same user who logs out and logs back in, just default settings.

There is at most 4 pens.

The issue is removing a pen and re-adding it, or removing all pens and re-adding it, often they all come in the same shade of blue which makes the powerchart hard to read.

If we can just always have them different that would be helpful. I assumed doing that would be easiest by making a dictionary of pen name - color pairings like

penColors = {
    "pressure1":"green", #really would use the hex code
    "pressure2":"orange",
    "pressure3":"blue",
    "pressure4":"pink"
}

and to use that in the pen change script somehow - but I am not sure how.

@victordcq I think that is actually fine - I am not sure how a style could be created though so that it only applies to a pen of a certain name.

1 Like

I would think that a property change event script on props.pens where you compare the previousValue to the currentValue to detect the addition of a pen and then lookup the appropriate config for that pen would be enough.

2 Likes

This was my first thought. I did tell my coworker to come make a post here in the event there was "better" or built-in way to get this behavior. But if this is how it must be done then that's what I needed confirmation of before I put in the time to script it. Unless @victordcq you have a magical css solution?

ah it has be by pen name?
then no css alone wont be enough. With some js it wouldnt be to hard, but i woudlnt call it better than a onchange script^^
so you should probably just go for that

2 Likes