| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/core/tracks/chart_axis.html"> |
| <link rel="import" href="/core/tracks/chart_point.html"> |
| <link rel="import" href="/core/tracks/chart_series.html"> |
| <link rel="import" href="/core/tracks/chart_track.html"> |
| <link rel="import" href="/base/ui.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tv.exportTo('tv.c.tracks', function() { |
| |
| /** |
| * A track that displays a Counter object. |
| * @constructor |
| * @extends {ChartTrack} |
| */ |
| var CounterTrack = |
| tv.b.ui.define('counter-track', tv.c.tracks.ChartTrack); |
| |
| CounterTrack.prototype = { |
| __proto__: tv.c.tracks.ChartTrack.prototype, |
| |
| decorate: function(viewport) { |
| tv.c.tracks.ChartTrack.prototype.decorate.call(this, viewport); |
| this.classList.add('counter-track'); |
| }, |
| |
| get counter() { |
| return this.chart; |
| }, |
| |
| set counter(counter) { |
| this.heading = counter.name + ': '; |
| this.series = CounterTrack.buildChartSeriesFromCounter(counter); |
| this.autoSetAllAxes({expandMax: true}); |
| }, |
| |
| getModelEventFromItem: function(chartValue) { |
| return chartValue; |
| } |
| }; |
| |
| CounterTrack.buildChartSeriesFromCounter = function(counter) { |
| var numSeries = counter.series.length; |
| var totals = counter.totals; |
| |
| // Create one common axis for all series. |
| var chartAxis = new tv.c.tracks.ChartAxis(0, undefined); |
| |
| // Build one chart series for each counter series. |
| var chartSeries = counter.series.map(function(series, seriesIndex) { |
| var chartPoints = series.samples.map(function(sample, sampleIndex) { |
| var total = totals[sampleIndex * numSeries + seriesIndex]; |
| return new tv.c.tracks.ChartPoint(sample, sample.timestamp, total); |
| }); |
| var renderingConfig = { |
| chartType: tv.c.tracks.ChartSeriesType.AREA, |
| colorId: series.color |
| }; |
| return new tv.c.tracks.ChartSeries( |
| chartPoints, chartAxis, renderingConfig); |
| }); |
| |
| // Show the first series (with the smallest cumulative value) at the top. |
| chartSeries.reverse(); |
| |
| return chartSeries; |
| }; |
| |
| return { |
| CounterTrack: CounterTrack |
| }; |
| }); |
| </script> |