Contributing

You are welcome to make contributions to this project. The project main page is at Github.

Class Architecture

The classes in this project are built by composing a base class, BasePlot with different mixins to in the end provide full featured classes ready for production.

base.py

This module contains the basic classes used for building the actual classes that are used in generating the plots. It is structured around a base class called BasePlot that implements the common logic required for the project operations with some mixin classes to add it extra functionality by multiple inheritance.

class plottings.base.BasePlot

Base class of all the plot classes used in this library. It implements the basic protocol that gathers the data, draws the graph and passes it to an in memory file like object ready to be consumed.

buffer_class

alias of BytesIO

get_filetype()

Override this method to dinamically set the file format of the generated file.

get_image()

Returns a in memory file object with the plot image.

get_plot_data()

Override this method to provide data to plotter_function() method.

get_plot_options()

Override this method to provide the plotter function with extra parameters to customize the graphical generation.

get_save_options()

Override this method to provide get_image function with extra parameters to set file properties.

static plotter_function(data, **options)

Override this method with an statically linked function that returns a Matplotlib figure to be lately used to render the plot in given file formats.

Data:

A data structure that contains the information to be graphically modeled by the plotter function.

Options:

A dict of parameters used to customize the image rendering.

process_image(image_buffer)

Override this method to add modifications to the image such as watermarks before caching.

class plottings.base.CachedMixin

Mixin class to add cache functionality to the BasePlot object.

get_cache_key()

Override this method with a value that changes when plot regeneration is required.

class plottings.base.SVGPlotMixin

Mixing to generate a memory file containing an SVG figure.

buffer_class

alias of StringIO

class plottings.base.SVGZPlotMixin

Mixin to generate a memory file containing an SVGZ figure.

buffer_class

alias of BytesIO

class plottings.base.PNGPlotMixin

Mixin to generate a memory file containing a binary PNG figure.

buffer_class

alias of BytesIO

views.py

This module provides with a collection of Django View classes that respond to requests with HttpResponse objects with Matplotlib figures as payload.

class plottings.views.BasePlotView(**kwargs)

A Django View class that has the common logic of all project’s View classes. It is not intended to be used in production but instead to be subclassed and extended via mixins.

get(request, *args, **kwargs)

This methods generates the GET response.

get_disposition()

Override this method if you want to dinamically set the content disposition of the HttpResponse object.

get_encoding()

Override this method if you want to dinamically set the encoding of the generated file.

get_filename()

Override this method if you want to dinamically set the name of the file generated from the figure when the disposition is attachment.

get_headers(buffer)

Returns a dict of parameters to be used as headers of the response object. Override it to provide extend the values it contains.

get_mimetype()

Override this method if you want to dinamically set the mimetype of the generated file.

head(request, *args, **kwargs)

This methods generates the HEAD response.

http_response_class

alias of HttpResponse

value.py

This module provides with classes that assist in storing plots into variables ready to be passed to Django templates and include the plot within the html document.

class plottings.value.ValueMixin

This mixins provides BasePlot with the get_value() method that returns a safe string to be used inside a template. It also has the magic method __str__.py so it can be inyected to the template.

get_value()

Add the returned value of this method to the context dictionary that is passed to render the template.

class plottings.value.Base64ValueMixin

This mixin provides the BasePlot class with base64 encoding of its provided value through get_value() method. It also has the magic method __str__.py so it can be inyected to the template.

get_value()

Add the returned value of this method to the context dictionary that is passed to render the template.

file.py

This module provides the classes required to generate Django files ready to be stored in media directories.

class plottings.file.FileMixin

This mixin provides the BasePlot class with the capability of generating a in memory file to be passed to an Image field.

file_class

alias of File

get_file()

This method returns a Django file object ready to be assigned to an ImageField.

get_filename()

Override this method to dinamically change the name of the file object created by the get_file() method.

Testing Application

This software is tested using a Django testing application that is stored in the /testing_app directory. It provides two main features:

  • A tool for running the project test suite

  • A running webapp to test the results.

To run it only requires to install the requirements.txt in a virtualenv and with it activated launch ./manage.py runserver for running the test server and ./manage.py test to launch the testsuite.