Permalink
Browse files

Merge branch 'dev'

* dev:
  Update version to 1.1
  Force symbolic link
  Add error lines to plot2d
  Remove sname from startup
  Add .gitignore to src/ directory
  Reduce the number of xy2chart calls
  Add debug_info for compilation
  • Loading branch information...
2 parents af0efa7 + d81b505 commit 31bea8197ae4844b30888bd8dd04d44b6756ea55 @psyeugenic committed Oct 20, 2010
Showing with 49 additions and 35 deletions.
  1. +6 −5 Makefile
  2. +1 −1 bin/eplot
  3. +1 −0 src/.gitignore
  4. +36 −22 src/egd_chart.erl
  5. +4 −6 src/eplot_main.erl
  6. +1 −1 vsn.mk
View
@@ -1,10 +1,11 @@
include vsn.mk
-ERLC = erlc
-ESRC = src
-EBIN = ebin
-BIN = bin
-LINK = ln -s
+ERLC = erlc
+ESRC = src
+EBIN = ebin
+BIN = bin
+LINK = ln -s -f
+EFLAGS = +debug_info
MODULES = \
egd_chart \
View
@@ -1,5 +1,5 @@
#!/usr/bin/env escript
-%%! -smp enable -sname eplot
+%%! -smp enable
%% vim: filetype=erlang
usage() ->
View
@@ -0,0 +1 @@
+*.swp
View
@@ -140,10 +140,8 @@ graph(Data, Options) ->
% Fonts? Check for text enabling
Font = egd_font:load(filename:join([code:priv_dir(percept), "fonts", "6x11_latin1.wingsfont"])),
-
draw_graphs(Data, Chart, Im),
-
% estetic crop, necessary?
{{X0,Y0}, {X1,Y1}} = Chart#chart.bbx,
@@ -238,24 +236,35 @@ draw_graphs(Datas, Chart, Im) ->
draw_graphs([],_,_,_) -> ok;
draw_graphs([{_, Data}|Datas], ColorIndex, Chart, Im) ->
Color = color_scheme(ColorIndex),
- draw_graph(Data, Chart, Color, Im),
+ % convert data to graph data
+ % fewer pass of xy2chart
+ GraphData = [xy2chart(Pt, Chart) || Pt <- Data],
+ draw_graph(GraphData, Color, Im),
draw_graphs(Datas, ColorIndex + 1, Chart, Im).
-draw_graph([], _, _,_) -> ok;
-draw_graph([E1,E2|Data], Chart, Color, Im) ->
- P1 = xy2chart(E1, Chart),
- P2 = xy2chart(E2, Chart),
- draw_graph_dot(P1, Color, Im),
- egd:line(Im, P1,P2, Color),
- draw_graph([E2|Data], Chart, Color, Im);
-draw_graph([E|Data], Chart, Color, Im) ->
- Pt = xy2chart(E, Chart),
+draw_graph([], _,_) -> ok;
+draw_graph([Pt1,Pt2|Data], Color, Im) ->
+ draw_graph_dot(Pt1, Color, Im),
+ draw_graph_line(Pt1,Pt2, Color, Im),
+ draw_graph([Pt2|Data], Color, Im);
+
+draw_graph([Pt|Data], Color, Im) ->
draw_graph_dot(Pt, Color, Im),
- draw_graph(Data, Chart, Color, Im).
+ draw_graph(Data, Color, Im).
draw_graph_dot({X,Y}, Color, Im) ->
+ egd:filledEllipse(Im, {X - 3, Y - 3}, {X + 3, Y + 3}, Color);
+draw_graph_dot({X,Y,Ey}, Color, Im) ->
+ egd:line(Im, {X, Y - Ey}, {X, Y + Ey}, Color),
+ egd:line(Im, {X - 4, Y - Ey}, {X + 4, Y - Ey}, Color),
+ egd:line(Im, {X - 4, Y + Ey}, {X + 4, Y + Ey}, Color),
egd:filledEllipse(Im, {X - 3, Y - 3}, {X + 3, Y + 3}, Color).
+draw_graph_line({X1,Y1,_},{X2,Y2,_}, Color, Im) ->
+ egd:line(Im, {X1,Y1}, {X2,Y2}, Color);
+draw_graph_line(Pt1, Pt2, Color, Im) ->
+ egd:line(Im, Pt1, Pt2, Color).
+
%% name and color information
@@ -595,12 +604,15 @@ draw_bar2d_data_bars([{{Color,_Set}, Value}|Bars], Chart, Font, Im, Bx, Bo,CS) -
%%==========================================================================
-xy2chart({X,Y}, Chart) ->
- {{Rx0,Ry0}, {_Rx1,_Ry1}} = Chart#chart.ranges,
- {{Bx0,By0}, {_Bx1,By1}} = Chart#chart.bbx,
- {Dx, Dy} = Chart#chart.dxdy,
- {round(X*Dx + Bx0 - Rx0*Dx), round(By1 - (Y*Dy + By0 - Ry0*Dy - Chart#chart.margin))}.
-
+xy2chart({X,Y}, #chart{
+ ranges = {{Rx0,Ry0}, {_Rx1,_Ry1}},
+ bbx = {{Bx0,By0}, {_Bx1, By1}},
+ dxdy = {Dx, Dy},
+ margin = Margin } ) ->
+ {round(X*Dx + Bx0 - Rx0*Dx), round(By1 - (Y*Dy + By0 - Ry0*Dy - Margin))};
+xy2chart({X,Y,Error}, Chart) ->
+ {Xc,Yc} = xy2chart({X,Y}, #chart{ dxdy = {_,Dy} } = Chart),
+ {Xc, Yc, round(Dy*Error)}.
ranges([{_Name, Es}|Data]) when is_list(Es) ->
Ranges = xy_minmax(Es),
@@ -651,10 +663,12 @@ precision_level(S, E, N) when is_number(S), is_number(E) ->
end;
precision_level(_, _, _) -> 2.
-% on form [{X,Y}]
+% on form [{X,Y}] | [{X,Y,E}]
xy_minmax(Elements) ->
- Xs = [ X || {X,_} <- Elements ],
- Ys = [ Y || {_,Y} <- Elements ],
+ {Xs, Ys} = lists:foldl(fun
+ ({X,Y,_}, {Xis, Yis}) -> {[X|Xis],[Y|Yis]};
+ ({X,Y}, {Xis, Yis}) -> {[X|Xis],[Y|Yis]}
+ end, {[],[]}, Elements),
{{lists:min(Xs),lists:min(Ys)}, {lists:max(Xs), lists:max(Ys)}}.
xy_resulting_ranges({{X0,Y0},{X1,Y1}},{{X2,Y2},{X3,Y3}}) ->
View
@@ -65,12 +65,10 @@ parse_data_file(Fd, String, Out) ->
parse_data_file(Fd, io:get_line(Fd, ""), [Item|Out]).
tokens2item(Tokens) ->
- Is = lists:map(fun
- (String) ->
- string_to_term(String)
- end, Tokens),
- [X,Y|_] = Is,
- {X,Y}.
+ case lists:map(fun (String) -> string_to_term(String) end, Tokens) of
+ [X,Y] -> {X,Y};
+ [X,Y,E|_] -> {X,Y,E}
+ end.
string_to_term(Value) ->
try
View
2 vsn.mk
@@ -1 +1 @@
-VSN = 1.0.1
+VSN = 1.1

0 comments on commit 31bea81

Please sign in to comment.