Home | History | Annotate | Download | only in tracks
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright (c) 2015 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 
      8 <link rel="import" href="/core/test_utils.html">
      9 <link rel="import" href="/ui/timeline_display_transform.html">
     10 <link rel="import" href="/ui/tracks/chart_axis.html">
     11 <link rel="import" href="/ui/tracks/chart_transform.html">
     12 
     13 <script>
     14 'use strict';
     15 
     16 tr.b.unittest.testSuite(function() {
     17   var TimelineDisplayTransform = tr.ui.TimelineDisplayTransform;
     18   var ChartTransform = tr.ui.tracks.ChartTransform;
     19   var ChartAxis = tr.ui.tracks.ChartAxis;
     20 
     21   function buildChartTransform() {
     22     var displayTransform = new TimelineDisplayTransform();
     23     displayTransform.panX = -20;
     24     displayTransform.scaleX = 0.5;
     25 
     26     var axis = new ChartAxis(-100, 100);
     27 
     28     var chartTransform = new ChartTransform(
     29         displayTransform,
     30         axis,
     31         500, /* trackWidth */
     32         80, /* trackHeight */
     33         15, /* topPadding */
     34         5, /* bottomPadding */
     35         3 /* pixelRatio */);
     36 
     37     return chartTransform;
     38   }
     39 
     40   test('checkFields', function() {
     41     var t = buildChartTransform();
     42 
     43     assert.equal(t.pixelRatio, 3);
     44 
     45     assert.equal(t.leftViewX, 0);
     46     assert.equal(t.rightViewX, 500);
     47     assert.equal(t.leftTimestamp, 20);
     48     assert.equal(t.rightTimestamp, 1020);
     49 
     50     assert.equal(t.outerTopViewY, 0);
     51     assert.equal(t.innerTopViewY, 15);
     52     assert.equal(t.innerBottomViewY, 75);
     53     assert.equal(t.outerBottomViewY, 80);
     54   });
     55 
     56   test('checkWorldXToViewX', function() {
     57     var t = buildChartTransform();
     58 
     59     assert.equal(t.worldXToViewX(-100), -60);
     60     assert.equal(t.worldXToViewX(0), -10);
     61     assert.equal(t.worldXToViewX(520), 250);
     62     assert.equal(t.worldXToViewX(1020), 500);
     63     assert.equal(t.worldXToViewX(1200), 590);
     64   });
     65 
     66   test('checkViewXToWorldX', function() {
     67     var t = buildChartTransform();
     68 
     69     assert.equal(t.viewXToWorldX(-60), -100);
     70     assert.equal(t.viewXToWorldX(-10), 0);
     71     assert.equal(t.viewXToWorldX(250), 520);
     72     assert.equal(t.viewXToWorldX(500), 1020);
     73     assert.equal(t.viewXToWorldX(590), 1200);
     74   });
     75 
     76   test('checkWorldYToViewY', function() {
     77     var t = buildChartTransform();
     78 
     79     assert.equal(t.worldYToViewY(-200), 105);
     80     assert.equal(t.worldYToViewY(-100), 75);
     81     assert.equal(t.worldYToViewY(0), 45);
     82     assert.equal(t.worldYToViewY(100), 15);
     83     assert.equal(t.worldYToViewY(200), -15);
     84   });
     85 });
     86 </script>
     87