facelessuser / ColorHelper

Sublime plugin that provides helpful color previews and tooltips
https://facelessuser.github.io/ColorHelper/
MIT License
254 stars 30 forks source link

Add X11 color preview to GraphViz files #209

Closed michaelblyons closed 2 years ago

michaelblyons commented 2 years ago

Description

When the (built-in) GraphViz syntax is active, please inject the phantoms for detected X11 colors.

digraph D {

  A [shape=diamond]
  B [shape=box]
  C [shape=circle]

  A -> B [style=dashed, color=grey]
  A -> C [color=indianred2]
  A -> D [penwidth=5, arrowhead=none]

}

I don't know if it's possible to differentiate injection by scope, but if so, it would be even better if embedded HTML/CSS had the CSS colors injected, and the rest of source.dot had X11 colors.

digraph D {

  node [shape=plaintext]

  some_node [
   label=<
     <table border="0" cellborder="1" cellspacing="0">
       <tr><td bgcolor="yellow">Foo</td></tr>
       <tr><td bgcolor="lightblue"><font color="#0000ff">Bar</font></td></tr>
       <tr><td bgcolor="#f0e3ff"><font color="#ff1020">Baz</font></td></tr>
     </table>>
  ];

}

Support Info

facelessuser commented 2 years ago

I will need this explained a bit more explicitly.

  1. You want X11 color in GraphViz, does this only mean color names? What should be included and what should not be included?
  2. Are you saying that injected HTML should not use X11 colors, but instead should use modern CSS colors?
michaelblyons commented 2 years ago

Thanks for asking!

  1. You want X11 color in GraphViz, does this only mean color names? What should be included and what should not be included?

No, good point. I would also like custom RGB, RGBA, and perhaps HSV colors as well. This is the documentation page.

  1. Are you saying that injected HTML should not use X11 colors, but instead should use modern CSS colors?

Correct. If possible, anyway. If it's not possible, I'd rather have X11 everywhere.


There's also something about "Brewer" colors where a color scheme has to be selected first, and then colors can be single integers. But I've never used them, they have some kind of license attached, and they're less likely to be a thing you've done before. Don't go messing around with those unless you think it's fun to.

facelessuser commented 2 years ago

I don't think I understand the HSV syntax very well. Is it just any float separated by commas or spaces? That seems tricky to not get false positives.

I have a linked pull request up that fixes some issues I had overlooked with the recent coloraide update and it adds GraphViz support.

I imagine in embedded HTML there could be some false positives as we usually trigger off the style attribute scope with has embedded CSS, not deprecated attributes like bgcolor that just come up as generic attributes.

facelessuser commented 2 years ago

If we want HSV support, I'll have to come up with a more targeted way to maybe capture them after an = sign or something. It'll also require a custom class that recognizes and outputs this HSV format.

michaelblyons commented 2 years ago

I don't think I understand the HSV syntax very well. Is it just any float separated by commas or spaces? That seems tricky to not get false positives.

Same. I think any set of three floats between 0 and 1 with commas or spaces. But the format string seems to suggest you can have any number of commas or spaces in between the values, which seems ludicrous.

I haven't encountered the HSV format in my usage, so I'm not upset you skipped it.

I have a linked pull request up that fixes some issues I had overlooked with the recent coloraide update and it adds GraphViz support.

Neat. So the tmTheme set coincidentally covers the RGB/RGBA/X11 cases? Nice. It's also really cool that you do have scope-awareness so the X11 / CSS split works.

I imagine in embedded HTML there could be some false positives as we usually trigger off the style attribute scope with has embedded CSS, not deprecated attributes like bgcolor that just come up as generic attributes.

Yeah, I wouldn't worry too much. All the samples I've seen have been very basic table-based HTML. GraphViz only supports a tiny subset of the markup. Attributes are (from what I've seen) only ever used for direct visual changes.

Now that ST4 has syntax inheritance, it may be worth going back and making a special HTML-for-Gv syntax. But that'd be me, not you.

facelessuser commented 2 years ago

Yeah. I will probably skip HSV (for now). If GraphViz scoped bgcolor, color, etc. with something special to make them stand out as color attributes, it'd be easier to avoid false positives. I may play around and see if we can maybe use some look behinds to maybe check the attributes. If something like that worked, it'd be easy to do HSV, but right now I worry the non-specific color notation for HSV, coupled with no real scoping to indicate you are in an attribute that allows color, will just cause colors to appear in weird places.

facelessuser commented 2 years ago

I cut a release this morning as I wanted to also get some of the fixes out there. Hopefully, this provides enough functionality without giving too many false positives. As long as it's balanced enough to be useful without being annoying, I think it should be fine,

michaelblyons commented 2 years ago

Works great. Thanks!