Created
February 17, 2016 18:23
-
-
Save johnhamelink/5bfb88f53bce544b7676 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Api.Slack.Gnuplot do | |
| alias Porcelain.Process, as: Proc | |
| alias Porcelain.Result | |
| require Logger | |
| def line do | |
| proc = %Proc{pid: pid} = setup | |
| plot(proc, | |
| """ | |
| a = 0.9 | |
| f(x) = a * sin(x) | |
| g(x) = a * cos(x) | |
| # Plot | |
| plot f(x) title 'sin(x)' with lines linestyle 1, \ | |
| g(x) notitle with lines linestyle 2 | |
| """ | |
| ) | |
| end | |
| def setup do | |
| Porcelain.spawn_shell("gnuplot", in: :receive, out: {:send, self()}) | |
| end | |
| def plot(proc, msg) do | |
| Proc.send_input(proc, | |
| """ | |
| # Clean basis for SVG | |
| set terminal svg enhanced font 'Verdana,10' | |
| # Line width of the axes | |
| set border linewidth 1.5 | |
| # Line styles | |
| set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2 | |
| set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 2 | |
| # Output | |
| set terminal svg | |
| #{msg} | |
| """ | |
| ) | |
| receive do | |
| {^pid, :data, :out, data} -> data | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment