ui-stats is a series of polymer components which allow you to quickly and easily create a
statusboard to track whatever it is you need to track. Data can be loaded explicitly, programmatically, or more commonly via URL. Different components can generate different types of tiles for displaying different types of data.
Check out the demo
Import polymer and the ui-stats component, easiest to use the shared instance, but locally is fine too.
<link rel="import" href="https://services.glgresearch.com/ui-toolkit/polymer.html">
<link rel="import" href="https://services.glgresearch.com/ui-toolkit/node_modules/ui-stats/src/ui-stats.html">Due to a bug in polymer libraries, if you don't have a <script> tag in your document's <head>
you'll need to add one, though it can be empty. Here's a starting template that puts it all together.
<!DOCTYPE html>
<html>
<head>
<script><!-- work around polymer bug, that requires a script tag in head --></script>
<link rel="import" href="https://services.glgresearch.com/ui-toolkit/polymer.html">
<link rel="import" href="https://services.glgresearch.com/ui-toolkit/node_modules/ui-stats/src/ui-stats.html">
</head>
<body>
<ui-stats-timeline label="CM Acceptance Percentage" units="%" groupBy="week" valueProperty="accept_rate"
src="https://services.glgresearch.com/epiquery/councilApplicant/getStats.mustache">
</ui-stats-timeline>
</body>
</html>Display a value and its changes over time, with optional grouping by month, day, or hour. You can pass
property formatted JSON data via the data attribute, but the typical usage is to use the src attribute
to specify the URL of query that returns an array of JSON objects, and use the dateProperty and valueProperty
attributes to select your X and Y columns.
The body of the tag is interpreted as descriptive comment and will appear under the title.
<ui-stats-timeline label="Avg Daily CM Applications" groupBy="day" limit="30"
src="https://services.glgresearch.com/epiquery/councilApplicant/getStats.mustache"
valueProperty="applied">
</ui-stats-timeline>The name of the metric you are displaying
The name of the data property that holds the X-axis value. Must be a valid date. Defaults to date.
The moment.js date formatting pattern to use when parsing date values. Defaults to YYYY-MM-DD
The name of the data property that holds the Y-axis value. Must be a number. Defaults to all item properties excep the date property
An array of data properties for the Y-axis values. Will generate multi-series data with a legend.
You can specify an actual array of strings, or a comma separated list which will be parsed into an array.
If you specify multiple properties here, the reduction attribute will be applied to each series first,
and then to the collection of resulting values. Rolling up the roll ups as it were. If you want to hide
the primary metric, set the reduction attribute to none.
You can derive properties by using simple javascript expressions referencing other properties. For example
in this case accepted, paid and applied are properties in the return json and we are calculating the ratio.
<ui-stats-timeline label="Derived Value with Trendline (smoothed)" units="%" groupBy="day" smooth="true"
src="https://services.glgresearch.com/epiquery/councilApplicant/getStats.mustache" limit="30" trendline="true"
labels="Accept Rate, Paid Rate"
valueProperties="pct_accepted=accepted / applied, pct_paid=paid / applied">
</ui-stats-timeline>The number of rows to keep (after applying any grouping), taken from the end of the list. Defaults to MAX_INT
Grouping by date. One of either hour, day, week, or month which groups all the data by the start of
the time period, using your first date column as the key. Simply sums all the other property fields.
Defaults to group by day.
Sets the reduction function to apply when aggregating groupbed values. The default value
is sum. Possible values are: first, last, sum, average, min, max, and count.
if true, will keep incomplete groups - hours, days, weeks, etc.
Sets the reduction function to apply the data values to create the primary metric. The default value
is last, unless you have a trendline, and then it is trend.
Possible values are: first, last, sum, average, min, max, count, trend
and none. The value of none hides the metric area, just showing the graph.
The units, for example % (between 0 and 1), ms, or some arbitrary string. Defaults to empty.
Note that the percentage symbol triggers % formatting.
If false disables simple graphic smoothing.
Possible values are movingAverage, weightedMovingAverage, cumulative or none, defaults to none.
You can set the size of the sliding window for moving averages in parentheses. For example movingAverage(3), defaults to 7
Explicitely set the object array of data, rather than loading it from a URL
Type of chart, defaults to line. Useful values are column and area
GET or POST, defaults to GET, applied only if src is specified
If true, show a trendline
If false, hide the change indicators, defaults to true
If true, show the change as an absolute value rather than a percentage, defaults to false
If true, treat a decrease in value as an improvement, rather than a decline (ex. response time)
If specified, ignore values before this date string (uses dateFormat). Supports relatives in the format
-30d or +30d, where you can use days, hours, weeks. months, or years.
Any limit is applied after date range filtering
If specified, ignore values after this date string (uses dateFormat).
Supports relatives in the format
-30d or +30d, where you can use days, hours, weeks. months, or years.
Any limit is applied after date range filtering
Optional function (name) called after loading from src. You are passed the JSON from the server, and should
return new JSON. Designed to allow you to customize the data returned client side. For example:
var custom = function (json) {
for (var i=0; i < json.length; i++) {
row = json[i];
for (var property in row) {
if (typeof row[property] == 'number')
row[property] = row[property] * 2
}
}
return json;
}Optional list of labels to use for the valueProperties. Defaults to property name.
The Number tile is focused on the display of a metric that can be represented by a single number, along with associated secondary metrics, such as a comparison to the previous value or a sparkline. For example:
Data can be provided in one of several ways:
-
Via the
valueattribute, which specifies a single value:<ui-stats-number value="55"> </ui-stats>
-
Via the
dataattribute, which takes an array of values:<ui-stats-number data="[5, 10, 15, 20, 25]"> </ui-stats>
Or an array of quoted JSON objects, which requires use of the
propertyattribute to specify which property is your primary metric.<ui-stats-number property="count" data="[{'date':'2014-03-01', 'count':10}, {'date':'2014-03-02', 'count':15}, {'date':'2014-03-03', 'count':11}]"> </ui-stats>
-
Via the
srcattribute, passing in the URL to a resource containing an array of data, in JSON format. This option also requires thepropertyattribute. JSON is loaded from the URL and assigned to thedataattribute. Note that this is a client side call, and requires CORS if it's not hitting the same server. This is intended to be the the primary use case.<ui-stats-number property="count" src="http://example.com/data.json"> </ui-stats>
The layout of the tile is automatically configured by the type of data you pass into it, with the following behaviors.
-
If you set the
valueattribute to a single value, that value will be used as the primary display metric, overriding any other ways of setting that value, such as loading the data from a URL. -
If you set the
dataattribute to a single value, it is the same as setting thevalueattribute. -
If you set the
dataattribute to exactly two values, the first value will be used as the primary metric, and the second value will be considered the previous value for that metric. A percent change will automatically be shown in this case. If you want to display the previous value, rather than the change, set theabsoluteattribute totrue. -
If you set the
dataattribute to three or more values, a primary metric will be displayed and a sparkline of the values will be generated. By default the sum of the array will be the primary metric, but this can be controlled via thereductionattribute. If you only want to consider a subset of the values, set thelimitattribute to truncate the list to the lastlimitelements. For example, the following URL returns 365 days of data in JSON format, but we only care about the last 7 days, and the "applied" property.<ui-stats-number name="CM Applications (7 days)" src="https://services.glgresearch.com/epiquery/councilApplicant/getStats.mustache" property="applied" limit="7"> </ui-stats>
<URL>
URL containing data to populate data. Must be CORS accessible. Should return an array of JSON objects. Requires
the property value to specify which object property to use for the Y axis value.
<string>
Name of the property value to use for the Y axis when loading data via the src attribute
<integer>
Shortcut for assigning a single value, equivalent to passing a single value array to data
<Array>
Array of values, will be truncated to the last limit elements. If it contains two elements, you get change indicators, if three or more elements you get a sparkline.
<integer>
Number of elements (from the end of the array) to use from data
<string>
Sets the reduction function to apply the data values to create the primary metric. The default values is last if there are two or less values and sum if there are more than two values. Possible values are: first, last, sum, average, min, max, count
<string>
Name of the stat, appears in the title bar.
<boolean>
When there are exactly 2 values present, show the absolute change in value, rather than a percentage change.
<boolean>
If true, applies smoothing to the sparkline.
<string>
String prepended to the metrics, for example $ or ms.
GET or POST, defaults to GET, applied only if src is specified
Simplified wrapper around Google Charts designed to display charts from JSON data.
<URL>
URL containing data to populate data. Must be CORS accessible. Should return an array of JSON objects. Requires
the cols value to specify which object property or properties to use for the Y axis value(s).
<Array>
Array of values, will be truncated to the last limit elements. Data can be an array of numbers, or objects, if you
specify the cols attribute to describe the data.
<integer>
Number of elements (from the end of the array) to use from data
<string>
Name of the stat, appears in the title bar.
<boolean>
If true, applies smoothing to the sparkline.
<Array>
JSON array describing the columns in the data. Uses the following properties. Columns are considered ordered and you are expected to put dates in column 0 if generating a timeline chart.
id, property nametype, one ofdate,string, ornumberlabel, name (defaults to id value)pattern, only applies to dates, pattern for date parser, defaults to YYYY-MM-DD
<string>
Type of chart to draw. Can be one of pie, bar, column, line, 'scatter', 'area'
<string>
Grouping by date. One of either hour, day, week, or month which groups all the data by the start of
the time period, using your first date column as the key. Simply sums all the other property fields.
<length>
Width of the nested chart element. Defaults to 26em
GET or POST, defaults to GET, applied only if src is specified
<integer>
Moves the min value of the horizontal axis to the specified value for bar charts
Optional function (name) called after loading from src. You are passed the JSON from the server, and should
return new JSON. Designed to allow you to customize the data returned client side. For example:
var custom = function (json) {
for (var i=0; i < json.length; i++) {
row = json[i];
for (var property in row) {
if (typeof row[property] == 'number')
row[property] = row[property] * 2
}
}
return json;
}
