1<!DOCTYPE html> 2<!-- 3Copyright (c) 2012 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/base/color_scheme.html"> 9<link rel="import" href="/tracing/model/selection_state.html"> 10 11<script> 12'use strict'; 13 14/** 15 * @fileoverview Provides color scheme related functions. 16 */ 17tr.exportTo('tr.ui.b', function() { 18 var ColorScheme = tr.b.ColorScheme; 19 20 var colors = ColorScheme.colors; 21 var colorsAsStrings = ColorScheme.colorsAsStrings; 22 var numColorsPerVariant = ColorScheme.properties.numColorsPerVariant; 23 24 var SelectionState = tr.model.SelectionState; 25 26 /** 27 * Provides methods to get view values for events. 28 */ 29 var EventPresenter = { 30 getSelectableItemColorAsString: function(item) { 31 var colorId = item.colorId + this.getColorIdOffset_(item); 32 return colorsAsStrings[colorId]; 33 }, 34 35 getColorIdOffset_: function(event) { 36 return event.selectionState; 37 }, 38 39 getTextColor: function(event) { 40 if (event.selectionState === SelectionState.DIMMED) 41 return 'rgb(60,60,60)'; 42 return 'rgb(0,0,0)'; 43 }, 44 45 getSliceColorId: function(slice) { 46 return slice.colorId + this.getColorIdOffset_(slice); 47 }, 48 49 getSliceAlpha: function(slice, async) { 50 var alpha = 1; 51 if (async) 52 alpha *= 0.3; 53 return alpha; 54 }, 55 56 getInstantSliceColor: function(instant) { 57 var colorId = instant.colorId + this.getColorIdOffset_(instant); 58 return colors[colorId].toStringWithAlphaOverride(1.0); 59 }, 60 61 getObjectInstanceColor: function(instance) { 62 var colorId = instance.colorId + this.getColorIdOffset_(instance); 63 return colors[colorId].toStringWithAlphaOverride(0.25); 64 }, 65 66 getObjectSnapshotColor: function(snapshot) { 67 var colorId = 68 snapshot.objectInstance.colorId + this.getColorIdOffset_(snapshot); 69 return colors[colorId]; 70 }, 71 72 getCounterSeriesColor: function(colorId, selectionState, 73 opt_alphaMultiplier) { 74 var event = {selectionState: selectionState}; 75 var c = colors[colorId + this.getColorIdOffset_(event)]; 76 return c.toStringWithAlphaOverride( 77 opt_alphaMultiplier !== undefined ? opt_alphaMultiplier : 1.0); 78 }, 79 80 getBarSnapshotColor: function(snapshot, offset) { 81 var colorId = 82 (snapshot.objectInstance.colorId + offset) % 83 numColorsPerVariant; 84 colorId += this.getColorIdOffset_(snapshot); 85 return colors[colorId].toStringWithAlphaOverride(1.0); 86 } 87 }; 88 89 return { 90 EventPresenter: EventPresenter 91 }; 92}); 93</script> 94