aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tensorboard/components/tf-event-dashboard/tf-chart.html
blob: 49f9d8954412b36536639d04e65b1a97c67be2f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../tf-imports/plottable.html">
<link rel="import" href="../tf-imports/lodash.html">

<!--
tf-chart (TFChart) creates an element that draws a line chart for displaying event values.
It has the following settable properties:
  tag: (required, string) - the name of the tag to load for this chart
  selectedRuns: (required, string[]) - the runs the chart should display
  xType: (required, string) - the way to display x values - allows "step" or "wall_time"
  dataCoordinator: (required, TF.DataCoordinator) - the data coordinator for talking to backend
  colorScale: (required, Plottable.Scales.Color) - maps from runs to colors: (required, function) - allows the chart to modify tooltips

It exposes the following methods:
  redraw() - cause the chart to re-render (useful if e.g. container size changed)

The data is expected to be an array of [wall_time, step, value] arrays.
The wall_time is serialized as seconds since epoch.
-->
<dom-module id="tf-chart">
  <template>
    <svg id="chartsvg"></svg>
    <div id="tooltip">
      <table>
        <thead>
          <tr>
            <th></th>
            <th>Run</th>
            <th>Value</th>
            <th>Step</th>
            <th>Time</th>
            <th>Relative</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
    </div>
    <style>
      :host {
        -webkit-user-select: none;
        -moz-user-select: none;
        display: flex;
        flex-direction: column;
        flex-grow: 1;
        flex-shrink: 1;
        position: relative;
      }
      svg {
        -webkit-user-select: none;
        -moz-user-select: none;
        flex-grow: 1;
        flex-shrink: 1;
      }
      td {
        padding-left: 5px;
        padding-right: 5px;
        font-size: 13px;
        opacity: 1;
      }
      #tooltip {
        pointer-events: none;
        position: absolute;
        opacity: 0;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
        font-size: 14px;
        background: rgba(0, 0, 0, 0.8);
        color: white;
        border-radius: 4px;
        line-height: 1.4em;
        padding: 8px;
        z-index: 5;
        cursor: none;
      }
      .swatch {
        border-radius: 50%;
        width: 14px;
        height: 14px;
        display: block;
        border: 2px solid rgba(0,0,0,0);
      }
      .closest .swatch {
        border: 2px solid white;
      }
      th {
        padding-left: 5px;
        padding-right: 5px;
        text-align: left;
      }
      .distant td {
        opacity: 0.8;
      }

      .distant td.swatch {
        opacity: 1;
      }

    </style>
  </template>
  <script src="dragZoomInteraction.js"></script>
  <script src="tf-chart.js"></script>
  <script src="tf-chart-helpers.js"></script>
  <script>
    Polymer({
      is: "tf-chart",
      properties: {
        type: String, // "scalar" or "compressedHistogram"
        _chart: Object,
        colorScale: Object,
        tag: String,
        selectedRuns: Array,
        xType: String,
        dataProvider: Function,
        _initialized: Boolean,
      },
      observers: [
        "_makeChart(tag, dataProvider, xType, colorScale, _initialized)",
        "_changeRuns(_chart, selectedRuns.*)"
      ],
      _changeRuns: function(chart) {
        if (chart.tag !== this.tag) {
          return; // hack around some weird polymer bug :(
        }
        this._chart.changeRuns(this.selectedRuns);
        this.redraw();
      },
      redraw: function() {
        this._chart.redraw();
      },
      reload: function() {
        this._chart.reload();
      },
      _makeChart: function(tag, dataProvider, xType, colorScale, _initialized) {
        if (!_initialized) {
          return;
        }
        if (this._chart) this._chart.destroy();
        var tooltip = d3.select(this.$.tooltip);
        this.scopeSubtree(this.$.tooltip, true);
        var chart = new TF.LineChart(tag, dataProvider, xType, colorScale, tooltip);
        var svg = d3.select(this.$.chartsvg);
        this.async(function() {
          chart.renderTo(svg);
          this._chart = chart;
        }, 350);
      },
      attached: function() {
        this._initialized = true;
      },
      detached: function() {
        this._initialized = false;
      }
    });
  </script>
</dom-module>