{"id":281,"date":"2008-06-16T23:59:58","date_gmt":"2008-06-16T23:59:58","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=281"},"modified":"2008-06-17T00:38:45","modified_gmt":"2008-06-17T00:38:45","slug":"tweaking-the-currentcost-app","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=281","title":{"rendered":"Tweaking the CurrentCost app"},"content":{"rendered":"<p><a href=\"http:\/\/www.flickr.com\/photos\/dalelane\/2585909618\/\" title=\"tweaking the CurrentCost GUI by dalelane, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm4.static.flickr.com\/3173\/2585909618_385fe4db63.jpg\" width=\"500\" height=\"388\" alt=\"tweaking the CurrentCost GUI\" \/><\/a><\/p>\n<p>I spent a bit of tonight tweaking <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=280\">last night&#8217;s CurrentCost app<\/a>. <\/p>\n<p>Not a lot to say about it, as it&#8217;s more or less the same as it was last night&#8230;<\/p>\n<p><!--more--><strong>Adding axes to the bar graph<\/strong><br \/>\nThe most noticeable difference is that I worked out a way to add labels to the graphs. As I said last night, I&#8217;ve been learning to use WPF to draw the GUI, and starting to get my head around the approach to data binding &#8211; separate the data (in your C# objects) from the interface (specified in XAML). <\/p>\n<p>Last night, I started by creating a bar graph as a series of programmatically-generated Rectangles. I&#8217;ve now replaced this by specifying a DataTemplate for the bar graph control:<\/p>\n<pre><code>&lt;DataTemplate x:Key=\"template\"&gt;                        \r\n    &lt;StackPanel Orientation=\"Horizontal\" VerticalAlignment=\"Bottom\"&gt;\r\n        &lt;StackPanel Orientation=\"Vertical\" VerticalAlignment=\"Bottom\"&gt;\r\n            &lt;Rectangle\r\n                Height=\"{Binding Path=Value}\"\r\n                Width=\"20\" \r\n                Fill=\"Green\" \r\n                MouseEnter=\"Rectangle_MouseEnter\" \r\n                MouseLeave=\"Rectangle_MouseLeave\" \/&gt;\r\n            &lt;Label Content=\"{Binding Path=Key}\" FontSize=\"8\" \/&gt;\r\n        &lt;\/StackPanel&gt;\r\n        &lt;Rectangle Width=\"1\" \/&gt; &lt;!-- spacing --&gt;\r\n    &lt;\/StackPanel&gt;\r\n&lt;\/DataTemplate&gt;<\/code><\/pre>\n<p>Instead of being a stand-alone Rectangle, each item in the data collection where I store CurrentCost data is represented by a Rectangle (with the height specified by the value from the CurrentCost reading), and a Label (with the text specified by the label from the CurrentCost reading). <\/p>\n<p>Then I use MouseEnter and MouseLeave events to change the colour and populate the text boxes at the top &#8211; rather than try to add vertical axes, if you hover over a bar on the graph, you can see the reading for that bar.<\/p>\n<p>The more I play with WPF, the more I&#8217;m starting to like it&#8230;<\/p>\n<p><strong>CurrentCost history data<\/strong><br \/>\nAdding the labels to the graph had the unexpected bonus of highlighting that I&#8217;d misunderstood the history data a bit. I&#8217;ve since gone back and fixed my <a href=\"http:\/\/dalelane.co.uk\/blog\/post-images\/080615-CurrentCostHistory.cs.txt\">code from last night<\/a>, and added a comment to explain <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=280#comment-96292\">how I think the hourly history works<\/a>.<\/p>\n<p><strong>Time<\/strong><br \/>\nI&#8217;ve got rid of the option to choose between the computer or CurrentCost meter as a time source, as it was fairly pointless. It&#8217;s the CurrentCost meter that&#8217;s collecting this data, so you kind of need it&#8217;s time to be accurate. <\/p>\n<p>I replaced it with a line of code that checks the timestamp from a reading when you get it &#8211; if it&#8217;s significantly different to the current time on your computer, you will get a prompt warning you and advising you to correct the clock on your CurrentCost meter. <\/p>\n<p>Surprisingly, mine was running 56 minutes slow. These things really lose time fast! \ud83d\ude41<\/p>\n<p>The <a href=\"http:\/\/dalelane.co.uk\/files\/CurrentCostApp.exe\">updated version is available for download<\/a> if anyone wants to give it a try. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spent a bit of tonight tweaking last night&#8217;s CurrentCost app. Not a lot to say about it, as it&#8217;s more or less the same as it was last night&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[194,225],"class_list":["post-281","post","type-post","status-publish","format-standard","hentry","category-code","tag-currentcost","tag-wpf"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=281"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/281\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}