OLD | NEW |
1 /** | 1 /** |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 draw(context, x, height, pixelsPerMillisecond) {}, | 1487 draw(context, x, height, pixelsPerMillisecond) {}, |
1488 }; | 1488 }; |
1489 | 1489 |
1490 /** @enum {symbol} */ | 1490 /** @enum {symbol} */ |
1491 PerfUI.FlameChart.Events = { | 1491 PerfUI.FlameChart.Events = { |
1492 EntrySelected: Symbol('EntrySelected'), | 1492 EntrySelected: Symbol('EntrySelected'), |
1493 EntryHighlighted: Symbol('EntryHighlighted') | 1493 EntryHighlighted: Symbol('EntryHighlighted') |
1494 }; | 1494 }; |
1495 | 1495 |
1496 /** | 1496 /** |
| 1497 * @unrestricted |
| 1498 */ |
| 1499 PerfUI.FlameChart.ColorGenerator = class { |
| 1500 /** |
| 1501 * @param {!{min: number, max: number}|number=} hueSpace |
| 1502 * @param {!{min: number, max: number, count: (number|undefined)}|number=} sat
Space |
| 1503 * @param {!{min: number, max: number, count: (number|undefined)}|number=} lig
htnessSpace |
| 1504 * @param {!{min: number, max: number, count: (number|undefined)}|number=} alp
haSpace |
| 1505 */ |
| 1506 constructor(hueSpace, satSpace, lightnessSpace, alphaSpace) { |
| 1507 this._hueSpace = hueSpace || {min: 0, max: 360}; |
| 1508 this._satSpace = satSpace || 67; |
| 1509 this._lightnessSpace = lightnessSpace || 80; |
| 1510 this._alphaSpace = alphaSpace || 1; |
| 1511 /** @type {!Map<string, string>} */ |
| 1512 this._colors = new Map(); |
| 1513 } |
| 1514 |
| 1515 /** |
| 1516 * @param {string} id |
| 1517 * @param {string} color |
| 1518 */ |
| 1519 setColorForID(id, color) { |
| 1520 this._colors.set(id, color); |
| 1521 } |
| 1522 |
| 1523 /** |
| 1524 * @param {string} id |
| 1525 * @return {string} |
| 1526 */ |
| 1527 colorForID(id) { |
| 1528 var color = this._colors.get(id); |
| 1529 if (!color) { |
| 1530 color = this._generateColorForID(id); |
| 1531 this._colors.set(id, color); |
| 1532 } |
| 1533 return color; |
| 1534 } |
| 1535 |
| 1536 /** |
| 1537 * @param {string} id |
| 1538 * @return {string} |
| 1539 */ |
| 1540 _generateColorForID(id) { |
| 1541 var hash = String.hashCode(id); |
| 1542 var h = this._indexToValueInSpace(hash, this._hueSpace); |
| 1543 var s = this._indexToValueInSpace(hash >> 8, this._satSpace); |
| 1544 var l = this._indexToValueInSpace(hash >> 16, this._lightnessSpace); |
| 1545 var a = this._indexToValueInSpace(hash >> 24, this._alphaSpace); |
| 1546 return `hsla(${h}, ${s}%, ${l}%, ${a})`; |
| 1547 } |
| 1548 |
| 1549 /** |
| 1550 * @param {number} index |
| 1551 * @param {!{min: number, max: number, count: (number|undefined)}|number} spac
e |
| 1552 * @return {number} |
| 1553 */ |
| 1554 _indexToValueInSpace(index, space) { |
| 1555 if (typeof space === 'number') |
| 1556 return space; |
| 1557 var count = space.count || space.max - space.min; |
| 1558 index %= count; |
| 1559 return space.min + Math.floor(index / (count - 1) * (space.max - space.min))
; |
| 1560 } |
| 1561 }; |
| 1562 |
| 1563 /** |
1497 * @implements {PerfUI.TimelineGrid.Calculator} | 1564 * @implements {PerfUI.TimelineGrid.Calculator} |
1498 * @unrestricted | 1565 * @unrestricted |
1499 */ | 1566 */ |
1500 PerfUI.FlameChart.Calculator = class { | 1567 PerfUI.FlameChart.Calculator = class { |
1501 /** | 1568 /** |
1502 * @param {!PerfUI.FlameChartDataProvider} dataProvider | 1569 * @param {!PerfUI.FlameChartDataProvider} dataProvider |
1503 */ | 1570 */ |
1504 constructor(dataProvider) { | 1571 constructor(dataProvider) { |
1505 this._dataProvider = dataProvider; | 1572 this._dataProvider = dataProvider; |
1506 } | 1573 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 } | 1629 } |
1563 | 1630 |
1564 /** | 1631 /** |
1565 * @override | 1632 * @override |
1566 * @return {number} | 1633 * @return {number} |
1567 */ | 1634 */ |
1568 boundarySpan() { | 1635 boundarySpan() { |
1569 return this._maximumBoundaries - this._minimumBoundaries; | 1636 return this._maximumBoundaries - this._minimumBoundaries; |
1570 } | 1637 } |
1571 }; | 1638 }; |
OLD | NEW |