Is there any charting library in elixir? - graph

I want to plot a bar graph in elixir and save it as an image.
Is there any good charting library for doing this ?
I tried searching on elixir.libhunt.com and github.com/h4cc/awesome-elixir, but didn't find a single package for my need.
Thanks in advance.

Yes - you can interface to gnuplot with gnuplot-elixir
As as example, to generate the bar graph in this answer - the code would be:
import Gnuplot
chart = [
[:set, :term, :png, :size, '512,512'],
[:set, :output, Path.join("/tmp", "barchart.PNG")],
[:set, :boxwidth, 0.5],
~w(set style fill solid)a,
[:plot, "-", :using, '1:3:xtic(2)', :with, :boxes]
]
dataset = [[0, "label", 100], [1, "label2", 450], [2, "bar label", 75]]
plot(chart, [dataset])

I don't think there's any such control for Elixir--nothing native anyway. Graphics is not exactly in Elixir's wheelhouse. However, I think you could probably build something yourself with wxErlang. You can see what sorts of things you can do with wxErlang in Elixir by typing :wx.demo() from within iex. I don't know of a graph primitive in wxErlang but it may be that I simply haven't found it yet.

As an update to this question, you can now use the vega_lite package and LiveBook to easily plot with Elixir.
https://livebook.dev/
https://github.com/livebook-dev/vega_lite

Related

How to create Multi Type Charts with pptxgenjs

I am using PptGenJs (https://gitbrent.github.io/PptxGenJS/docs/api-charts/) to create a Multi Type Chart (a bar and a line in the same chart) in my Angular application. I am testing the demo code from the PptGenJs-Github-Repo, which you can find it here: https://github.com/gitbrent/PptxGenJS/blob/master/demos/modules/demo_chart.mjs#L1715
I am surprised to find that it doesn't work in my case. I have PptGenJs Version of 3.10.0 and Angular Version of 13.2.0.
The problems are:
charts are not found in "type: pptx.charts.BAR". Instead, I have to change it to "type: pptx.ChartType.bar"
the method of "slide.addChart(chartTypes, opts)" shows error. It seems that the parameter of "data" is missing according to its documentation:
addChart(type: CHART_NAME | IChartMulti[], data: any[], options?: IChartOpts): Slide
I must have done something wrong, but have no idea. Could anyone help me? Many thanks.
regards,
CC

Create UML diagrams directly from R code

Does anyone have an actual approach on how to create UML diagrams directly from R code?
This is pretty much the only resource that I found in that regard. Works, but not really "integrated" in the sense that the required info for the diagrams are automatically detected in the actual code in any sort.
Related to this question.
What do you mean by "required info for the diagrams are automatically detected in the actual code"? PlantUML in its current state (Link) is actually quite nice to easily create simple UML charts in R logic.
Take this example:
library(plantuml)
x <- '
(*) --> "Initialization"
if "Some Test" then
-->[true] "Some Activity"
--> "Another activity"
-right-> (*)
else
->[false] "Something else"
-->[Ending process] (*)
endif
'
x <- plantuml(
x
)
plot(
x = x
# vector = TRUE
)
will plot as
Maybe check it out?

Reading structured data from file

How can I read a structured data file in Julia?
Speaking in python, if I have defined some c-styled format:
df = [
['Label', '4s'],
['Version', 'i'],
['Revision', 'i'],
['Date', '28s'],
['FileFormat', '2i'],
['FileType', '4s'],
['OriginalFileName', '68s'], ...etc]
df is parsed out into var_names and structure and then read:
fh = open(fn,'rb')
data = fh.read()
header = struct.unpack_from(struct_format, data[0:structsize])
I can't figure out how to do something equivalent in Julia.
In a somewhat similar question, I see how I could build a type to handle this but have yet to figure out how a variable can have a specific amount of base types; 4 ints for example.
I've read all the documentation I can find on sprint and its cousins, but haven't found any examples to help make sense of the them.
It's possible that StrPack.jl will do some or all of what you want. I think the documentation emphasizes its use for in-memory objects, but its original purpose was to handle this problem. Might be worth browsing the source and perhaps contributing patches.

pyqtgraph, how track log/linear axes transformation changes between linked axes

I have 3 linked views, linked by X axis. This works great. However, when I switch one plot to log X mode, the others do not switch to log x mode, but they pop in to zoom way in to the log version of the x axis.
How do it make it so the log X transformation applies to all plots?
So far, I simply use the code
diViewWidget.setXLink(frViewWidget)
noiseViewWidget.setXLink(diViewWidget)
The data should look like this:
but actually look like this:
Basically, to reproduce you can go to any 2 linked views, right click and set the transformation to log x.
The workaround I found is to go to each plot individually and set the transformation individually, but I'd like it to happen programatically.
Thanks,
-Caleb
#learning qt i just found a better linkLogXChecks version
from itertools import permutations
def linkLogXChecks(plotitems):
for a, b in permutations(plotitems, 2):
a.ctrl.logXCheck.toggled.connect(b.ctrl.logXCheck.setChecked)
https://groups.google.com/forum/#!msg/pyqtgraph/3686qqVHgpI/bmBAQ_sDKJIJ
https://forum.qt.io/topic/39241/how-to-set-logarithmic-scale-on-a-qgraphicsview/2
I couldn't apply that fix across separate PlotItems, so tried broadcasting the changed checkbox signal and it seems to work
import pyqtgraph as pg
data = pg.np.random.normal(size=100)
app = pg.QtGui.QApplication([])
win = pg.GraphicsWindow()
p1 = win.addPlot(y=data)
win.nextRow()
p2 = win.addPlot(y=data)
p2.setXLink(p1)
win.nextRow()
p3 = win.addPlot(y=data)
p3.setXLink(p1)
def linkLogXChecks(plotitems):
def broadcast(state):
for p in plotitems:
p.ctrl.logXCheck.setChecked(state)
for p in plotitems:
p.ctrl.logXCheck.toggled.connect(broadcast)
linkLogXChecks([p1, p2, p3])
pg.QtGui.QApplication.instance().exec_()

JSNewtworkX stop layout

i'm using JSNetworkX for graph exploration and rendering.
JSNetworkX is using D3.js for graph render. However, as I work with large graph (json file about 5Mb), I would like to render this graph directly without any animations (so, in placing each node directly without force attraction).
I try to use D3.layout.force().stop() after rendering, but it's without effects.
Because of that, I'm thinking that it has to be done in jsnx.draw, see my code below.
jsnx.draw(G, {
element: 'body',
d3: d3,
layout_attr: {
charge: -1500,
linkDistance: 1,
gravity: 1,
friction: 0.4,
alpha: -100
},
});
force = d3.layout.force();
Unfortunately, you can't do that with the current version. Do you need a force layout at all or do you already have positions for each node? FWIW, if you really have a large graph, even a static layout would be slow, because you'd still have too many SVG elements. The next version will include a WebGL rendered for large graphs.
So, we can't for the moment.
As of v0.3.4, jsnx.draw returns the force layout object so you can do var force = jsnx.draw{/*...*/} then force.stop().

Resources