From 9b4e4d6408545d62495f90236a4d79ca23ce1530 Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Mon, 6 Mar 2023 09:40:20 -0800 Subject: [PATCH] x-axis labels (#5) --- go.mod | 10 ++-- go.sum | 78 ++++++++++++++++++++++++++++++++ internal/ui/app.go | 103 ++++++++++++++++++++++-------------------- internal/ui/graphs.go | 19 +++++--- 4 files changed, 150 insertions(+), 60 deletions(-) diff --git a/go.mod b/go.mod index 3ba56da..4ee4d4c 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/charmbracelet/bubbles v0.15.0 github.com/charmbracelet/bubbletea v0.23.2 github.com/charmbracelet/lipgloss v0.6.0 - github.com/chriskim06/bubble-plot v0.0.0-20230302184816-bc8356fec41f + github.com/chriskim06/bubble-plot v0.0.1 github.com/muesli/reflow v0.3.0 github.com/spf13/cobra v1.6.1 github.com/spf13/viper v1.15.0 @@ -25,7 +25,7 @@ require ( github.com/MakeNowJust/heredoc v1.0.0 // indirect github.com/aymanbagabas/go-osc52 v1.2.2 // indirect github.com/chai2010/gettext-go v1.0.2 // indirect - github.com/chriskim06/drawille-go v0.0.0-20230302181717-a5dd98780f5c // indirect + github.com/chriskim06/drawille-go v0.0.1 // indirect github.com/containerd/console v1.0.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dlclark/regexp2 v1.4.0 // indirect @@ -87,9 +87,9 @@ require ( golang.org/x/net v0.7.0 // indirect golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.5.0 // indirect - golang.org/x/term v0.5.0 // indirect - golang.org/x/text v0.7.0 // indirect + golang.org/x/sys v0.6.0 // indirect + golang.org/x/term v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect golang.org/x/time v0.1.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 // indirect diff --git a/go.sum b/go.sum index f8071d0..6de37bf 100644 --- a/go.sum +++ b/go.sum @@ -75,12 +75,84 @@ github.com/chriskim06/bubble-plot v0.0.0-20230302183228-1eac405a6f10 h1:kLfaqBzK github.com/chriskim06/bubble-plot v0.0.0-20230302183228-1eac405a6f10/go.mod h1:OUc3hk6G48+Na1RHSvdSjCQ5XmIoy3ziXv1+00GUigU= github.com/chriskim06/bubble-plot v0.0.0-20230302184816-bc8356fec41f h1:wETeE1lBwhu7s2YRPGtu2/KPGOgj5M1Bssj3NJ/wVlE= github.com/chriskim06/bubble-plot v0.0.0-20230302184816-bc8356fec41f/go.mod h1:OUc3hk6G48+Na1RHSvdSjCQ5XmIoy3ziXv1+00GUigU= +github.com/chriskim06/bubble-plot v0.0.0-20230303182715-ff1b2da9d66d h1:MSWOHwXbfJxJWjNLYAYqG6Oubp/QwxqEUkGG7pr6dec= +github.com/chriskim06/bubble-plot v0.0.0-20230303182715-ff1b2da9d66d/go.mod h1:gO/X1uN9o/RCxkFKdQcthn26qV0iIxXEDlH7TbUrn3M= +github.com/chriskim06/bubble-plot v0.0.0-20230303194920-50d109668c10 h1:/BI1nHsSeUbop5sG78QPMSkkX4n/zhrM8LfMkUsf55I= +github.com/chriskim06/bubble-plot v0.0.0-20230303194920-50d109668c10/go.mod h1:RC/7nroCdEIhSyUBZyq64/zq/V1+2qegM62EVtSl3cQ= +github.com/chriskim06/bubble-plot v0.0.0-20230303200615-e22cdf160edd h1:9qx65uv7m/9KVcfuX6g87AO5EE1xqyZLPPzvtMUpm54= +github.com/chriskim06/bubble-plot v0.0.0-20230303200615-e22cdf160edd/go.mod h1:FH2nIPt6afhIbSvMdyWdrLMkVC5WPzfLpXUP0Hu6pmg= +github.com/chriskim06/bubble-plot v0.0.0-20230303203555-10c581fefdf8 h1:vMd9H4qL2m7NZJZFbz4Bj57SDPNdB5SsNnkLTBLlcis= +github.com/chriskim06/bubble-plot v0.0.0-20230303203555-10c581fefdf8/go.mod h1:n8S4HM/ZT2I/pSeH+IHWHtTYTdb1Ca91JOQ9ZkS/XuE= +github.com/chriskim06/bubble-plot v0.0.0-20230303210905-7fa525790160 h1:vSYlyou2ImYJnx0JCzL51akTa7ukoqhWNVNvuMD/IjU= +github.com/chriskim06/bubble-plot v0.0.0-20230303210905-7fa525790160/go.mod h1:1RRf0BbnTuW3+kUXiAff4u9PIp9zYNkdJSl3RtjIgUc= +github.com/chriskim06/bubble-plot v0.0.0-20230303211045-865a5353b42b h1:DQ29gvHKzbFXOg3qOqfIUlkHganQAu00oiI3KtTZT84= +github.com/chriskim06/bubble-plot v0.0.0-20230303211045-865a5353b42b/go.mod h1:oSJhiV9UAzkH9XUkHkdvno0VTzzxU0d+VX7rXTrs41Y= +github.com/chriskim06/bubble-plot v0.0.0-20230303212721-5c041b7d14cd h1:iHch80Ex+p6LJHetq3trxKZ9NJkeb5kbVJnVIs3ucWs= +github.com/chriskim06/bubble-plot v0.0.0-20230303212721-5c041b7d14cd/go.mod h1:iimk3ZpFUhziZQoOtDNoukPYptNv3WSHm6DxgMfzdHc= +github.com/chriskim06/bubble-plot v0.0.0-20230303220054-ac9ecef579cc h1:t18wIy1Pf1cTJBDg2msrxDcYxzqy5rQ67C12MmHwvZ8= +github.com/chriskim06/bubble-plot v0.0.0-20230303220054-ac9ecef579cc/go.mod h1:RQ+Id2niQu9hplDlGjWT/Dfm9C19pVwWfcLeqGcUK0Y= +github.com/chriskim06/bubble-plot v0.0.0-20230304000945-86bff3248e23 h1:Gk5n1QqTLuG1yy/5pY7MhUdshMJqABvgozKQCLHAmsQ= +github.com/chriskim06/bubble-plot v0.0.0-20230304000945-86bff3248e23/go.mod h1:knoYCNd1NI9lHyv93Q46WE4AHLmEZ1jK7NOx9CdIRzk= +github.com/chriskim06/bubble-plot v0.0.0-20230304001726-711edd2d1898 h1:5SOucJkf+p6r8x8wcYR8F1BA8DMCYGT6GgXVIE2F0hM= +github.com/chriskim06/bubble-plot v0.0.0-20230304001726-711edd2d1898/go.mod h1:jw8IZognlaK3E+QIFnQJxWx1DUzM4oSyPRBl4veYiqU= +github.com/chriskim06/bubble-plot v0.0.0-20230304002158-2dd3a1e8c6bf h1:xBltEUsrvs91nwPUiOc8DwwdwDzNMFE3o1pEVAhWpUs= +github.com/chriskim06/bubble-plot v0.0.0-20230304002158-2dd3a1e8c6bf/go.mod h1:rql/VDfhaJb33X7Q8cf3+Hk7yp9RxarnR3LcAWFgK4U= +github.com/chriskim06/bubble-plot v0.0.0-20230304003407-fc700abc3c7e h1:kldqTZLee5SWOFR/HsmDAuwvSXg1Bq4EIeV/1Wup7t0= +github.com/chriskim06/bubble-plot v0.0.0-20230304003407-fc700abc3c7e/go.mod h1:B4z3oT0XdPJosfZQLJKuu8uUPcdWO/UaZryANXjpi0E= +github.com/chriskim06/bubble-plot v0.0.0-20230304004114-a04acfe58bc2 h1:CF7T5My2DOjDVaAfRt5ocFtn08BRMUDqzWhfmCLFvtg= +github.com/chriskim06/bubble-plot v0.0.0-20230304004114-a04acfe58bc2/go.mod h1:XYdfulpaS53AvVU4TQ598SHNafJoI50J6gJsrV50KUc= +github.com/chriskim06/bubble-plot v0.0.0-20230304005413-f31b25fe4c1a h1:E4+wKX0koieRuke1+2xoGJzs92azz530v8TD4fpWf8U= +github.com/chriskim06/bubble-plot v0.0.0-20230304005413-f31b25fe4c1a/go.mod h1:nHCZWFXuJMWq6tpHCb2T80Ds3q/K8NLg+KullhA9+uQ= +github.com/chriskim06/bubble-plot v0.0.0-20230304010048-402082659038 h1:+wsDEO/AxipOa9LVBef0o/T3PCapPI5/pBsxuTXcqTs= +github.com/chriskim06/bubble-plot v0.0.0-20230304010048-402082659038/go.mod h1:FJohsM2uG1iXVb7sKY6abUbxsYcESCAunJm7LKzGpuQ= +github.com/chriskim06/bubble-plot v0.0.0-20230306154153-ece6031949f4 h1:RQ7g/X2olJpb2TE25aN5iP8KUIYg0y7wkJ1dsJXTtUs= +github.com/chriskim06/bubble-plot v0.0.0-20230306154153-ece6031949f4/go.mod h1:raCm6JOSxYV37dYkWUwXehjEIsKt2UU4XOGAEEkcboA= +github.com/chriskim06/bubble-plot v0.0.0-20230306164058-ae1edb20c5cf h1:DcH8AiFF5L6QTdqSDQ+1+yQAM0R3oldWewCjVLBtaMU= +github.com/chriskim06/bubble-plot v0.0.0-20230306164058-ae1edb20c5cf/go.mod h1:/XqRtQIaxyoL871Gxt0jePtSj9uwlOsT1yDo/E8jHX0= +github.com/chriskim06/bubble-plot v0.0.1 h1:hoYpc2eKKTmnpqfIyeMFRMz+9IehRAuN4rtg62fNfJo= +github.com/chriskim06/bubble-plot v0.0.1/go.mod h1:Hjhmli73PbzcTyRNdg3TzSgZSj15HYlQqLAYQN58s6M= github.com/chriskim06/drawille-go v0.0.0-20230302165514-dbd57b26d000 h1:Nno/mEy0KPPg/FkKSXgIIz0+2bjtlAoiUKfzbvVeAcE= github.com/chriskim06/drawille-go v0.0.0-20230302165514-dbd57b26d000/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= github.com/chriskim06/drawille-go v0.0.0-20230302175235-0295e5373f58 h1:KxGaXZsxHHP0l1ERfF9il5gGB9kVR19tvzoRFvBPLtU= github.com/chriskim06/drawille-go v0.0.0-20230302175235-0295e5373f58/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= github.com/chriskim06/drawille-go v0.0.0-20230302181717-a5dd98780f5c h1:Lwu/f8LGTtdwdtn6zO0MT9pRsNwymbhUYRVszT6KFxQ= github.com/chriskim06/drawille-go v0.0.0-20230302181717-a5dd98780f5c/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230303182535-d8ea23fcf665 h1:HQzS39KCuYAFbeazXg35/bvo+kQAUnNMX7qajoK/DBE= +github.com/chriskim06/drawille-go v0.0.0-20230303182535-d8ea23fcf665/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230303194217-11cca5c68a0a h1:+LlGhe61/u0/vodtp8H+en8qyqfY2kIwey+MU4ICLgY= +github.com/chriskim06/drawille-go v0.0.0-20230303194217-11cca5c68a0a/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230303200459-da27d0f9a939 h1:G6EUThZV/fkl1RkqdJu3128pZhEA8fMrsrJcxcu4HK0= +github.com/chriskim06/drawille-go v0.0.0-20230303200459-da27d0f9a939/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230303203526-13cf312e76ef h1:nwJythiQdyGHZUueKpe45H4EMgvZJKcC0LlUAlh2jZM= +github.com/chriskim06/drawille-go v0.0.0-20230303203526-13cf312e76ef/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230303210829-6f0fe9bd6a94 h1:iUFBm4YH28zNpLiw8ryV2/JwDzwhTh3CyKHv/VI0QOA= +github.com/chriskim06/drawille-go v0.0.0-20230303210829-6f0fe9bd6a94/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230303211018-936ecbb663a2 h1:5Q3lfIw5dGT40jKAhMfzMhsEDjspeBcXdU9TLNHhGzg= +github.com/chriskim06/drawille-go v0.0.0-20230303211018-936ecbb663a2/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230303212653-f374639550d1 h1:YTr3YW6v9cASYYwK+rmPzqjVDdi4LXDkPUnsGUezwg4= +github.com/chriskim06/drawille-go v0.0.0-20230303212653-f374639550d1/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230303220025-fd71b2672633 h1:eICbBcNGoeWU0mHTGOtcUvWhqPSQKqnB8WcDYEdzF4A= +github.com/chriskim06/drawille-go v0.0.0-20230303220025-fd71b2672633/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230304000914-88da1c7cba59 h1:zYMkHjIVmybzHmT1cRLxXJ3ypLkw7+WpXHxeSkxl+zw= +github.com/chriskim06/drawille-go v0.0.0-20230304000914-88da1c7cba59/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230304001648-7eabb8b6f09c h1:timuyOkitkbW8jN+eSg/oNJ8ECAtVJ6N8AMCFYIC1sA= +github.com/chriskim06/drawille-go v0.0.0-20230304001648-7eabb8b6f09c/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230304002132-d72837b391df h1:cHSWwtaLpbz6Th+JVpi96b5l4kfZ0gN57BV6bbWSdyg= +github.com/chriskim06/drawille-go v0.0.0-20230304002132-d72837b391df/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230304003338-b9e97358472a h1:t4YfdyQG6gAJ5Ah5r8nzS7cSRGCSRsz01YqEdk1TnRg= +github.com/chriskim06/drawille-go v0.0.0-20230304003338-b9e97358472a/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230304004048-da3db0eab298 h1:4/lbKXhQmb6vR1Yl2vMiqT3ZDjPCmbNQ/e6dvhRdlgA= +github.com/chriskim06/drawille-go v0.0.0-20230304004048-da3db0eab298/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230304005344-eec1facbfc5a h1:7HelyCnHPFFLbT6SbTSZbPNPka9giL2TC4mJSA6i22U= +github.com/chriskim06/drawille-go v0.0.0-20230304005344-eec1facbfc5a/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230304010020-980ecff09919 h1:Xv/gAGxuX9loYODOM1Bsqw2qWRBN2Ax+M1xsy5Mlhbw= +github.com/chriskim06/drawille-go v0.0.0-20230304010020-980ecff09919/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230306154119-342eea733d63 h1:sj6V6GfDtkUQvPVwytAxQ+U4zLMmnprMjjseLHNycIs= +github.com/chriskim06/drawille-go v0.0.0-20230306154119-342eea733d63/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.0-20230306164021-ddcc5112f612 h1:ybC3RIwu1aHgBiLTdsSwJcvhv8vqXm52stYps+FKJnQ= +github.com/chriskim06/drawille-go v0.0.0-20230306164021-ddcc5112f612/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= +github.com/chriskim06/drawille-go v0.0.1 h1:tvjp14ni1J6iLpz9fj/iwyf23hKDhu6iLvUQNTaB8YU= +github.com/chriskim06/drawille-go v0.0.1/go.mod h1:crZ9L4tSvNEwUJjxF2z+1RTq5P4CLZdUZeoD1XG7i3Q= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -496,10 +568,14 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -509,6 +585,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/internal/ui/app.go b/internal/ui/app.go index 3170eb7..1d1df52 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -14,24 +14,24 @@ import ( ) type App struct { - client metrics.MetricsClient - cpuData map[string][][]float64 - memData map[string][][]float64 - labels []string - resource metrics.Resource - options interface{} - current string - tick time.Ticker - interval time.Duration - ready bool - sizeReady bool - err error - height int - width int - itemsPane List - graphsPane Graphs - infoPane Info - loading *spinner.Model + client metrics.MetricsClient + cpuData map[string][][]float64 + memData map[string][][]float64 + xAxisLabels *[]string + resource metrics.Resource + options interface{} + current string + tick time.Ticker + interval time.Duration + ready bool + sizeReady bool + err error + height int + width int + itemsPane List + graphsPane Graphs + infoPane Info + loading *spinner.Model } func New(resource metrics.Resource, interval int, options interface{}, showManagedFields bool, flags *genericclioptions.ConfigFlags) *App { @@ -45,17 +45,17 @@ func New(resource metrics.Resource, interval int, options interface{}, showManag allNs = &allNamespaces } app := &App{ - client: metrics.New(flags, showManagedFields, allNs), - resource: resource, - options: options, - cpuData: map[string][][]float64{}, - memData: map[string][][]float64{}, - labels: []string{}, - interval: time.Duration(interval) * time.Second, - itemsPane: *items, - graphsPane: *graphs, - infoPane: *NewInfo(conf), - loading: &loading, + client: metrics.New(flags, showManagedFields, allNs), + resource: resource, + options: options, + cpuData: map[string][][]float64{}, + memData: map[string][][]float64{}, + xAxisLabels: &[]string{}, + interval: time.Duration(interval) * time.Second, + itemsPane: *items, + graphsPane: *graphs, + infoPane: *NewInfo(conf), + loading: &loading, } return app } @@ -64,7 +64,7 @@ func (a App) Init() tea.Cmd { return tea.Batch(a.loading.Tick, a.updateData) } -func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (a *App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd var cmds []tea.Cmd switch msg := msg.(type) { @@ -74,9 +74,13 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { a.width = msg.Width half := msg.Height / 2 third := msg.Width / 3 - a.graphsPane.SetSize(msg.Width, half) a.itemsPane.SetSize(msg.Width-third, half) a.infoPane.SetSize(third, half) + a.graphsPane.SetSize(msg.Width, half) + if a.current != "" { + a.graphsPane.updateData(a.current, a.cpuData, a.memData, *a.xAxisLabels) + } + return a, cmd case tea.KeyMsg: switch keypress := msg.String(); keypress { case "ctrl+c": @@ -124,7 +128,7 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { a.itemsPane, cmd = a.itemsPane.Update(msg) cmds = append(cmds, cmd) a.current = a.itemsPane.GetSelected() - a.graphsPane.updateData(a.current, a.cpuData, a.memData) + a.graphsPane.updateData(a.current, a.cpuData, a.memData, *a.xAxisLabels) } case tickMsg: if msg.err != nil { @@ -135,10 +139,11 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if a.itemsPane.content.SelectedItem() != nil { msg.name = a.itemsPane.GetSelected() } + a.current = msg.name var itemsCmd, graphsCmd tea.Cmd - a.itemsPane, itemsCmd = a.itemsPane.Update(msg) a.graphsPane, graphsCmd = a.graphsPane.Update(msg) - cmds = append(cmds, itemsCmd, graphsCmd, a.tickCmd()) + a.itemsPane, itemsCmd = a.itemsPane.Update(msg) + cmds = append(cmds, graphsCmd, itemsCmd, a.tickCmd()) case spinner.TickMsg: if a.ready && a.sizeReady { a.loading = nil @@ -165,12 +170,12 @@ func (a App) View() string { } type tickMsg struct { - m []metrics.MetricValue - name string - err error - cpuData map[string][][]float64 - memData map[string][][]float64 - labels []string + m []metrics.MetricValue + name string + err error + cpuData map[string][][]float64 + memData map[string][][]float64 + xAxisLabels []string } func (a *App) tickCmd() tea.Cmd { @@ -188,12 +193,13 @@ func (a *App) updateData() tea.Msg { m, err = a.client.GetNodeMetrics(a.options.(*top.TopNodeOptions)) } if err != nil { - fmt.Println(err) return tickMsg{err: err} } - if len(a.labels) == 50 { - a.labels = a.labels[1:] + if len(*a.xAxisLabels) == 50 { + *a.xAxisLabels = (*a.xAxisLabels)[1:] } + t := time.Now() + *a.xAxisLabels = append(*a.xAxisLabels, fmt.Sprintf("%02d:%02d:%02d", t.Hour(), t.Minute(), t.Second())) for _, metric := range m { name := metric.Name if a.cpuData[name] == nil || a.memData[name] == nil { @@ -209,13 +215,12 @@ func (a *App) updateData() tea.Msg { a.cpuData[name][1] = append(a.cpuData[name][1], float64(metric.CPUCores.MilliValue())) a.memData[name][0] = append(a.memData[name][0], float64(metric.MemLimit)) a.memData[name][1] = append(a.memData[name][1], float64(metric.MemCores)) - a.labels = append(a.labels, fmt.Sprintf("%d:%d:%d", metric.Timestamp.Hour(), metric.Timestamp.Minute(), metric.Timestamp.Second())) } return tickMsg{ - m: m, - name: m[0].Name, - cpuData: a.cpuData, - memData: a.memData, - labels: a.labels, + m: m, + name: m[0].Name, + cpuData: a.cpuData, + memData: a.memData, + xAxisLabels: *a.xAxisLabels, } } diff --git a/internal/ui/graphs.go b/internal/ui/graphs.go index 9200edb..167e5c7 100644 --- a/internal/ui/graphs.go +++ b/internal/ui/graphs.go @@ -31,6 +31,8 @@ type Graphs struct { func NewGraphs(conf config.Colors) *Graphs { cpuPlot := plot.New() memPlot := plot.New() + cpuPlot.MaxDataPoints = 50 + memPlot.MaxDataPoints = 50 cpuPlot.Styles.LineColors = []int{conf.CPULimit, conf.CPUUsage} cpuPlot.Styles.AxisColor = conf.Axis cpuPlot.Styles.LabelColor = conf.Labels @@ -50,8 +52,10 @@ func (g Graphs) Init() tea.Cmd { func (g *Graphs) Update(msg tea.Msg) (Graphs, tea.Cmd) { switch msg := msg.(type) { + case tea.WindowSizeMsg: + g.SetSize(msg.Width, msg.Height) case tickMsg: - g.updateData(msg.name, msg.cpuData, msg.memData) + g.updateData(msg.name, msg.cpuData, msg.memData, msg.xAxisLabels) } return *g, nil } @@ -63,23 +67,26 @@ func (g *Graphs) View() string { func (g *Graphs) SetSize(width, height int) { m := tea.WindowSizeMsg{ Width: (width / 2) - ph, - Height: height - pv - 1, + Height: height - pv - 2, } - g.cpuPlot.Update(m) g.memPlot.Update(m) + g.cpuPlot.Update(m) g.extra = width % 2 } -func (g *Graphs) updateData(name string, cpuData, memData map[string][][]float64) { +func (g *Graphs) updateData(name string, cpuData, memData map[string][][]float64, labels []string) { g.name = name g.cpuData = cpuData g.memData = memData + g.labels = labels g.cpuPlot.Title = fmt.Sprintf("CPU - %s", g.name) g.memPlot.Title = fmt.Sprintf("MEM - %s", g.name) g.cpuPlot.Update(plot.GraphUpdateMsg{ - Data: g.cpuData[g.name], + Data: g.cpuData[g.name], + Labels: g.labels, }) g.memPlot.Update(plot.GraphUpdateMsg{ - Data: g.memData[g.name], + Data: g.memData[g.name], + Labels: g.labels, }) }