KarthikRIyer / swiftplot

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

Improve default aesthetics of plot #33

Closed KarthikRIyer closed 5 years ago

KarthikRIyer commented 5 years ago

32

I've just enabled grid at the moment. I'm opening the PR just to track the progress.

KarthikRIyer commented 5 years ago

@BradLarson I have used the default fonts for text in both svg and agg. To support a different font I think I'll have to make significant changes in AGG atleast. I am looking into it now.

KarthikRIyer commented 5 years ago

@BradLarson @marcrasi what would be our purpose of rendering SVGs? I mean, why would the end user want to use SVG? Will he/she view it in a browser? Why I'm asking this is because, on searching, the ways I'm getting, to use custom fonts in an SVG are using CSS like here: https://graphicdesign.stackexchange.com/a/10735 This doesn't work on the default image viewer in Ubuntu, but works in a browser.

BradLarson commented 5 years ago

@KarthikRIyer - My primary driver for SVGs was to help make sure the interface was generic enough to support very different kinds of rendering. You don't have access to Core Graphics readily on your end, so this seemed like a good proxy.

I can see a vector backend renderer like this being used for the web as the primary target, so if you want to focus on ways of making that work for custom fonts, that might be a good first step. We can figure out later if something more general is needed for other applications we'd come across.

KarthikRIyer commented 5 years ago

@BradLarson @marcrasi I am now able to use custom fonts in both renderers. But it still needs polishing. I am using the default font used in matplotlib i.e. DejaVuSans. What I need to figure out next is how to set it as the default font. Now I've hardcoded everything. For AGG the font needs to be present in the directory from where the executable is executed and for SVG the font file needs to be in the same directory as the image.

KarthikRIyer commented 5 years ago

@BradLarson @marcrasi I've changed the default font to Roboto-Regular. For SVG images I'm getting the font from the google fonts API. DejaVuSans wasn't available on google fonts, and trying to use the url for that font from anywhere else gave me a CORS error. That's why I decided to go for goggle fonts. So if the end user needs to use a different font he/she needs to pass the name of any font available on google fonts.

For AGG, I'm not sure how I can get a font to be default. I have to pass in the path of the font to the renderer. Right now the font is in the topmost directory of the library, from where we run the command swift build. So it will work only when any executable is executed form there. To bundle the font with the library I thought I could use an online tool to convert the ttf file to a char array and then load it from memory. But AGG doesn't provide any methods to do that. So right now I'm trying to understand AGG's code and will see if I can implement my own method to load the font from memory.

What do you think? Is there a simpler way of achieving this? Or some way we can get the path to the ttf file in the library's directory irrespective of where we execute it from?

KarthikRIyer commented 5 years ago

Also I'm getting this:

'CFreeType' /home/karthik/swiftplot/.build/checkouts/CFreeType: warning: system packages are deprecated; use system library targets instead

I did as given here but it's still the same.

Link to CFreeType repo where I made the changes: https://github.com/KarthikRIyer/CFreeType

KarthikRIyer commented 5 years ago

29

@BradLarson @marcrasi please review. Next I'll move to implementing a CoreGraphics Renderer and simultaneously fix other problems we might notice.

KarthikRIyer commented 5 years ago

Also @BradLarson any ideas on how to go about getting it to build on Mac? I believe once FreeType is installed this should build. But I've been unable to install FreeType on Mac.

KarthikRIyer commented 5 years ago

Merging now.