<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Diplomats can code too! (Posts about predix)</title><link>https://wintermade.it/blog/</link><description></description><atom:link href="https://wintermade.it/blog/categories/predix.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sat, 05 Oct 2019 08:14:28 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>How to set timezone in px-vis-timeseries</title><link>https://wintermade.it/blog/posts/how-to-set-timezone-in-px-vis-timeseries.html</link><dc:creator>Alessandro Balzano</dc:creator><description>&lt;div&gt;&lt;img alt="/images/px-vis-timeseries-example.png" src="https://wintermade.it/blog/images/px-vis-timeseries-example.png"&gt;
&lt;p&gt;&lt;em&gt;px-vis-timeseries&lt;/em&gt; is one of the most used web components in the Predix
toolkit set. This must-know component is essential, as it lets
chart time-based data and events! Unfortunately, it's not so
easy to configure it to show the correct timezone.
Let's see how to set it right, then.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: &lt;em&gt;in this post, we are discussing px-vis-timeseries, version 4.0.0.&lt;/em&gt;
&lt;em&gt;This post may not apply to future versions of the components discussed here&lt;/em&gt;.&lt;/p&gt;
&lt;div class="section" id="gotcha-1-the-default-x-axis-timezone-is-utc"&gt;
&lt;h2&gt;Gotcha #1: the default x-axis timezone is UTC&lt;/h2&gt;
&lt;p&gt;The default timezone of the X axis is UTC. While it may be the norm in
engineering disciplines or technical users, it may confuse normal users:
they are used to the timezone they live in, and UTC may confuse them (if they're
even aware of it!)&lt;/p&gt;
&lt;p&gt;To see the time in the browser's timezone, you need to set &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;x-axis-type="timeLocal"&lt;/span&gt;&lt;/tt&gt;.
By default, it's set to &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;x-axis-type="time"&lt;/span&gt;&lt;/tt&gt;.&lt;/p&gt;
&lt;pre class="code html"&gt;&lt;a name="rest_code_0944522f0aec447dab262dc9733f8ddb-1"&gt;&lt;/a&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;px-vis-timeseries&lt;/span&gt;
&lt;a name="rest_code_0944522f0aec447dab262dc9733f8ddb-2"&gt;&lt;/a&gt;    &lt;span class="na"&gt;x-axis-type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"timeLocal"&lt;/span&gt;
&lt;a name="rest_code_0944522f0aec447dab262dc9733f8ddb-3"&gt;&lt;/a&gt;    &lt;span class="na"&gt;chart-data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[[chartData]]"&lt;/span&gt;
&lt;a name="rest_code_0944522f0aec447dab262dc9733f8ddb-4"&gt;&lt;/a&gt;    &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"450"&lt;/span&gt;
&lt;a name="rest_code_0944522f0aec447dab262dc9733f8ddb-5"&gt;&lt;/a&gt;    &lt;span class="na"&gt;show-tooltip&lt;/span&gt;
&lt;a name="rest_code_0944522f0aec447dab262dc9733f8ddb-6"&gt;&lt;/a&gt;    &lt;span class="na"&gt;hide-register&lt;/span&gt;
&lt;a name="rest_code_0944522f0aec447dab262dc9733f8ddb-7"&gt;&lt;/a&gt;    &lt;span class="na"&gt;series-config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[[seriesConfig]]"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;a name="rest_code_0944522f0aec447dab262dc9733f8ddb-8"&gt;&lt;/a&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;px-vis-timeseries&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="section" id="gotcha-2-tooltip-and-register-timezones-can-be-configured-separately"&gt;
&lt;h2&gt;Gotcha #2: tooltip and register timezones can be configured separately!&lt;/h2&gt;
&lt;p&gt;The tooltip and the register are independent components, and &lt;em&gt;px-vis-timeseries&lt;/em&gt;
does not configure them automatically, nor offers a single configuration point.&lt;/p&gt;
&lt;p&gt;While this design choice makes the parent implementation simpler and
allows for more flexibility, the users have to remember to configure each
sub-component.&lt;/p&gt;
&lt;p&gt;The configuration can be provided by setting &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;tooltip-config&lt;/span&gt;&lt;/tt&gt;
and &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;register-config&lt;/span&gt;&lt;/tt&gt;, to set the tooltip and the register.&lt;/p&gt;
&lt;pre class="code html"&gt;&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-1"&gt;&lt;/a&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;px-vis-timeseries&lt;/span&gt;
&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-2"&gt;&lt;/a&gt;    &lt;span class="na"&gt;tooltip-config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[[timezoneConfig]]"&lt;/span&gt;
&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-3"&gt;&lt;/a&gt;    &lt;span class="na"&gt;register-config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[[timezoneConfig]]"&lt;/span&gt;
&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-4"&gt;&lt;/a&gt;    &lt;span class="na"&gt;chart-data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[[chartData]]"&lt;/span&gt;
&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-5"&gt;&lt;/a&gt;    &lt;span class="na"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"450"&lt;/span&gt;
&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-6"&gt;&lt;/a&gt;    &lt;span class="na"&gt;show-tooltip&lt;/span&gt;
&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-7"&gt;&lt;/a&gt;    &lt;span class="na"&gt;hide-register&lt;/span&gt;
&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-8"&gt;&lt;/a&gt;    &lt;span class="na"&gt;series-config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"[[seriesConfig]]"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;a name="rest_code_ef4f3444668f48ba898c045b2346923d-9"&gt;&lt;/a&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;px-vis-timeseries&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;p&gt;To set the timezone, you can either use a timezone string (such as "Europe/Rome") or use
the browser-provided &lt;a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl"&gt;Intl&lt;/a&gt; global object to retrieve the current timezone.&lt;/p&gt;
&lt;pre class="code javascript"&gt;&lt;a name="rest_code_d0863b7d49ee48989c09b940d8e60248-1"&gt;&lt;/a&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;timezoneConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;a name="rest_code_d0863b7d49ee48989c09b940d8e60248-2"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;// timezone: "Europe/Rome"&lt;/span&gt;
&lt;a name="rest_code_d0863b7d49ee48989c09b940d8e60248-3"&gt;&lt;/a&gt;    &lt;span class="nx"&gt;timezone&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Intl&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DateTimeFormat&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;resolvedOptions&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;timeZone&lt;/span&gt;
&lt;a name="rest_code_d0863b7d49ee48989c09b940d8e60248-4"&gt;&lt;/a&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;div class="section" id="proof-of-concept"&gt;
&lt;h2&gt;Proof of Concept&lt;/h2&gt;
&lt;p&gt;I've prepared a minimal proof of concept to experiment with.
This PoC is hosted &lt;a class="reference external" href="https://wintermade.it/examples/political-egret/"&gt;on wintermade.it&lt;/a&gt;: it lets you test the code for both gotchas, all in one component.
If you want to modify it, there is a live-editable version on &lt;a class="reference external" href="https://political-egret.glitch.me/"&gt;Glitch&lt;/a&gt;, a code editing service that lets you host your experiments/small websites.
In both cases, you need to enable javascript to see the example :D.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Did these notes save your day? Offer me a&lt;/em&gt; &lt;a class="reference external" href="https://www.ko-fi.com/alessandrobalzano"&gt;Ko-Fi&lt;/a&gt; &lt;em&gt;! Or drop me a&lt;/em&gt; &lt;a class="reference external" href="https://twitter.com/alfateam123"&gt;tweet&lt;/a&gt; &lt;em&gt;if you find errors or typos!&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</description><category>polymer</category><category>predix</category><category>px-vis-timeseries</category><category>screen-on</category><guid>https://wintermade.it/blog/posts/how-to-set-timezone-in-px-vis-timeseries.html</guid><pubDate>Fri, 31 Aug 2018 21:09:45 GMT</pubDate></item></channel></rss>