diff options
author | 2021-02-13 13:28:27 +0100 | |
---|---|---|
committer | 2021-02-13 13:28:27 +0100 | |
commit | ac365c3b609fb383fc072392d4c6f3b840bc40bc (patch) | |
tree | 2ffa053e4b95863677898f1042924e79b9ca1f13 /dotviewer | |
parent | support unicode in labels of edges too (diff) | |
download | pypy-ac365c3b609fb383fc072392d4c6f3b840bc40bc.tar.gz pypy-ac365c3b609fb383fc072392d4c6f3b840bc40bc.tar.bz2 pypy-ac365c3b609fb383fc072392d4c6f3b840bc40bc.zip |
the fontcolor is unfortunately lost in plain files. if the fillcolor is very
dark, switch to white as the fontcolor instead of black
Diffstat (limited to 'dotviewer')
-rw-r--r-- | dotviewer/drawgraph.py | 11 | ||||
-rw-r--r-- | dotviewer/test/test_interactive.py | 12 |
2 files changed, 20 insertions, 3 deletions
diff --git a/dotviewer/drawgraph.py b/dotviewer/drawgraph.py index 1cc74e60a0..51cd7bc034 100644 --- a/dotviewer/drawgraph.py +++ b/dotviewer/drawgraph.py @@ -7,6 +7,7 @@ from __future__ import generators import re, os, math import pygame from pygame.locals import * + from strunicode import forceunicode @@ -702,6 +703,15 @@ def getcolor(name, default): else: return default +def ensure_readable(fgcolor, bgcolor): + if bgcolor is None: + return fgcolor + r, g, b = bgcolor + + l = 0.2627 * r + 0.6780 * g + 0.0593 * b + if l < 70: + return (255, 255, 255) + return fgcolor class GraphLayout: fixedfont = False @@ -1285,6 +1295,7 @@ class GraphRenderer: class TextSnippet: def __init__(self, renderer, text, fgcolor, bgcolor=None, font=None): + fgcolor = ensure_readable(fgcolor, bgcolor) self.renderer = renderer self.imgs = [] self.parts = [] diff --git a/dotviewer/test/test_interactive.py b/dotviewer/test/test_interactive.py index 0f116856b3..4db0fbf53b 100644 --- a/dotviewer/test/test_interactive.py +++ b/dotviewer/test/test_interactive.py @@ -48,9 +48,6 @@ SOURCE2=r'''digraph f { }''' - - - def setup_module(mod): if not option.pygame: py.test.skip("--pygame not enabled") @@ -185,3 +182,12 @@ def test_linewidth(): dotfile = udir.join('graph2.dot') page = graphpage.DotFileGraphPage(str(dotfile)) graphclient.display_page(page) + +def test_ensure_readable(): + from dotviewer import graphpage, graphclient + tmpname = udir.join("graph5.dot") + tmpname.write('''digraph f { + node1 [shape="box", label="readable???", color="black", fillcolor="black", style="filled"]; + }''') + page = graphpage.DotFileGraphPage(str(tmpname)) + graphclient.display_page(page) |