From 7e5d40de51f3f95585330abe8bee49f8d924351d Mon Sep 17 00:00:00 2001 From: Chris McComb Date: Fri, 5 Jan 2024 11:11:16 -0500 Subject: [PATCH] Better typehinting --- trussme/matplotlib_color_type.py | 1142 ------------------------------ trussme/report.py | 21 +- trussme/visualize.py | 31 +- 3 files changed, 29 insertions(+), 1165 deletions(-) delete mode 100644 trussme/matplotlib_color_type.py diff --git a/trussme/matplotlib_color_type.py b/trussme/matplotlib_color_type.py deleted file mode 100644 index 731da1a..0000000 --- a/trussme/matplotlib_color_type.py +++ /dev/null @@ -1,1142 +0,0 @@ -from typing import Union, Literal, Tuple - -MatplotlibBaseColor = Literal[ - "b", - "g", - "r", - "c", - "m", - "y", - "k", - "w", -] - -MatplotlibTableauColor = Literal[ - "tab:blue", - "tab:orange", - "tab:green", - "tab:red", - "tab:purple", - "tab:brown", - "tab:pink", - "tab:gray", - "tab:olive", - "tab:cyan", -] - -MatplotlibCssColor = Literal[ - "aliceblue", - "antiquewhite", - "aqua", - "aquamarine", - "azure", - "beige", - "bisque", - "black", - "blanchedalmond", - "blue", - "blueviolet", - "brown", - "burlywood", - "cadetblue", - "chartreuse", - "chocolate", - "coral", - "cornflowerblue", - "cornsilk", - "crimson", - "cyan", - "darkblue", - "darkcyan", - "darkgoldenrod", - "darkgray", - "darkgreen", - "darkgrey", - "darkkhaki", - "darkmagenta", - "darkolivegreen", - "darkorange", - "darkorchid", - "darkred", - "darksalmon", - "darkseagreen", - "darkslateblue", - "darkslategray", - "darkslategrey", - "darkturquoise", - "darkviolet", - "deeppink", - "deepskyblue", - "dimgray", - "dimgrey", - "dodgerblue", - "firebrick", - "floralwhite", - "forestgreen", - "fuchsia", - "gainsboro", - "ghostwhite", - "gold", - "goldenrod", - "gray", - "green", - "greenyellow", - "grey", - "honeydew", - "hotpink", - "indianred", - "indigo", - "ivory", - "khaki", - "lavender", - "lavenderblush", - "lawngreen", - "lemonchiffon", - "lightblue", - "lightcoral", - "lightcyan", - "lightgoldenrodyellow", - "lightgray", - "lightgreen", - "lightgrey", - "lightpink", - "lightsalmon", - "lightseagreen", - "lightskyblue", - "lightslategray", - "lightslategrey", - "lightsteelblue", - "lightyellow", - "lime", - "limegreen", - "linen", - "magenta", - "maroon", - "mediumaquamarine", - "mediumblue", - "mediumorchid", - "mediumpurple", - "mediumseagreen", - "mediumslateblue", - "mediumspringgreen", - "mediumturquoise", - "mediumvioletred", - "midnightblue", - "mintcream", - "mistyrose", - "moccasin", - "navajowhite", - "navy", - "oldlace", - "olive", - "olivedrab", - "orange", - "orangered", - "orchid", - "palegoldenrod", - "palegreen", - "paleturquoise", - "palevioletred", - "papayawhip", - "peachpuff", - "peru", - "pink", - "plum", - "powderblue", - "purple", - "rebeccapurple", - "red", - "rosybrown", - "royalblue", - "saddlebrown", - "salmon", - "sandybrown", - "seagreen", - "seashell", - "sienna", - "silver", - "skyblue", - "slateblue", - "slategray", - "slategrey", - "snow", - "springgreen", - "steelblue", - "tan", - "teal", - "thistle", - "tomato", - "turquoise", - "violet", - "wheat", - "white", - "whitesmoke", - "yellow", - "yellowgreen", -] - -# New type that includes all matplotib colors -MatplotlibXkcdColor = Literal[ - "xkcd:cloudy blue", - "xkcd:dark pastel green", - "xkcd:dust", - "xkcd:electric lime", - "xkcd:fresh green", - "xkcd:light eggplant", - "xkcd:nasty green", - "xkcd:really light blue", - "xkcd:tea", - "xkcd:warm purple", - "xkcd:yellowish tan", - "xkcd:cement", - "xkcd:dark grass green", - "xkcd:dusty teal", - "xkcd:grey teal", - "xkcd:macaroni and cheese", - "xkcd:pinkish tan", - "xkcd:spruce", - "xkcd:strong blue", - "xkcd:toxic green", - "xkcd:windows blue", - "xkcd:blue blue", - "xkcd:blue with a hint of purple", - "xkcd:booger", - "xkcd:bright sea green", - "xkcd:dark green blue", - "xkcd:deep turquoise", - "xkcd:green teal", - "xkcd:strong pink", - "xkcd:bland", - "xkcd:deep aqua", - "xkcd:lavender pink", - "xkcd:light moss green", - "xkcd:light seafoam green", - "xkcd:olive yellow", - "xkcd:pig pink", - "xkcd:deep lilac", - "xkcd:desert", - "xkcd:dusty lavender", - "xkcd:purpley grey", - "xkcd:purply", - "xkcd:candy pink", - "xkcd:light pastel green", - "xkcd:boring green", - "xkcd:kiwi green", - "xkcd:light grey green", - "xkcd:orange pink", - "xkcd:tea green", - "xkcd:very light brown", - "xkcd:egg shell", - "xkcd:eggplant purple", - "xkcd:powder pink", - "xkcd:reddish grey", - "xkcd:baby shit brown", - "xkcd:liliac", - "xkcd:stormy blue", - "xkcd:ugly brown", - "xkcd:custard", - "xkcd:darkish pink", - "xkcd:deep brown", - "xkcd:greenish beige", - "xkcd:manilla", - "xkcd:off blue", - "xkcd:battleship grey", - "xkcd:browny green", - "xkcd:bruise", - "xkcd:kelley green", - "xkcd:sickly yellow", - "xkcd:sunny yellow", - "xkcd:azul", - "xkcd:darkgreen", - "xkcd:green/yellow", - "xkcd:lichen", - "xkcd:light light green", - "xkcd:pale gold", - "xkcd:sun yellow", - "xkcd:tan green", - "xkcd:burple", - "xkcd:butterscotch", - "xkcd:toupe", - "xkcd:dark cream", - "xkcd:indian red", - "xkcd:light lavendar", - "xkcd:poison green", - "xkcd:baby puke green", - "xkcd:bright yellow green", - "xkcd:charcoal grey", - "xkcd:squash", - "xkcd:cinnamon", - "xkcd:light pea green", - "xkcd:radioactive green", - "xkcd:raw sienna", - "xkcd:baby purple", - "xkcd:cocoa", - "xkcd:light royal blue", - "xkcd:orangeish", - "xkcd:rust brown", - "xkcd:sand brown", - "xkcd:swamp", - "xkcd:tealish green", - "xkcd:burnt siena", - "xkcd:camo", - "xkcd:dusk blue", - "xkcd:fern", - "xkcd:old rose", - "xkcd:pale light green", - "xkcd:peachy pink", - "xkcd:rosy pink", - "xkcd:light bluish green", - "xkcd:light bright green", - "xkcd:light neon green", - "xkcd:light seafoam", - "xkcd:tiffany blue", - "xkcd:washed out green", - "xkcd:browny orange", - "xkcd:nice blue", - "xkcd:sapphire", - "xkcd:greyish teal", - "xkcd:orangey yellow", - "xkcd:parchment", - "xkcd:straw", - "xkcd:very dark brown", - "xkcd:terracota", - "xkcd:ugly blue", - "xkcd:clear blue", - "xkcd:creme", - "xkcd:foam green", - "xkcd:grey/green", - "xkcd:light gold", - "xkcd:seafoam blue", - "xkcd:topaz", - "xkcd:violet pink", - "xkcd:wintergreen", - "xkcd:yellow tan", - "xkcd:dark fuchsia", - "xkcd:indigo blue", - "xkcd:light yellowish green", - "xkcd:pale magenta", - "xkcd:rich purple", - "xkcd:sunflower yellow", - "xkcd:green/blue", - "xkcd:leather", - "xkcd:racing green", - "xkcd:vivid purple", - "xkcd:dark royal blue", - "xkcd:hazel", - "xkcd:muted pink", - "xkcd:booger green", - "xkcd:canary", - "xkcd:cool grey", - "xkcd:dark taupe", - "xkcd:darkish purple", - "xkcd:true green", - "xkcd:coral pink", - "xkcd:dark sage", - "xkcd:dark slate blue", - "xkcd:flat blue", - "xkcd:mushroom", - "xkcd:rich blue", - "xkcd:dirty purple", - "xkcd:greenblue", - "xkcd:icky green", - "xkcd:light khaki", - "xkcd:warm blue", - "xkcd:dark hot pink", - "xkcd:deep sea blue", - "xkcd:carmine", - "xkcd:dark yellow green", - "xkcd:pale peach", - "xkcd:plum purple", - "xkcd:golden rod", - "xkcd:neon red", - "xkcd:old pink", - "xkcd:very pale blue", - "xkcd:blood orange", - "xkcd:grapefruit", - "xkcd:sand yellow", - "xkcd:clay brown", - "xkcd:dark blue grey", - "xkcd:flat green", - "xkcd:light green blue", - "xkcd:warm pink", - "xkcd:dodger blue", - "xkcd:gross green", - "xkcd:ice", - "xkcd:metallic blue", - "xkcd:pale salmon", - "xkcd:sap green", - "xkcd:algae", - "xkcd:bluey grey", - "xkcd:greeny grey", - "xkcd:highlighter green", - "xkcd:light light blue", - "xkcd:light mint", - "xkcd:raw umber", - "xkcd:vivid blue", - "xkcd:deep lavender", - "xkcd:dull teal", - "xkcd:light greenish blue", - "xkcd:mud green", - "xkcd:pinky", - "xkcd:red wine", - "xkcd:shit green", - "xkcd:tan brown", - "xkcd:darkblue", - "xkcd:rosa", - "xkcd:lipstick", - "xkcd:pale mauve", - "xkcd:claret", - "xkcd:dandelion", - "xkcd:orangered", - "xkcd:poop green", - "xkcd:ruby", - "xkcd:dark", - "xkcd:greenish turquoise", - "xkcd:pastel red", - "xkcd:piss yellow", - "xkcd:bright cyan", - "xkcd:dark coral", - "xkcd:algae green", - "xkcd:darkish red", - "xkcd:reddy brown", - "xkcd:blush pink", - "xkcd:camouflage green", - "xkcd:lawn green", - "xkcd:putty", - "xkcd:vibrant blue", - "xkcd:dark sand", - "xkcd:purple/blue", - "xkcd:saffron", - "xkcd:twilight", - "xkcd:warm brown", - "xkcd:bluegrey", - "xkcd:bubble gum pink", - "xkcd:duck egg blue", - "xkcd:greenish cyan", - "xkcd:petrol", - "xkcd:royal", - "xkcd:butter", - "xkcd:dusty orange", - "xkcd:off yellow", - "xkcd:pale olive green", - "xkcd:orangish", - "xkcd:leaf", - "xkcd:light blue grey", - "xkcd:dried blood", - "xkcd:lightish purple", - "xkcd:rusty red", - "xkcd:lavender blue", - "xkcd:light grass green", - "xkcd:light mint green", - "xkcd:sunflower", - "xkcd:velvet", - "xkcd:brick orange", - "xkcd:lightish red", - "xkcd:pure blue", - "xkcd:twilight blue", - "xkcd:violet red", - "xkcd:yellowy brown", - "xkcd:carnation", - "xkcd:muddy yellow", - "xkcd:dark seafoam green", - "xkcd:deep rose", - "xkcd:dusty red", - "xkcd:grey/blue", - "xkcd:lemon lime", - "xkcd:purple/pink", - "xkcd:brown yellow", - "xkcd:purple brown", - "xkcd:wisteria", - "xkcd:banana yellow", - "xkcd:lipstick red", - "xkcd:water blue", - "xkcd:brown grey", - "xkcd:vibrant purple", - "xkcd:baby green", - "xkcd:barf green", - "xkcd:eggshell blue", - "xkcd:sandy yellow", - "xkcd:cool green", - "xkcd:pale", - "xkcd:blue/grey", - "xkcd:hot magenta", - "xkcd:greyblue", - "xkcd:purpley", - "xkcd:baby shit green", - "xkcd:brownish pink", - "xkcd:dark aquamarine", - "xkcd:diarrhea", - "xkcd:light mustard", - "xkcd:pale sky blue", - "xkcd:turtle green", - "xkcd:bright olive", - "xkcd:dark grey blue", - "xkcd:greeny brown", - "xkcd:lemon green", - "xkcd:light periwinkle", - "xkcd:seaweed green", - "xkcd:sunshine yellow", - "xkcd:ugly purple", - "xkcd:medium pink", - "xkcd:puke brown", - "xkcd:very light pink", - "xkcd:viridian", - "xkcd:bile", - "xkcd:faded yellow", - "xkcd:very pale green", - "xkcd:vibrant green", - "xkcd:bright lime", - "xkcd:spearmint", - "xkcd:light aquamarine", - "xkcd:light sage", - "xkcd:yellowgreen", - "xkcd:baby poo", - "xkcd:dark seafoam", - "xkcd:deep teal", - "xkcd:heather", - "xkcd:rust orange", - "xkcd:dirty blue", - "xkcd:fern green", - "xkcd:bright lilac", - "xkcd:weird green", - "xkcd:peacock blue", - "xkcd:avocado green", - "xkcd:faded orange", - "xkcd:grape purple", - "xkcd:hot green", - "xkcd:lime yellow", - "xkcd:mango", - "xkcd:shamrock", - "xkcd:bubblegum", - "xkcd:purplish brown", - "xkcd:vomit yellow", - "xkcd:pale cyan", - "xkcd:key lime", - "xkcd:tomato red", - "xkcd:lightgreen", - "xkcd:merlot", - "xkcd:night blue", - "xkcd:purpleish pink", - "xkcd:apple", - "xkcd:baby poop green", - "xkcd:green apple", - "xkcd:heliotrope", - "xkcd:yellow/green", - "xkcd:almost black", - "xkcd:cool blue", - "xkcd:leafy green", - "xkcd:mustard brown", - "xkcd:dusk", - "xkcd:dull brown", - "xkcd:frog green", - "xkcd:vivid green", - "xkcd:bright light green", - "xkcd:fluro green", - "xkcd:kiwi", - "xkcd:seaweed", - "xkcd:navy green", - "xkcd:ultramarine blue", - "xkcd:iris", - "xkcd:pastel orange", - "xkcd:yellowish orange", - "xkcd:perrywinkle", - "xkcd:tealish", - "xkcd:dark plum", - "xkcd:pear", - "xkcd:pinkish orange", - "xkcd:midnight purple", - "xkcd:light urple", - "xkcd:dark mint", - "xkcd:greenish tan", - "xkcd:light burgundy", - "xkcd:turquoise blue", - "xkcd:ugly pink", - "xkcd:sandy", - "xkcd:electric pink", - "xkcd:muted purple", - "xkcd:mid green", - "xkcd:greyish", - "xkcd:neon yellow", - "xkcd:banana", - "xkcd:carnation pink", - "xkcd:tomato", - "xkcd:sea", - "xkcd:muddy brown", - "xkcd:turquoise green", - "xkcd:buff", - "xkcd:fawn", - "xkcd:muted blue", - "xkcd:pale rose", - "xkcd:dark mint green", - "xkcd:amethyst", - "xkcd:blue/green", - "xkcd:chestnut", - "xkcd:sick green", - "xkcd:pea", - "xkcd:rusty orange", - "xkcd:stone", - "xkcd:rose red", - "xkcd:pale aqua", - "xkcd:deep orange", - "xkcd:earth", - "xkcd:mossy green", - "xkcd:grassy green", - "xkcd:pale lime green", - "xkcd:light grey blue", - "xkcd:pale grey", - "xkcd:asparagus", - "xkcd:blueberry", - "xkcd:purple red", - "xkcd:pale lime", - "xkcd:greenish teal", - "xkcd:caramel", - "xkcd:deep magenta", - "xkcd:light peach", - "xkcd:milk chocolate", - "xkcd:ocher", - "xkcd:off green", - "xkcd:purply pink", - "xkcd:lightblue", - "xkcd:dusky blue", - "xkcd:golden", - "xkcd:light beige", - "xkcd:butter yellow", - "xkcd:dusky purple", - "xkcd:french blue", - "xkcd:ugly yellow", - "xkcd:greeny yellow", - "xkcd:orangish red", - "xkcd:shamrock green", - "xkcd:orangish brown", - "xkcd:tree green", - "xkcd:deep violet", - "xkcd:gunmetal", - "xkcd:blue/purple", - "xkcd:cherry", - "xkcd:sandy brown", - "xkcd:warm grey", - "xkcd:dark indigo", - "xkcd:midnight", - "xkcd:bluey green", - "xkcd:grey pink", - "xkcd:soft purple", - "xkcd:blood", - "xkcd:brown red", - "xkcd:medium grey", - "xkcd:berry", - "xkcd:poo", - "xkcd:purpley pink", - "xkcd:light salmon", - "xkcd:snot", - "xkcd:easter purple", - "xkcd:light yellow green", - "xkcd:dark navy blue", - "xkcd:drab", - "xkcd:light rose", - "xkcd:rouge", - "xkcd:purplish red", - "xkcd:slime green", - "xkcd:baby poop", - "xkcd:irish green", - "xkcd:pink/purple", - "xkcd:dark navy", - "xkcd:greeny blue", - "xkcd:light plum", - "xkcd:pinkish grey", - "xkcd:dirty orange", - "xkcd:rust red", - "xkcd:pale lilac", - "xkcd:orangey red", - "xkcd:primary blue", - "xkcd:kermit green", - "xkcd:brownish purple", - "xkcd:murky green", - "xkcd:wheat", - "xkcd:very dark purple", - "xkcd:bottle green", - "xkcd:watermelon", - "xkcd:deep sky blue", - "xkcd:fire engine red", - "xkcd:yellow ochre", - "xkcd:pumpkin orange", - "xkcd:pale olive", - "xkcd:light lilac", - "xkcd:lightish green", - "xkcd:carolina blue", - "xkcd:mulberry", - "xkcd:shocking pink", - "xkcd:auburn", - "xkcd:bright lime green", - "xkcd:celadon", - "xkcd:pinkish brown", - "xkcd:poo brown", - "xkcd:bright sky blue", - "xkcd:celery", - "xkcd:dirt brown", - "xkcd:strawberry", - "xkcd:dark lime", - "xkcd:copper", - "xkcd:medium brown", - "xkcd:muted green", - "xkcd:robin's egg", - "xkcd:bright aqua", - "xkcd:bright lavender", - "xkcd:ivory", - "xkcd:very light purple", - "xkcd:light navy", - "xkcd:pink red", - "xkcd:olive brown", - "xkcd:poop brown", - "xkcd:mustard green", - "xkcd:ocean green", - "xkcd:very dark blue", - "xkcd:dusty green", - "xkcd:light navy blue", - "xkcd:minty green", - "xkcd:adobe", - "xkcd:barney", - "xkcd:jade green", - "xkcd:bright light blue", - "xkcd:light lime", - "xkcd:dark khaki", - "xkcd:orange yellow", - "xkcd:ocre", - "xkcd:maize", - "xkcd:faded pink", - "xkcd:british racing green", - "xkcd:sandstone", - "xkcd:mud brown", - "xkcd:light sea green", - "xkcd:robin egg blue", - "xkcd:aqua marine", - "xkcd:dark sea green", - "xkcd:soft pink", - "xkcd:orangey brown", - "xkcd:cherry red", - "xkcd:burnt yellow", - "xkcd:brownish grey", - "xkcd:camel", - "xkcd:purplish grey", - "xkcd:marine", - "xkcd:greyish pink", - "xkcd:pale turquoise", - "xkcd:pastel yellow", - "xkcd:bluey purple", - "xkcd:canary yellow", - "xkcd:faded red", - "xkcd:sepia", - "xkcd:coffee", - "xkcd:bright magenta", - "xkcd:mocha", - "xkcd:ecru", - "xkcd:purpleish", - "xkcd:cranberry", - "xkcd:darkish green", - "xkcd:brown orange", - "xkcd:dusky rose", - "xkcd:melon", - "xkcd:sickly green", - "xkcd:silver", - "xkcd:purply blue", - "xkcd:purpleish blue", - "xkcd:hospital green", - "xkcd:shit brown", - "xkcd:mid blue", - "xkcd:amber", - "xkcd:easter green", - "xkcd:soft blue", - "xkcd:cerulean blue", - "xkcd:golden brown", - "xkcd:bright turquoise", - "xkcd:red pink", - "xkcd:red purple", - "xkcd:greyish brown", - "xkcd:vermillion", - "xkcd:russet", - "xkcd:steel grey", - "xkcd:lighter purple", - "xkcd:bright violet", - "xkcd:prussian blue", - "xkcd:slate green", - "xkcd:dirty pink", - "xkcd:dark blue green", - "xkcd:pine", - "xkcd:yellowy green", - "xkcd:dark gold", - "xkcd:bluish", - "xkcd:darkish blue", - "xkcd:dull red", - "xkcd:pinky red", - "xkcd:bronze", - "xkcd:pale teal", - "xkcd:military green", - "xkcd:barbie pink", - "xkcd:bubblegum pink", - "xkcd:pea soup green", - "xkcd:dark mustard", - "xkcd:shit", - "xkcd:medium purple", - "xkcd:very dark green", - "xkcd:dirt", - "xkcd:dusky pink", - "xkcd:red violet", - "xkcd:lemon yellow", - "xkcd:pistachio", - "xkcd:dull yellow", - "xkcd:dark lime green", - "xkcd:denim blue", - "xkcd:teal blue", - "xkcd:lightish blue", - "xkcd:purpley blue", - "xkcd:light indigo", - "xkcd:swamp green", - "xkcd:brown green", - "xkcd:dark maroon", - "xkcd:hot purple", - "xkcd:dark forest green", - "xkcd:faded blue", - "xkcd:drab green", - "xkcd:light lime green", - "xkcd:snot green", - "xkcd:yellowish", - "xkcd:light blue green", - "xkcd:bordeaux", - "xkcd:light mauve", - "xkcd:ocean", - "xkcd:marigold", - "xkcd:muddy green", - "xkcd:dull orange", - "xkcd:steel", - "xkcd:electric purple", - "xkcd:fluorescent green", - "xkcd:yellowish brown", - "xkcd:blush", - "xkcd:soft green", - "xkcd:bright orange", - "xkcd:lemon", - "xkcd:purple grey", - "xkcd:acid green", - "xkcd:pale lavender", - "xkcd:violet blue", - "xkcd:light forest green", - "xkcd:burnt red", - "xkcd:khaki green", - "xkcd:cerise", - "xkcd:faded purple", - "xkcd:apricot", - "xkcd:dark olive green", - "xkcd:grey brown", - "xkcd:green grey", - "xkcd:true blue", - "xkcd:pale violet", - "xkcd:periwinkle blue", - "xkcd:light sky blue", - "xkcd:blurple", - "xkcd:green brown", - "xkcd:bluegreen", - "xkcd:bright teal", - "xkcd:brownish yellow", - "xkcd:pea soup", - "xkcd:forest", - "xkcd:barney purple", - "xkcd:ultramarine", - "xkcd:purplish", - "xkcd:puke yellow", - "xkcd:bluish grey", - "xkcd:dark periwinkle", - "xkcd:dark lilac", - "xkcd:reddish", - "xkcd:light maroon", - "xkcd:dusty purple", - "xkcd:terra cotta", - "xkcd:avocado", - "xkcd:marine blue", - "xkcd:teal green", - "xkcd:slate grey", - "xkcd:lighter green", - "xkcd:electric green", - "xkcd:dusty blue", - "xkcd:golden yellow", - "xkcd:bright yellow", - "xkcd:light lavender", - "xkcd:umber", - "xkcd:poop", - "xkcd:dark peach", - "xkcd:jungle green", - "xkcd:eggshell", - "xkcd:denim", - "xkcd:yellow brown", - "xkcd:dull purple", - "xkcd:chocolate brown", - "xkcd:wine red", - "xkcd:neon blue", - "xkcd:dirty green", - "xkcd:light tan", - "xkcd:ice blue", - "xkcd:cadet blue", - "xkcd:dark mauve", - "xkcd:very light blue", - "xkcd:grey purple", - "xkcd:pastel pink", - "xkcd:very light green", - "xkcd:dark sky blue", - "xkcd:evergreen", - "xkcd:dull pink", - "xkcd:aubergine", - "xkcd:mahogany", - "xkcd:reddish orange", - "xkcd:deep green", - "xkcd:vomit green", - "xkcd:purple pink", - "xkcd:dusty pink", - "xkcd:faded green", - "xkcd:camo green", - "xkcd:pinky purple", - "xkcd:pink purple", - "xkcd:brownish red", - "xkcd:dark rose", - "xkcd:mud", - "xkcd:brownish", - "xkcd:emerald green", - "xkcd:pale brown", - "xkcd:dull blue", - "xkcd:burnt umber", - "xkcd:medium green", - "xkcd:clay", - "xkcd:light aqua", - "xkcd:light olive green", - "xkcd:brownish orange", - "xkcd:dark aqua", - "xkcd:purplish pink", - "xkcd:dark salmon", - "xkcd:greenish grey", - "xkcd:jade", - "xkcd:ugly green", - "xkcd:dark beige", - "xkcd:emerald", - "xkcd:pale red", - "xkcd:light magenta", - "xkcd:sky", - "xkcd:light cyan", - "xkcd:yellow orange", - "xkcd:reddish purple", - "xkcd:reddish pink", - "xkcd:orchid", - "xkcd:dirty yellow", - "xkcd:orange red", - "xkcd:deep red", - "xkcd:orange brown", - "xkcd:cobalt blue", - "xkcd:neon pink", - "xkcd:rose pink", - "xkcd:greyish purple", - "xkcd:raspberry", - "xkcd:aqua green", - "xkcd:salmon pink", - "xkcd:tangerine", - "xkcd:brownish green", - "xkcd:red brown", - "xkcd:greenish brown", - "xkcd:pumpkin", - "xkcd:pine green", - "xkcd:charcoal", - "xkcd:baby pink", - "xkcd:cornflower", - "xkcd:blue violet", - "xkcd:chocolate", - "xkcd:greyish green", - "xkcd:scarlet", - "xkcd:green yellow", - "xkcd:dark olive", - "xkcd:sienna", - "xkcd:pastel purple", - "xkcd:terracotta", - "xkcd:aqua blue", - "xkcd:sage green", - "xkcd:blood red", - "xkcd:deep pink", - "xkcd:grass", - "xkcd:moss", - "xkcd:pastel blue", - "xkcd:bluish green", - "xkcd:green blue", - "xkcd:dark tan", - "xkcd:greenish blue", - "xkcd:pale orange", - "xkcd:vomit", - "xkcd:forrest green", - "xkcd:dark lavender", - "xkcd:dark violet", - "xkcd:purple blue", - "xkcd:dark cyan", - "xkcd:olive drab", - "xkcd:pinkish", - "xkcd:cobalt", - "xkcd:neon purple", - "xkcd:light turquoise", - "xkcd:apple green", - "xkcd:dull green", - "xkcd:wine", - "xkcd:powder blue", - "xkcd:off white", - "xkcd:electric blue", - "xkcd:dark turquoise", - "xkcd:blue purple", - "xkcd:azure", - "xkcd:bright red", - "xkcd:pinkish red", - "xkcd:cornflower blue", - "xkcd:light olive", - "xkcd:grape", - "xkcd:greyish blue", - "xkcd:purplish blue", - "xkcd:yellowish green", - "xkcd:greenish yellow", - "xkcd:medium blue", - "xkcd:dusty rose", - "xkcd:light violet", - "xkcd:midnight blue", - "xkcd:bluish purple", - "xkcd:red orange", - "xkcd:dark magenta", - "xkcd:greenish", - "xkcd:ocean blue", - "xkcd:coral", - "xkcd:cream", - "xkcd:reddish brown", - "xkcd:burnt sienna", - "xkcd:brick", - "xkcd:sage", - "xkcd:grey green", - "xkcd:white", - "xkcd:robin's egg blue", - "xkcd:moss green", - "xkcd:steel blue", - "xkcd:eggplant", - "xkcd:light yellow", - "xkcd:leaf green", - "xkcd:light grey", - "xkcd:puke", - "xkcd:pinkish purple", - "xkcd:sea blue", - "xkcd:pale purple", - "xkcd:slate blue", - "xkcd:blue grey", - "xkcd:hunter green", - "xkcd:fuchsia", - "xkcd:crimson", - "xkcd:pale yellow", - "xkcd:ochre", - "xkcd:mustard yellow", - "xkcd:light red", - "xkcd:cerulean", - "xkcd:pale pink", - "xkcd:deep blue", - "xkcd:rust", - "xkcd:light teal", - "xkcd:slate", - "xkcd:goldenrod", - "xkcd:dark yellow", - "xkcd:dark grey", - "xkcd:army green", - "xkcd:grey blue", - "xkcd:seafoam", - "xkcd:puce", - "xkcd:spring green", - "xkcd:dark orange", - "xkcd:sand", - "xkcd:pastel green", - "xkcd:mint", - "xkcd:light orange", - "xkcd:bright pink", - "xkcd:chartreuse", - "xkcd:deep purple", - "xkcd:dark brown", - "xkcd:taupe", - "xkcd:pea green", - "xkcd:puke green", - "xkcd:kelly green", - "xkcd:seafoam green", - "xkcd:blue green", - "xkcd:khaki", - "xkcd:burgundy", - "xkcd:dark teal", - "xkcd:brick red", - "xkcd:royal purple", - "xkcd:plum", - "xkcd:mint green", - "xkcd:gold", - "xkcd:baby blue", - "xkcd:yellow green", - "xkcd:bright purple", - "xkcd:dark red", - "xkcd:pale blue", - "xkcd:grass green", - "xkcd:navy", - "xkcd:aquamarine", - "xkcd:burnt orange", - "xkcd:neon green", - "xkcd:bright blue", - "xkcd:rose", - "xkcd:light pink", - "xkcd:mustard", - "xkcd:indigo", - "xkcd:lime", - "xkcd:sea green", - "xkcd:periwinkle", - "xkcd:dark pink", - "xkcd:olive green", - "xkcd:peach", - "xkcd:pale green", - "xkcd:light brown", - "xkcd:hot pink", - "xkcd:black", - "xkcd:lilac", - "xkcd:navy blue", - "xkcd:royal blue", - "xkcd:beige", - "xkcd:salmon", - "xkcd:olive", - "xkcd:maroon", - "xkcd:bright green", - "xkcd:dark purple", - "xkcd:mauve", - "xkcd:forest green", - "xkcd:aqua", - "xkcd:cyan", - "xkcd:tan", - "xkcd:dark blue", - "xkcd:lavender", - "xkcd:turquoise", - "xkcd:dark green", - "xkcd:violet", - "xkcd:light purple", - "xkcd:lime green", - "xkcd:grey", - "xkcd:sky blue", - "xkcd:yellow", - "xkcd:magenta", - "xkcd:light green", - "xkcd:orange", - "xkcd:teal", - "xkcd:light blue", - "xkcd:red", - "xkcd:brown", - "xkcd:pink", - "xkcd:blue", - "xkcd:green", - "xkcd:purple", -] - -MatplotlibNamedColors = Union[ - MatplotlibXkcdColor, MatplotlibTableauColor, MatplotlibBaseColor, MatplotlibCssColor -] - -RgbColor = Tuple[float, float, float] -RgbaColor = Tuple[float, float, float, float] - -MatplotlibColorWithoutAlphaTuple = Union[MatplotlibNamedColors, RgbColor, RgbaColor] - -MatplotlibColor = Union[ - MatplotlibColorWithoutAlphaTuple, Tuple[MatplotlibColorWithoutAlphaTuple, float] -] diff --git a/trussme/report.py b/trussme/report.py index 59fbe71..7cb691e 100644 --- a/trussme/report.py +++ b/trussme/report.py @@ -1,5 +1,8 @@ import json +import io +import re +import matplotlib.pyplot import numpy import pandas import scipy @@ -9,6 +12,18 @@ from trussme.truss import Truss, Goals +def _fig_to_svg(fig: matplotlib.pyplot.Figure) -> str: + imgdata = io.StringIO() + fig.savefig(imgdata, format="svg") + imgdata.seek(0) # rewind the data + + svg = imgdata.getvalue() + svg = re.sub("(.*?)", "", svg) + svg = re.sub("url\(#(.*?)\)", "url(#truss)", svg) + svg = re.sub('', '', svg) + + return svg + def report_to_str(truss: Truss, goals: Goals, with_figures: bool = True) -> str: """ Generates a report on the truss @@ -235,7 +250,7 @@ def __generate_instantiation_information(truss, with_figures: bool = True) -> st instantiation = "# INSTANTIATION INFORMATION\n" if with_figures: - instantiation += trussme.visualize.plot_truss(truss) + "\n" + instantiation += _fig_to_svg(trussme.visualize.plot_truss(truss)) + "\n" # Print joint information instantiation += "## JOINTS\n" @@ -396,7 +411,7 @@ def __generate_stress_analysis(truss, goals, with_figures: bool = True) -> str: analysis += "\n## FORCES AND STRESSES\n" if with_figures: - analysis += trussme.visualize.plot_truss(truss, starting_shape="force") + "\n" + analysis += _fig_to_svg(trussme.visualize.plot_truss(truss, starting_shape="force")) + "\n" data = [] rows = [] @@ -435,7 +450,7 @@ def __generate_stress_analysis(truss, goals, with_figures: bool = True) -> str: if with_figures: analysis += ( - trussme.visualize.plot_truss(truss, starting_shape="k", deflected_shape="m") + _fig_to_svg(trussme.visualize.plot_truss(truss, starting_shape="k", deflected_shape="m")) + "\n" ) diff --git a/trussme/visualize.py b/trussme/visualize.py index b621518..19b5302 100644 --- a/trussme/visualize.py +++ b/trussme/visualize.py @@ -1,19 +1,19 @@ import matplotlib.pyplot -import io -import re import numpy -from typing import Union, Literal +from typing import Union, Literal, Any, Type -from .matplotlib_color_type import MatplotlibColor + +MatplotlibColor = Type[Any] +"""Type: New type to represent a matplotlib color""" def plot_truss( - truss, - starting_shape: Union[None, Literal["fos", "force"], MatplotlibColor] = "k", - deflected_shape: Union[None, Literal["fos", "force"], MatplotlibColor] = None, - exaggeration_factor: float = 10, - fos_threshold: float = 1.0, -) -> str: + truss, + starting_shape: Union[None, Literal["fos", "force"], MatplotlibColor] = "k", + deflected_shape: Union[None, Literal["fos", "force"], MatplotlibColor] = None, + exaggeration_factor: float = 10, + fos_threshold: float = 1.0, +) -> matplotlib.pyplot.Figure: """Plot the truss. Parameters @@ -102,13 +102,4 @@ def plot_truss( color=color, ) - imgdata = io.StringIO() - fig.savefig(imgdata, format="svg") - imgdata.seek(0) # rewind the data - - svg = imgdata.getvalue() - svg = re.sub("(.*?)", "", svg) - svg = re.sub("url\(#(.*?)\)", "url(#truss)", svg) - svg = re.sub('', '', svg) - - return svg + return fig