Current section
Files
Jump to
Current section
Files
src/spectator@internal@views@charts.erl
-module(spectator@internal@views@charts).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([legend_item/3, column_chart/1, meter/1]).
-export_type([chart_segment/0]).
-type chart_segment() :: {chart_segment, binary(), binary(), float()}.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/charts.gleam", 74).
-spec legend_item(binary(), binary(), lustre@internals@vdom:element(AQLB)) -> lustre@internals@vdom:element(AQLB).
legend_item(Label, Color, Value) ->
lustre@element@html:'div'(
[lustre@attribute:class(<<"legend-item"/utf8>>)],
[lustre@element@html:'div'(
[lustre@attribute:class(<<"legend-colour"/utf8>>)],
[lustre@element@html:'div'(
[lustre@attribute:style(
[{<<"background-color"/utf8>>, Color}]
)],
[]
)]
),
lustre@element@html:'div'(
[],
[lustre@element@html:'div'(
[lustre@attribute:class(<<"legend-label"/utf8>>)],
[lustre@element@html:text(Label)]
),
Value]
)]
).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/charts.gleam", 17).
-spec map_segments_with_offset(
list(chart_segment()),
list(lustre@internals@vdom:element(AQKV)),
float()
) -> list(lustre@internals@vdom:element(AQKV)).
map_segments_with_offset(Input, Acc, Offset) ->
case Input of
[] ->
lists:reverse(Acc);
[S | Rest] ->
map_segments_with_offset(
Rest,
[lustre@element:namespaced(
<<"http://www.w3.org/2000/svg"/utf8>>,
<<"rect"/utf8>>,
[lustre@attribute:title(
<<<<(erlang:element(3, S))/binary, " "/utf8>>/binary,
(spectator@internal@common:format_percentage(
erlang:element(4, S)
))/binary>>
),
lustre@attribute:style(
[{<<"x"/utf8>>,
<<(gleam@float:to_string(Offset))/binary,
"px"/utf8>>},
{<<"y"/utf8>>, <<"0px"/utf8>>},
{<<"height"/utf8>>,
<<"100"/utf8, "px"/utf8>>},
{<<"width"/utf8>>,
<<(gleam@float:to_string(
erlang:element(4, S)
))/binary,
"px"/utf8>>},
{<<"fill"/utf8>>, erlang:element(2, S)}]
)],
[lustre@element@svg:title(
[],
[lustre@element@html:text(
<<<<(erlang:element(3, S))/binary,
" "/utf8>>/binary,
(spectator@internal@common:format_percentage(
erlang:element(4, S)
))/binary>>
)]
)]
) |
Acc],
Offset + erlang:element(4, S)
)
end.
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/charts.gleam", 61).
-spec column_chart(list(chart_segment())) -> lustre@internals@vdom:element(any()).
column_chart(Segments) ->
lustre@element@html:svg(
[lustre@attribute:class(<<"column-chart"/utf8>>),
lustre@attribute:attribute(
<<"viewBox"/utf8>>,
<<"0 0 100 "/utf8, "100"/utf8>>
),
lustre@attribute:attribute(
<<"height"/utf8>>,
<<"100"/utf8, "px"/utf8>>
),
lustre@attribute:attribute(<<"width"/utf8>>, <<"100%"/utf8>>),
lustre@attribute:attribute(
<<"preserveAspectRatio"/utf8>>,
<<"none"/utf8>>
)],
map_segments_with_offset(Segments, [], +0.0)
).
-file("/Users/jonas/Projects/spectator/src/spectator/internal/views/charts.gleam", 88).
-spec meter(float()) -> lustre@internals@vdom:element(any()).
meter(Value) ->
lustre@element@html:svg(
[lustre@attribute:class(<<"meter-chart"/utf8>>),
lustre@attribute:attribute(
<<"viewBox"/utf8>>,
<<"0 0 100 "/utf8, "25"/utf8>>
),
lustre@attribute:attribute(
<<"height"/utf8>>,
<<"25"/utf8, "px"/utf8>>
),
lustre@attribute:attribute(<<"width"/utf8>>, <<"100%"/utf8>>),
lustre@attribute:attribute(
<<"preserveAspectRatio"/utf8>>,
<<"none"/utf8>>
)],
[lustre@element@svg:rect(
[lustre@attribute:style(
[{<<"x"/utf8>>, <<"0px"/utf8>>},
{<<"y"/utf8>>, <<"0px"/utf8>>},
{<<"height"/utf8>>, <<"25"/utf8, "px"/utf8>>},
{<<"width"/utf8>>,
<<(spectator_ffi:truncate_float(Value))/binary,
"px"/utf8>>},
{<<"fill"/utf8>>, <<"var(--meter-bar)"/utf8>>}]
)]
)]
).