Allow adding a text watermark to all the plots
KarthikRIyer opened this issue · 5 comments
This task will require you to implement the following:
- Add a new feature to existing plots that let the end users specify some text and use it as a watermark for their plot. The text drawing functions already exist. You need to add a function to the plot types that accept a String and use the drawing functions to add a watermark.
Hi, I'm planning on implementing this soon. Thanks!
Hi, thanks so much for your kind help before getting set me up with swiftplot on the Google Group. I was looking through the source files and was wondering where I should put the code to add the feature. I see the drawText function in /Sources/SwiftPlot/Renderer.swift, however, I don't know where the "plot types" file is.
@WilliamHYZhang The Plot Types are in the SwiftPlot directory, for example BarChart.swift, LineChart.swift, etc. You do not need to add the function to draw text to each of these plots. Take a look at BarChart.swift for example and try to understand how it works. As a hint, you would need to make changes to GraphLayout.swift, which is the file that contains the code to draw stuff that's common to all the plots. Hope that helps.
Also, you should claim the task on the GCI website, and also state which issue you are working on before proceeding to work on the task.
Best of luck! I look forward to seeing your work! 😄
@WilliamHYZhang Just some implementation advice here:
If you take a look at Matplotlib, you'll see that watermarks and text labels are just one of the kind of annotations they support.
So I would recommend making something like an Annotation
protocol. Very simple, like Plot
, just describing some object which can be drawn in a Rect using a given Renderer. Then you'd add a property on GraphLayout
of type [Annotation]
, where the user can add labels or anything else we add later (arrows, etc). You can expose this on the plots themselves with HasGraphLayout
, like we do for plotTitle
.
Then you'd add a label type which conforms to Annotation
, and make GraphLayout
tell them to draw when it draws the rest of the foreground.
Thank you for the guidance! Currently, I'm stuck on another task which prohibits me from claiming this one, so I thought I'd get a head start working on this task in the meantime. I will definitely take a look at the Matplotlib files and try to implement something similar to their watermark annotations in swiftplot.