Skip to content

Commit 426f60a

Browse files
committed
Change sample time line to vertical layout
1 parent 6cd6fda commit 426f60a

2 files changed

Lines changed: 67 additions & 51 deletions

File tree

demo/filereader.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
writing-mode: vertical-rl;
125125
vertical-align: middle;
126126
}
127+
.pair:hover .block {
128+
stroke: yellow !important;
129+
stroke-width: 3;
130+
filter: drop-shadow(0 0 8px yellow);
131+
}
127132
</style>
128133
<link rel="stylesheet" href="style.css" />
129134
<script async defer src="https://buttons.github.io/buttons.js"></script>

demo/filereader.js

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,90 +1006,74 @@ function buildSampleMap(start, end) {
10061006
}
10071007
}
10081008

1009-
SampleTimeline.prototype.update = function () {
1009+
function verticalTimeline () {
10101010
var that = this;
10111011
var data = this.data;
10121012
if (!data || data.length === 0) {
10131013
return;
10141014
}
1015-
var scale = data[0].duration ? 50 / data[0].duration : 50;
1016-
var sample_height = 30;
1017-
var height_spacing = 10;
1018-
var x_offset = 100;
1019-
this.svg.html('');
1020-
this.svg
1021-
.append('text')
1022-
.attr('x', 0)
1023-
.attr('y', sample_height / 2)
1024-
.text('Decoding');
1025-
this.svg.append('text').attr('x', 0).attr('y', sample_height).text('Timeline');
1026-
this.svg
1027-
.append('text')
1028-
.attr('x', 0)
1029-
.attr('y', (3 * sample_height) / 2 + height_spacing)
1030-
.text('Composition');
1031-
this.svg
1032-
.append('text')
1033-
.attr('x', 0)
1034-
.attr('y', 2 * sample_height + height_spacing)
1035-
.text('Timeline');
1036-
this.svg
1037-
.append('defs')
1038-
.append('marker')
1039-
.attr('id', 'arrow')
1040-
.attr('markerWidth', 13)
1041-
.attr('markerHeight', 13)
1042-
.attr('refX', 2)
1043-
.attr('refY', 6)
1044-
.attr('orient', 'auto')
1045-
.append('path')
1046-
.attr('d', 'M2,2 L2,11 L10,6 L2,2')
1047-
.attr('fill', 'black');
1015+
var scale = data[0].duration ? 30 / data[0].duration : 30;
1016+
const sample_width = 120;
1017+
const content = this.svg.select("g.content");
1018+
content.html('');
10481019
var dts_offset = data[0].dts;
1020+
var ypos = 50;
10491021
data.forEach(function (d, i) {
1050-
var sampleg = that.svg.append('g').attr('transform', 'translate(' + x_offset + ')');
1022+
var sampleg = content.append('g').attr("class","pair");
1023+
const dts_y = (d.dts - dts_offset) * scale + ypos;
1024+
const cts_y = (d.cts - dts_offset) * scale + ypos;
1025+
const rect_h = d.duration * scale;
1026+
const rect_middle = rect_h / 2;
1027+
// Decoding Timeline
10511028
sampleg
10521029
.append('rect')
1053-
.attr('x', (d.dts - dts_offset) * scale)
1054-
.attr('y', 0)
1055-
.attr('width', d.duration * scale)
1056-
.attr('height', sample_height)
1030+
.attr('y', dts_y)
1031+
.attr('width', sample_width)
1032+
.attr('height',rect_h)
1033+
.attr("class","block")
10571034
.style('fill', 'red')
10581035
.style('stroke', d.is_sync ? 'black' : 'none');
10591036
sampleg
10601037
.append('text')
10611038
.attr('text-anchor', 'middle')
10621039
.attr('dominant-baseline', 'central')
1063-
.attr('x', (d.dts - dts_offset + d.duration / 2) * scale)
1064-
.attr('y', sample_height / 2)
1040+
.attr('x', sample_width/ 2)
1041+
.attr('y', dts_y + rect_middle )
10651042
.text(d.dts);
1043+
1044+
// Composition Timeline
10661045
sampleg
10671046
.append('rect')
1068-
.attr('x', (d.cts - dts_offset) * scale)
1069-
.attr('y', sample_height + height_spacing)
1070-
.attr('width', d.duration * scale)
1071-
.attr('height', sample_height)
1047+
.attr('x', sample_width *2)
1048+
.attr('y', cts_y)
1049+
.attr('width', sample_width)
1050+
.attr('height', rect_h)
1051+
.attr("class","block")
10721052
.style('fill', 'blue')
10731053
.style('stroke', d.is_sync ? 'black' : 'none');
10741054
sampleg
10751055
.append('text')
10761056
.attr('text-anchor', 'middle')
10771057
.attr('dominant-baseline', 'central')
1078-
.attr('x', (d.cts - dts_offset + d.duration / 2) * scale)
1079-
.attr('y', sample_height + height_spacing + sample_height / 2)
1058+
.attr('x', sample_width *2.5)
1059+
.attr('y', cts_y + rect_middle)
10801060
.text(d.cts);
1061+
10811062
sampleg
10821063
.append('line')
1083-
.attr('x1', (d.dts - dts_offset + d.duration / 2) * scale)
1084-
.attr('y1', sample_height)
1085-
.attr('x2', (d.cts - dts_offset + d.duration / 2) * scale)
1086-
.attr('y2', sample_height + height_spacing)
1064+
.attr('x1', sample_width)
1065+
.attr('y1', dts_y + rect_middle)
1066+
.attr('x2', sample_width*2)
1067+
.attr('y2', cts_y + rect_middle)
1068+
.attr("class","block")
10871069
.attr('stroke-width', '1px')
10881070
.attr('marker-end', 'url(#arrow)')
10891071
.style('stroke', 'black');
10901072
});
10911073
};
10921074

1075+
SampleTimeline.prototype.update = verticalTimeline;
1076+
10931077
function SampleTimeline() {
10941078
var margin = { top: 10, right: 10, bottom: 80, left: 20 };
10951079
var width = (this.width = document.body.clientWidth - margin.left - margin.right);
@@ -1107,6 +1091,33 @@ function SampleTimeline() {
11071091
)
11081092
.append('g')
11091093
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
1094+
const sample_height = 30;
1095+
const sample_width = 120;
1096+
this.svg
1097+
.append('text')
1098+
.attr('x', sample_width/2)
1099+
.attr('y', sample_height/2)
1100+
.attr('text-anchor', 'middle')
1101+
.text('Decoding');
1102+
this.svg
1103+
.append('text')
1104+
.attr('x', sample_width*2.5)
1105+
.attr('y', sample_height/2)
1106+
.attr('text-anchor', 'middle')
1107+
.text('Composition');
1108+
this.svg
1109+
.append('defs')
1110+
.append('marker')
1111+
.attr('id', 'arrow')
1112+
.attr('markerWidth', 13)
1113+
.attr('markerHeight', 13)
1114+
.attr('refX', 10)
1115+
.attr('refY', 6)
1116+
.attr('orient', 'auto')
1117+
.append('path')
1118+
.attr('d', 'M2,2 L2,11 L10,6 z')
1119+
.attr('fill', 'black');
1120+
this.svg.append('g').attr("class","content");
11101121
}
11111122

11121123
SampleGraph.prototype.update = function () {

0 commit comments

Comments
 (0)