KarthikRIyer / swiftplot

Swift library for Data Visualization :bar_chart:
Apache License 2.0
400 stars 39 forks source link

Allow adding a text watermark to all the plots #40

Closed KarthikRIyer closed 4 years ago

KarthikRIyer commented 4 years ago

This task will require you to implement the following:

WilliamHYZhang commented 4 years ago

Hi, I'm planning on implementing this soon. Thanks!

WilliamHYZhang commented 4 years ago

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.

KarthikRIyer commented 4 years ago

@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! 😄

karwa commented 4 years ago

@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.

WilliamHYZhang commented 4 years ago

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.