GSoC 2019 Project [ Rubyplot ] discussion

Hello everyone,

I am creating this forum for discussion of Rubyplot 2019 GSoC project ( project link ).

I will be posting my daily updates, blog links here and will use it for discussion of the project.

[RUBYPLOT-GSOC][DAILY][31 May] The beginning

Planned Progress
Correcting the transform function to improve the plot.

Progress

  • Revised the codebase.
  • Tried to correct the transform function and realised that within_window function needs to be done first.
  • Optimized text rotation by plotting it only when write function is called. (the coordinate system is translated to its original value before proceeding for next text) (Will explain text rotation in the next blog)

Problems

  • Rubyplot needs a standardised unit system as GR and Magick both use various units for points,
    text, etc. This is a major challenge which needs to be solved. This may be solved by using the figsize_unit argument in the figure, I will look into it further later.
  • Magick backend lacks a within_window function which is needed for further development since it has no inbuilt function like setviewport, a function will have to be created for solving this. This will have to be done first before proceeding further.

Plans

  • (For next 4 days) I will find a way to create the within_window function and then proceed to correct transform function and implementing major and minor ticks in the X and Y axes.

[RUBYPLOT-GSOC][DAILY][1 June] Setting up basics for the backend

Planned Progress
Implementing ticks in X and Y axes.

Progress

  • Created the within_window function only for abs = false.
  • Corrected the transform function.
  • The scatter plot looks like this currently(with canvas height and width 500 pixels) :
    exp
    (Legend box and text are missing due to incomplete within_window function (for abs = true))

Problems

  • Understanding the different units used is confusing, I struggled a lot to understand it.
  • This is mainly due to scaling issues which have not yet been tackled, I will work on that after completion of the within_window function.
  • Due to lack of setviewport and setwindow functions in Magick, I found a way to implement them using translating and scaling (and then rescaling and retranslating to original coordinates after calling the block), I feel doing this is inefficient but is the only way to implement it.

Plans

  • After implementing within_window for abs = true, the basic plot will be ready after which I will implement ticks (by end of 4th June)

You can name the translating functions the same as they are in GR so as to keep the code understandable and uniform.

For example put the Magick::setviewport function inside a module MagickWrapper::Helpers and put all these functions in there which help you make Magick behave more like a plotting library than simply an image manipulation tool.

I have combined setwindow and setviewport functions, separating them would be a difficult task as it would require scaling and translating twice(will explain in the next blog). For translation, magick’s inbuilt function translate is used and there’s no separate function for translation.

[RUBYPLOT-GSOC][DAILY][3 June] Completed setting up basics for the backend

Planned Progress
researching on and creating within_window function

Progress

  • Completed within_window function for abs = true by modifying the transform function.
  • Corrected scaling issues by changing canvas height and width when require based on figsize_unit variable (cm, inch or pixel).
  • Found and corrected a small bug in scatter plot: For setting the colour of markers marker_color function should be used and currently doing this does not change the colour in the legend box and so found a way by changing color variable in data to fix the bug (waiting for approval from @v0dro since it is a change in the frontend )
  • Currently, the scatter plot looks like this (For default size 40 cm and colour of markers plum purple):

Problems

  • Scaling in this way is limited to magick backend and not for GR and so for consistency may be a different method can be found (or a similar method can be found for GR)
  • implementing within_window function with abs = true (i.e. plot units in rubyplot coordinates) was done by improving transform_x and tranform_y function so as they can transform rubyplot coordinates (abs = true) and plot data coordinates (abs = false) to pixel values.
  • There was a small bug in scatter plot (refer to point 3 in progress)

Plans

  • Implementing ticks for Magick backend (by EOD 4th June) and writing a blog after this.
  • Starting with improving scatter plot.

I don’t entirely understand what you mean by ‘scaling in this way is limited to magick bacend and not for GR’.

Can you please explain?

Also, what is your approach for the XTicks? GR does it with a callback but I think that is a very limiting approach if all you want to do is specify your ticks in an array.

Ah I see. But how do you change the ‘view’ on the canvas on which you are plotting? Do you do this at the same time as setting the co-ordinates of that view?

The viewports are very useful when working with multiple subplots.

I will explain my approach in a blog which I will write by EOD tomorrow.

The only possible way I think in magick backend is by specifying the ticks in an array and then at the time of plotting x axis, iterate through the array and make lines at the point where tick is required. I am trying this approach currently.

[RUBYPLOT-GSOC][DAILY][4 June] Design decisions

Planned Progress
Completing the within_window function

