mwshinn / CanD

6 stars 3 forks source link

Feature Added: make text in add_legend customizable #21

Closed syncrostone closed 1 month ago

syncrostone commented 1 month ago

As an example, the text color can now be set with the text_params field:

c = Canvas(5, 5, "cm")
c.add_legend(Point(1,3,"cm" ),[('entry one',{'text_params': {'color': 'orange'}, 'color': 'k'}),('entry two',{'text_params': {'color': 'blue'}, 'color': 'grey'})])
c.show()

Resulting in the following legend: example.pdf

mwshinn commented 1 month ago

Thanks for the PR! One bug though: the use of the pop function modifies the dictionary, so if you have a STYLE = {...} at the beginning of your file and pass it to this function more than once, the text_properties will be removed after the first invocation. Either make a copy first and modify the copy, or else construct a new dictionary which excludes the element to pass on. E.g., see this line

syncrostone commented 1 month ago

Good point! I modified the code so that the dictionary gets copied first instead.

mwshinn commented 1 month ago

Thanks Jasmine!