MarkerTimeline
Summary: _typescript_ Reviewed By: priteshrnandgaonkar Differential Revision: D16828814 fbshipit-source-id: 13b86338a73a4838857a31e16ea184e35ebfa7d0
This commit is contained in:
committed by
Facebook Github Bot
parent
cd10856c3e
commit
3691305b4d
@@ -6,27 +6,28 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {Component} from 'react';
|
import {Component} from 'react';
|
||||||
import styled from '../styled/index.js';
|
import styled from 'react-emotion';
|
||||||
import Text from './Text.js';
|
import Text from './Text';
|
||||||
import FlexRow from './FlexRow.js';
|
import FlexRow from './FlexRow';
|
||||||
import {colors} from './colors.tsx';
|
import {colors} from './colors';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
type DataPoint = {
|
type DataPoint = {
|
||||||
time: number,
|
time: number;
|
||||||
color?: string,
|
color?: string;
|
||||||
label: string,
|
label: string;
|
||||||
key: string,
|
key: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = {|
|
type Props = {
|
||||||
onClick?: (keys: Array<string>) => mixed,
|
onClick?: (keys: Array<string>) => void;
|
||||||
selected?: ?string,
|
selected?: string | null | undefined;
|
||||||
points: Array<DataPoint>,
|
points: DataPoint[];
|
||||||
lineHeight: number,
|
lineHeight: number;
|
||||||
maxGap: number,
|
maxGap: number;
|
||||||
|};
|
};
|
||||||
|
|
||||||
const Markers = styled('div')(props => ({
|
const Markers = styled('div')((props: {totalTime: number}) => ({
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
margin: 10,
|
margin: 10,
|
||||||
height: props.totalTime,
|
height: props.totalTime,
|
||||||
@@ -41,61 +42,70 @@ const Markers = styled('div')(props => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const Point = styled(FlexRow)(props => ({
|
const Point = styled(FlexRow)(
|
||||||
position: 'absolute',
|
(props: {
|
||||||
top: props.positionY,
|
positionY: number;
|
||||||
left: 0,
|
onClick: Function;
|
||||||
right: 10,
|
number: number;
|
||||||
cursor: props.onClick ? 'pointer' : 'default',
|
threadColor: string;
|
||||||
borderRadius: 3,
|
selected: boolean;
|
||||||
alignItems: 'flex-start',
|
cut: boolean;
|
||||||
lineHeight: '16px',
|
}) => ({
|
||||||
':hover': {
|
|
||||||
background: `linear-gradient(to top, rgba(255,255,255,0) 0, #ffffff 10px)`,
|
|
||||||
paddingBottom: 5,
|
|
||||||
zIndex: 2,
|
|
||||||
'> span': {
|
|
||||||
whiteSpace: 'initial',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
'::before': {
|
|
||||||
position: 'relative',
|
|
||||||
textAlign: 'center',
|
|
||||||
fontSize: 8,
|
|
||||||
fontWeight: '500',
|
|
||||||
content: props.number ? `'${props.number}'` : '""',
|
|
||||||
display: 'inline-block',
|
|
||||||
width: 9,
|
|
||||||
height: 9,
|
|
||||||
flexShrink: 0,
|
|
||||||
color: 'rgba(0,0,0,0.4)',
|
|
||||||
lineHeight: '9px',
|
|
||||||
borderRadius: '999em',
|
|
||||||
border: '1px solid rgba(0,0,0,0.2)',
|
|
||||||
backgroundColor: props.threadColor,
|
|
||||||
marginRight: 6,
|
|
||||||
zIndex: 3,
|
|
||||||
boxShadow: props.selected
|
|
||||||
? `0 0 0 2px ${colors.macOSTitleBarIconSelected}`
|
|
||||||
: null,
|
|
||||||
},
|
|
||||||
'::after': {
|
|
||||||
content: props.cut ? '""' : null,
|
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
width: 11,
|
top: props.positionY,
|
||||||
top: -20,
|
|
||||||
left: 0,
|
left: 0,
|
||||||
height: 2,
|
right: 10,
|
||||||
background: colors.white,
|
cursor: props.onClick ? 'pointer' : 'default',
|
||||||
borderTop: `1px solid ${colors.light30}`,
|
borderRadius: 3,
|
||||||
borderBottom: `1px solid ${colors.light30}`,
|
alignItems: 'flex-start',
|
||||||
transform: `skewY(-10deg)`,
|
lineHeight: '16px',
|
||||||
},
|
':hover': {
|
||||||
}));
|
background: `linear-gradient(to top, rgba(255,255,255,0) 0, #ffffff 10px)`,
|
||||||
|
paddingBottom: 5,
|
||||||
|
zIndex: 2,
|
||||||
|
'> span': {
|
||||||
|
whiteSpace: 'initial',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'::before': {
|
||||||
|
position: 'relative',
|
||||||
|
textAlign: 'center',
|
||||||
|
fontSize: 8,
|
||||||
|
fontWeight: 500,
|
||||||
|
content: props.number ? `'${props.number}'` : '""',
|
||||||
|
display: 'inline-block',
|
||||||
|
width: 9,
|
||||||
|
height: 9,
|
||||||
|
flexShrink: 0,
|
||||||
|
color: 'rgba(0,0,0,0.4)',
|
||||||
|
lineHeight: '9px',
|
||||||
|
borderRadius: '999em',
|
||||||
|
border: '1px solid rgba(0,0,0,0.2)',
|
||||||
|
backgroundColor: props.threadColor,
|
||||||
|
marginRight: 6,
|
||||||
|
zIndex: 3,
|
||||||
|
boxShadow: props.selected
|
||||||
|
? `0 0 0 2px ${colors.macOSTitleBarIconSelected}`
|
||||||
|
: null,
|
||||||
|
},
|
||||||
|
'::after': {
|
||||||
|
content: props.cut ? '""' : null,
|
||||||
|
position: 'absolute',
|
||||||
|
width: 11,
|
||||||
|
top: -20,
|
||||||
|
left: 0,
|
||||||
|
height: 2,
|
||||||
|
background: colors.white,
|
||||||
|
borderTop: `1px solid ${colors.light30}`,
|
||||||
|
borderBottom: `1px solid ${colors.light30}`,
|
||||||
|
transform: `skewY(-10deg)`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
const Time = styled('span')({
|
const Time = styled('span')({
|
||||||
color: colors.light30,
|
color: colors.light30,
|
||||||
fontWeight: '300',
|
fontWeight: 300,
|
||||||
marginRight: 4,
|
marginRight: 4,
|
||||||
marginTop: -2,
|
marginTop: -2,
|
||||||
});
|
});
|
||||||
@@ -107,17 +117,17 @@ const Code = styled(Text)({
|
|||||||
});
|
});
|
||||||
|
|
||||||
type TimePoint = {
|
type TimePoint = {
|
||||||
timestamp: number,
|
timestamp: number;
|
||||||
markerNames: Array<string>,
|
markerNames: Array<string>;
|
||||||
markerKeys: Array<string>,
|
markerKeys: Array<string>;
|
||||||
isCut: boolean,
|
isCut: boolean;
|
||||||
positionY: number,
|
positionY: number;
|
||||||
color: string,
|
color: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {|
|
type State = {
|
||||||
timePoints: Array<TimePoint>,
|
timePoints: Array<TimePoint>;
|
||||||
|};
|
};
|
||||||
|
|
||||||
export default class MarkerTimeline extends Component<Props, State> {
|
export default class MarkerTimeline extends Component<Props, State> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@@ -126,9 +136,9 @@ export default class MarkerTimeline extends Component<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static getDerivedStateFromProps(props: Props) {
|
static getDerivedStateFromProps(props: Props) {
|
||||||
const sortedMarkers: Array<[number, Array<DataPoint>]> = Array.from(
|
const sortedMarkers: [number, DataPoint[]][] = Array.from(
|
||||||
props.points
|
props.points
|
||||||
.reduce((acc: Map<number, Array<DataPoint>>, cv: DataPoint) => {
|
.reduce((acc: Map<number, DataPoint[]>, cv: DataPoint) => {
|
||||||
const list = acc.get(cv.time);
|
const list = acc.get(cv.time);
|
||||||
if (list) {
|
if (list) {
|
||||||
list.push(cv);
|
list.push(cv);
|
||||||
@@ -136,7 +146,7 @@ export default class MarkerTimeline extends Component<Props, State> {
|
|||||||
acc.set(cv.time, [cv]);
|
acc.set(cv.time, [cv]);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, (new Map(): Map<number, Array<DataPoint>>))
|
}, new Map())
|
||||||
.entries(),
|
.entries(),
|
||||||
).sort((a, b) => a[0] - b[0]);
|
).sort((a, b) => a[0] - b[0]);
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ export {default as Heading} from './components/Heading.js';
|
|||||||
// filters
|
// filters
|
||||||
export type {Filter} from './components/filter/types.js';
|
export type {Filter} from './components/filter/types.js';
|
||||||
|
|
||||||
export {default as MarkerTimeline} from './components/MarkerTimeline.js';
|
export {default as MarkerTimeline} from './components/MarkerTimeline.tsx';
|
||||||
|
|
||||||
export {default as StackTrace} from './components/StackTrace.js';
|
export {default as StackTrace} from './components/StackTrace.js';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user