enso-org / dataframes

A library for working with tabular data in Luna.
https://luna-lang.org
MIT License
6 stars 5 forks source link

Support for saving charts as image files, as requested in #109 #119

Closed mwu-tow closed 5 years ago

mwu-tow commented 5 years ago

Charts can now be saved to image files. Sample usage below:

import Std.Base
import Std.Foreign.C.Value

import Dataframes.Internal.Utils
import Dataframes.Array
import Dataframes.Column
import Dataframes.Table
import Dataframes.Types

def main:
    c = Column.fromList "a" Int64Type [1,2,3,4,5]
    t = Table.fromColumns [c]
    t.plot "a" "a" . write 800 600 "foo.png"
mwu-tow commented 5 years ago

Proposed docstring:

    # Saves the chart to an image file.
    #
    # Image will have dimensions as requested in function arguments. 
    # The image file format is deduced from filename extension. Supported formats: eps, pdf, pgf, png, ps, raw, rgba, svg, svgz.
    #
    # > import Dataframes.Column
    # > import Dataframes.Types
    # > import Dataframes.Table
    # >
    # > def main:
    # >     l1 = [1,2,3,4,5]
    # >     l2 = [11,12,13,14,15]
    # >     col1 = Column.fromList "col1" Int64Type l1
    # >     col2 = Column.fromList "col2" Int64Type l2
    # >     table = Table.fromColumns [col1 , col2]
    # >     col = table.column "col1"
    # >     None
    #
    # errors:
    # An exception is raised when output file is not writable.
    # An exception is raised when output file extension is not of one of supported image formats.
    # An exception is raised when requested image width or height is less or equal to zero.
    #
    # `width`: Requested width of the image, must be greater than zero.
    # `height`: Requested height of the image, must be greater than zero.
    # `filename`: Output path where image will be stored, must be writable.
    #
    # `return`: None

Two points however raise my concerns: 1) apparently we will have to repeat this for every single chart type 2) if so, the sample snippet should be different for each chart — but then we need to have a proper sampels for every one of them