#!/usr/bin/env escript %% -*- erlang -*- %%! -smp enable -sname graph_ring -mnesia debug verbose main([RingFile, OutFile]) -> {ok, Binary} = file:read_file(RingFile), Ring = binary_to_term(Binary), OwnerList = element(2,element(4,Ring)), %io:format("~s~n", [lists:flatten(header(body(footer([]),OwnerList)))]); OutString = lists:flatten(header(body(footer([]),OwnerList))), try file:write_file(OutFile, io_lib:format("~s~n", [OutString])), io:format("Saved ~p to ~p.~n", [RingFile, OutFile]) catch A:B -> io:format("Exception ~p:~p~n",[A,B]) end; main([RingFile]) -> main([RingFile, lists:append(RingFile,".html")]); main(_) -> usage(). usage() -> io:format("usage: graph_ring RingFile [OutputFile]\n"), halt(1). header(IOList) -> Header = " Ring Graph ", Chart = "", [Header, Chart,IOList]. body(IOList,OwnerList) -> BodyBegin = " ", [BodyBegin, data(OwnerList), options(), BodyEnd, legend(OwnerList), IOList]. footer(IOList) -> Footer = " ", [Footer,IOList]. data(OwnerList) -> % {Modulo,_} = lists:nth(2,OwnerList), DataList = lists:map( fun({_Partition,Node}) -> <> = erlang:md5(atom_to_list(Node)), ["{value:",integer_to_list(1),",color:\"rgb(",integer_to_list(R),",",integer_to_list(G),",",integer_to_list(B),")\"},\n"] end, OwnerList), ["var data = [",DataList,"];\n"]. options() -> [" var options = { segmentShowStroke : true, segmentStrokeWidth : 1, percentageInnerCutout : 95, animation : false } "]. legend(OwnerList) -> ["",legendRows(OwnerList),"
"]. legendRows(OwnerList) -> NodeList=lists:usort(element(2,lists:unzip(OwnerList))), NodeHtml = lists:map( fun(Node) -> <> = erlang:md5(atom_to_list(Node)), ["",atom_to_list(Node),""] end, NodeList), NodeHtml. textColor(Colors) -> case (lists:max(Colors) + lists:min(Colors)) / 2.0 < 128 of true -> "white"; _ -> "black" end.