Progress

  • Found a bug in frontend for adding subplots, in the function add_subplot! the array should use nrow -1 and ncol - 1 as the array is 0-indexed and the numbering for subplots start with 1.
  • Updated my website (enables disqus) for future blogs.
  • Revised the within_window function and corrected a small bug (had used bottom margins instead of top margins) (magick has its origin at top left corner)

Problems

  • While implementing ticks, where should the ticks be placed and how does the GR backend make them is unclear? (will discuss with @v0dro)
  • The only way to make ticks in magick backend is to make small lines where tick is required.
  • usage of XTick and YTick object is unclear and why is(x/y)_minor_ticks_count not passed in axes_map? (alternatively where is (x/y)_major_ticks_count) used?

Plans

  • Implementing ticks will take a lot of time as it (maybe) requires changes in frontend and major design decisions. I will work on ticks parallelly with the daily planned tasks until it is completed (if I am not able to complete in decided time)
  • Improving my introductory blog (adding how does the library work)
  • Writing a blog for the progress till 6th July EOD (i.e. setting up plot basics before moving on to plot-specific tasks)

The window of canvas is the base_image itself. For drawing shapes/text/axes 3 Magick::Draw objects are used which are named draw, text and axes. So when I want to change the view i.e. the area where to plot I translate the origin (initially upper left corner) of all these by left_spacing (of figure) + left_margin (of axes) and top_spacing (of figure) + top_margin (of axes) and after this translation these are scaled in the required proportion (this scaling scales all the pixel coordinate values) and so all the drawing now is done in the required space.

Do let me know if this is unclear @v0dro

OK. Understood. Seems reasonable.

1 Like

Lets talk about the ticks in this week’s meeting. I had implemented ticks in Magick before, and you can use that code as reference. However I’m not very happy with the way it was previously implemented and you’ll need to think of new way of implementing it such that it fits into the new front end.

Here’s the link: https://github.com/SciRuby/rubyplot/blob/9d3fb0075ca9c82fbb0f23de40382081cdc82d40/lib/rubyplot/artist/tick/x_tick.rb

The ticks were initialized by the XAxis: https://github.com/SciRuby/rubyplot/blob/9d3fb0075ca9c82fbb0f23de40382081cdc82d40/lib/rubyplot/artist/axis/x_axis.rb

Sure, I’ll look into it.

[RUBYPLOT-GSOC][DAILY][5 June] Stuck with ticks

Planned progress
Writing documentation.

Progress

  • Improved the project introduction blog.
  • Started the first blog which is on setting up basic functions for Magick backend.
  • Fixed the colour bug and discussed various design decisions regarding the colour of markers and ticks with @v0dro.

Problems

  • Ticks will require changes in Front-end as well as back-end and so I will work on it parallelly.
  • Multiple subplots are not working and so front-end will have to be changed to make it work.

Plans

  • Completing the first blog.
  • Writing the documentation.
  • Working on multiple subplots and on ticks parallelly.

Why are multiple subplots not working? It works for GR.

I am looking into it. Can you please provide a sample code which works for GR?

[RUBYPLOT-GSOC][DAILY][6 June] Writing the Blogs and starting to improve the plots

Planned progress
Writing documentation and blog.

Progress

  • Completed the introduction blog, link: https://alishdipani.github.io/gsoc2019/2019/05/20/GSoC-2019-project-introduction/
  • Started writing a blog for explaining a scatter plot example in detail with the code for new developers to get started easily, this blog will be followed by a blog discussing functions I implemented and the design decisions taken, link: https://alishdipani.github.io/gsoc2019/2019/06/06/The-Scatter-plot-example/
  • Corrected base(for backend) and scatter by adding border_color
  • Corrected draw_circle function
  • Shifted drawing markers in draw_markers to the backend
  • Added a nominal factor to be multiplied by the size of the markers, in GR the nominal factor is the nominal size generated on the graphics device, I hardcoded the value for Magick backend (I have set it to 15 as it seemed good to me, @v0dro please suggest if any changes (will discuss this in the weekly call))
  • Implemented circle and plus markers

Problems

  • The scatter plot example blog is big and will take 1-2 more days.
  • the nominal factor for marker size is set to 15 (see the 6th point in progress), should it be changed?
  • Implementing different types of markers will make the draw_marker function very big, should helper functions be created for every marker or one for each marker? The helper functions will also be big anyway if created.

Plans

  • Completing the scatter plot example blog
  • Writing the setting up basics blog after the example blog
  • Implementing different types of marker types