Skip to content

Commit

Permalink
generate layout as well as data-grid
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolas committed May 23, 2018
1 parent 1604212 commit d199b43
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/TimecodeEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ export default class TimecodeEditor extends React.Component {

TimecodeEditor.propTypes = {
min: PropTypes.number.isRequired,
onChange: PropTypes.func.isRequired,
timecode: PropTypes.number.isRequired
};
43 changes: 42 additions & 1 deletion src/Track.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,46 @@ export default class Track extends React.Component {
super(props);
this.width = 910;
}
// TODO: generateLayout / generateItems logic is identical, and
// could be merged.
generateLayout(trackData) {
let layout = [];
const me = this;
trackData.map(function(data, i) {
if (!me.props.duration ||
// In case of bad track data, it's possible that the
// track item's start time could be greater than the
// spine's duration. Track items like this just
// shouldn't be displayed.
data.start_time > me.props.duration
) {
return;
}

// A similar fix for bad track data: track items that
// have a start time within a valid range, but an out
// of bounds end time should just be capped to the valid
// range.
const itemLen = Math.min(
data.end_time - data.start_time,
me.props.duration);

const width = percentToTrackCoords(
(itemLen / me.props.duration) * 100);

const percent = (data.start_time / me.props.duration) * 100;
const xPos = percentToTrackCoords(percent);

const item = {
x: xPos,
y: 0,
w: width,
h: 49
};
layout.push(item);
});
return layout;
}
generateItems(trackData) {
let items = [];
const me = this;
Expand All @@ -46,7 +86,7 @@ export default class Track extends React.Component {

// A similar fix for bad track data: track items that
// have a start time within a valid range, but an out
// of bounds end time should just be capped to the valid
// of bounds end time should just be capped to the valid
// range.
const itemLen = Math.min(
data.end_time - data.start_time,
Expand Down Expand Up @@ -124,6 +164,7 @@ export default class Track extends React.Component {
rowHeight={1}
autoSize={false}
isResizable={false}
layout={this.generateLayout(this.props.data)}
preventCollision={true}>
{this.generateItems(this.props.data)}
</ReactGridLayout>
Expand Down

0 comments on commit d199b43

Please sign in to comment.