Aug 19, 2015 - GSoC 2015

Introduction

Hi, GSoC 2015 is almost over and in this blog post I want to draw a line under my activities related to GnuplotRB project and compare project proposal with developed gem.

Activities during this summer

CI, programming style and tests

Travis CI and Co

To be sure that I'm not breaking anything with new contributions, I added Travis CI build configuration for my project and used Codeclimate with its testcoverage gem. I ran tests (RSpec) via Travis on both MRI (2.0, 2.1, 2.2) and Jruby (9.0.0.0).

I also used Rubocop to check my code from time to time for style and code complexity issues.

For documenting I used RDoc until I realized that Rubydoc uses YARD to parse gem's documentation =). After it I fixed docs to satisfy YARD syntax so now it's readable on Rubydoc.

Functional style in Ruby

From the very beginning GnuplotRB's classes were immutable. Every time user changed it, a new object with given parameters was instantiated. Now that's true for simple methods (not the ones ending with ! or =). Destructive update methods (#option!(value) or #option = value) change state of existing object. The idea is taken from Ruby standart library (e.g., Array#sort and Array#sort!).

Pre-midterm contributions

Basic staff classes

I started gem development by designing several staff classes: Terminal, Datablock and Dataset. Their main purpose was to create a robust base for other plottable classes such as Plot and Multiplot.

GnuplotRB::Plot class

My first milestone was to develop staff classes and GnuplotRB::Plot that would allow users to plot 2D graphs. During second week I implemented Plot as container of Datasets with its own plotting methods.

GnuplotRB::Splot and Multiplot

After Plot was developed it was pretty simple to implement Splot on its base. The only difference between them is in constructor: the main plotting command for Plot is 'plot' while for Splot it's 'splot'.

Multiplot is a little bit different: it is container of plots so I had to implement handy methods for updating plots multiplot consists of.

Since most plotting methods (#to_png, #to_canvas etc) were the same for Plot and Multiplot, I decided to move them to Plottable module and mixin it into both classes. A little bit later I also moved all methods related to option handling into OptionHandling module and added it into Plottable via Module.extend. Later it allowed me to make Dataset plottable just by adding #plot method and mixing in it Plottable module.

Project state before midterm

See a blog post.

Post-midterm contributions

Error handling

For now error handling wors in the following way: - Gem checks if given terminal is available with current Gnuplot installation (e.g., if user tries to call Plot#to_missing_term, he will recieve an error). - Before outputting each command to Gnuplot pipe, GnuplotRB::Terminal now checks stderr for errors. This is far from ideal and if you have any ideas how to imrove it, please take a part in a discussion.

GnuplotRB::Animation

GnuplotRB::Animation is just container for plots with its own rules of outputting them. I created it as Multiplot's child, wrote new #plot and restricted some plotting possibilities (e.g., '#to_png').

Since up to this moment all other plottable classes were able to embed themselves into iRuby notebooks, I wanted to embed Animation's GIFs too. Now they are embedded as HTML =): GIF is converted to BASE64 and then inserted as <img .../> tag.

GnuplotRB::Fit

This module contain several public methods: ::fit_polynomial, ::fit_exp, ::fit_log, ::fit_sin. Each of them fits given data with methematical function mentioned in its name. If you want to use another function, I recommend you to look at ::fit method that accepts function as an argument.

The main problem I faced with was to get output from Gnuplot. Since Terminal's ErrorHandling catchs all the output, I had to write a method that collected all the errors and took data from them.

Notebooks

During GSoC I wrote several notebook to show GnuplotRB's features and provide examples for users. You can find them all in the notebook folder.

The rest

During last two weeks of GSoC I fixed my docs (made them compatible with YARD) and tests (improved coverage and found pair of bugs).

I also wrote a blog post for sciruby.com to introduce the gem to community.

Comparison

All features mentioned in project proposal were developed. Interface of GnuplotRB gem is very similar to proposed. I only added safe and destructive update methods and support for iRuby and Daru containers. I planned to provide GnuplotRB with Approximation class for fitting data, but later decided to add Fit module instead.

Jul 5, 2015 - GnuplotRB gem at midterm of GSOC 2015

Introduction

Hi, half of the GSOC 2015 is over so I think it's good time to draw a line under the work that is already done. My project is visualization library (GnuplotRB) for Ruby based on Gnuplot. In this post I'm going to write a few words about already implemented features and give several examples (mostly as links).

Gem repository (with README and installation notes).

Gem on RubyGems.

Documentation.

Features

Embedding plots into iRuby notebooks

GnuplotRB plots may be embedded into iRuby notebooks as images (terminals svg, png, jpeg and pngcairo are supported) or plain text (dumb terminal). They may be customized with canvas size, font family, font size etc. By default plots are embedded as svg and to change it one should use term option. Examples of embedding plots of different times may be found in a notebook.

2D and 3D plots

GnuplotRB is capable to plot vast range of plots from histograms to 3D heatmaps. Gem's repository contains examples of several plot types:

Others may be found in Gnuplot's examples.

Possible datasources

GnuplotRB may take data in Ruby container or in a file. Supported containers for now are Arrays, Daru::Vector and Daru::DataFrame. When data given in file, GnuplotRB pass filename to Gnuplot without reading the file into memory.

Examples of using different datasources:

Multiplot

You can not only plot several datasets in single coordinate system but place several coordinate systems on a canvas. Example notebook.

Discuss?

You're very welcome to request examples or help and report bugs at issues list. There are also questions that should be discussed:

Jun 24, 2015 - First half of june progress

Introduction

Hi, last several weeks I spend developing gem parts which allow to plot 3D visualizations (Splot) and place several plots on single layout (Multiplot). I found cases when current Terminal was unable to set some gnuplot options and fixed it. GnuplotRB now may be used in iRuby notebooks, see notebook readme Last week (15-19.06) I also reviewed ruby bindings for symengine (developed by Abinash Meher) and Alexej Gossmann reviewed my project.

3D plots and multiplotting

To implement plotting 3D visualizations with GnuplotRB I developed Splot that inherited almost all features from Plot. I also added example for that type of visualization and a notebook.

Multiplot class was developed to allow placing several visualizations on one layout. It takes several Plot or Splot objects and options. Most of options are handled just as in any other plottable object but Multiplot also have two speciefic options:

  • :title is a string that should be placed above all the plots on that layout
  • :layout is size of layout, possible values: [r, c], 'r c' and so on. 'r' here is number of rows and "c" is number of columns in Multiplot.

Unfortunately I still haven't add a notebook for that kind of plots (will add soon) but there is an example for it.

Multi word keys in options

Last week I found that some options of gnuplot have multi word keys (e.g. 'set style data ...' and 'set style fill ...'). Since GnuplotRB allows only one value for each option key and in this case the key (for GnuplotRB) is 'style' this options can't be used together. To avoid that issue I made GnuplotRB to permit option keys like :style_fill. In this case :style_fill and :style_data are different keys so they can be used together. Before outputting this options to gnuplot, GnuplotRB replaces underscores with spaces. If you have some other ideas how it should be implemented, there is an github issue where we can discuss it.

By the way I have one more subject that may be discussed: error handling.

Code review session

As it was stated on the meeting, last week was time for the first code review session. So I reviewed Ruby bindings for symengine (repository and pull request) developed by Abinash. I looked through his code and told him about places where in my opinion something should be done another way. I also tried installing his gem on my computer with Ubuntu 14.04 and installation was successful. I wanted to try to use some symengine features but they were WIP so I tested only gem installation and basic object creation.

During that code review session Alexej reviewed my code and found a bug that related to outputting updated data to gnuplot. His review was very thorough and helpful. He both pointed me on missing and wrong docs and fixed some of them in his pull request. And he also gave me idea about notebook with example that should be created.

Plans for nearest next weeks

  1. Add missing specs for Splot and Multiplot
  2. Add iRuby notebook for Multiplot
  3. Implement Daru support