-module(spectator@internal@views@charts). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/spectator/internal/views/charts.gleam"). -export([legend_item/3, column_chart/1, meter/1]). -export_type([chart_segment/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC(false). -type chart_segment() :: {chart_segment, binary(), binary(), float()}. -file("src/spectator/internal/views/charts.gleam", 74). ?DOC(false). -spec legend_item(binary(), binary(), lustre@vdom@vnode:element(ACJR)) -> lustre@vdom@vnode:element(ACJR). 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:styles( [{<<"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("src/spectator/internal/views/charts.gleam", 17). ?DOC(false). -spec map_segments_with_offset( list(chart_segment()), list(lustre@vdom@vnode:element(ACJL)), float() ) -> list(lustre@vdom@vnode:element(ACJL)). 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:styles( [{<<"x"/utf8>>, <<(gleam_stdlib:float_to_string(Offset))/binary, "px"/utf8>>}, {<<"y"/utf8>>, <<"0px"/utf8>>}, {<<"height"/utf8>>, <<"100"/utf8, "px"/utf8>>}, {<<"width"/utf8>>, <<(gleam_stdlib: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("src/spectator/internal/views/charts.gleam", 61). ?DOC(false). -spec column_chart(list(chart_segment())) -> lustre@vdom@vnode: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("src/spectator/internal/views/charts.gleam", 88). ?DOC(false). -spec meter(float()) -> lustre@vdom@vnode: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:styles( [{<<"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>>}] )] )] ).