aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tensorboard/components/vz_heatmap/demo/index.html
blob: 0ef092fccc4a140a2b077086b670c088719def6c (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
156
157
158
159
160
161
<!doctype html>
<!--
@license
Copyright 2016 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Heatmap example</title>
  <link rel="import" href="../vz-heatmap.html">
  <link rel="import" href="../../iron-demo-helpers/demo-snippet.html">
  <link rel="import" href="../../tf-imports/d3.html">
</head>
<script>
  function generateRandomMatrix() {
    var rows = getRandomArbitrary(10, 20);
    var columns = getRandomArbitrary(10, 20);
    var data = [];
    // Generate new data array.
    for (var row = 0; row < rows; row++) {
      var currentRow = [];
      for (var col = 0; col < columns; col++) {
        currentRow[col] = getRandomArbitrary(0, 20);
      }
      data[row] = currentRow;
    }
    return data;
  }

  // Returns a random number between min (inclusive) and max (exclusive)
  function getRandomArbitrary(min, max) {
    return Math.random() * (max - min) + min;
  }

  function getRandomColorRange() {
    return [getRandomColor(), getRandomColor()];
  }

  function getRandomColor() {
    var letters = '0123456789ABCDEF';
    var color = '#';
    for (var i = 0; i < 6; i++) {
      color += letters[Math.floor(Math.random() * 16)];
    }
    return color;
  }
</script>
<body>
<h1>Initialized with data</h1>
<div style="width: 30%">
  <demo-snippet>
    <template>
      <vz-heatmap data="[[1,2],[3,4]]"></vz-heatmap>
    </template>
  </demo-snippet>
</div>

<h1>Initialized with data and custom data range</h1>
<div style="width: 30%">
  <demo-snippet>
    <template>
      <vz-heatmap data="[[1,2],[3,4]]" values="[0,10]"></vz-heatmap>
    </template>
  </demo-snippet>
</div>

<h1>Initialized with data and colors</h1>
<div style="width: 30%">
  <demo-snippet>
    <template>
      <vz-heatmap data="[[1,2],[3,4]]" colors='["yellow", "red"]'></vz-heatmap>
    </template>
  </demo-snippet>
</div>

<h1>Initialized with data and colors and threshold values</h1>
<div style="width: 30%">
  <demo-snippet>
    <template>
      <vz-heatmap data="[[1,2],[3,4]]"
                  values="[0, 10]"
                  colors='["yellow", "red"]'
      ></vz-heatmap>
    </template>
  </demo-snippet>
</div>
<h1>Initialized with data and color function</h1>
<div style="width: 30%">
  <demo-snippet>
    <template>
      <vz-heatmap id="color_function" data="[[1,2],[3,4]]"
      ></vz-heatmap>
    </template>
  </demo-snippet>
  <script>
    setTimeout(function () {
      var heatmapColor = document.getElementById('color_function');
      heatmapColor.colorFunction =
          d3.scaleLinear().range(['white', 'black']).domain([0, 5]);
    }, 1500);
  </script>
</div>

<h1>Initialized with data and updated data</h1>
<h3>Click on the heatmap to create new random data.</h3>
<div style="width: 30%">
  <demo-snippet>
    <template>
      <vz-heatmap data="[[1,2],[3,4]]"
                  onclick="this.data = generateRandomMatrix()"
      >
      </vz-heatmap>
    </template>
  </demo-snippet>
</div>

<h1>Initialized with data and updated color update</h1>
<h3>Click on the heatmap to update the color scheme.</h3>
<div style="width: 30%">
  <demo-snippet>
    <template>
      <vz-heatmap id="data_color_update" data="[[1,2],[3,4]]"
                  onclick="this.colors = getRandomColorRange();
                       this.data = generateRandomMatrix()"
      >
      </vz-heatmap>
    </template>
  </demo-snippet>
</div>

<h2>Let's try to actually break it... *Puts on fedora*</h2>
<p>Code below is not meant to be seen, but to ensure that no errors are
  thrown when invalid data is passed into the Polymer element.</p>
<demo-snippet>
  <template>
    <vz-heatmap id="break_the_heatmap" data="undefined"></vz-heatmap>
  </template>
</demo-snippet>
<script>
  var bth = document.getElementById('break_the_heatmap');
  bth.data = []; // Empty 1D array.
  bth.data = [[]]; // Empty 2D array.
  bth.colors = ['yellow', 'blue', '']; // More than 2 elements in colors array.
  bth.values = [1, 2, 3]; // More than 2 elements in values array.
</script>

</body>
</html>