Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Commit

Permalink
Fix #173 Link Heatmap of Dashboard to Trace
Browse files Browse the repository at this point in the history
A node of Heatmap represents a range of Trace.
  • Loading branch information
hanahmily committed Jun 8, 2018
1 parent 9750aec commit c960050
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
25 changes: 23 additions & 2 deletions src/components/Charts/HeatMap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ class HeatMap extends Component {
}
mapXAxisData = (reducedData, datetime) =>
reducedData.map((count, i) => ({ datetime, responseTime: i, count }))
handlePlotClick = (dtStart, dtEnd, responseTime) => {
const removedUnit = responseTime.slice(0, responseTime.indexOf('ms'));
let min;
let max;
if (removedUnit.indexOf('>') === 0) {
min = parseInt(removedUnit.slice(1), 10);
} else {
const value = parseInt(removedUnit, 10);
min = value - 100 < 0 ? 0 : value - 100;
max = value;
}
this.props.onClick({ start: dtStart, end: dtEnd }, { min, max });
}
render() {
const {
height,
Expand All @@ -63,7 +76,7 @@ class HeatMap extends Component {
if (!nodes || nodes.length < 1) {
return (<span style={{ display: 'none' }} />);
}
const { display: { range } } = duration;
const { display: { range }, raw: { range: rawRange } } = duration;

const source = [];
let maxResponseTimeOffset = 0;
Expand Down Expand Up @@ -118,7 +131,15 @@ class HeatMap extends Component {
return (
<div className={styles.chart} style={{ height }}>
<div>
<Chart data={mergeSource} scale={cols} forceFit height={height * 1.4}>
<Chart
data={mergeSource}
scale={cols}
forceFit
height={height * 1.4}
onPlotClick={({ data: { _origin: { datetime, responseTime } } }) =>
this.handlePlotClick(rawRange[datetime], rawRange[datetime + 1]
, responseTimeAxis[responseTime])}
>
<Axis
name="datetime"
grid={{
Expand Down
1 change: 1 addition & 0 deletions src/models/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default {
collapsed: true,
selected: payload,
display: value.display,
raw: value.raw,
},
globalVariables: { duration: value.input },
};
Expand Down
8 changes: 2 additions & 6 deletions src/models/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,8 @@ export default generateModal({
dispatch({
type: 'saveVariables',
payload: {
values: {
applicationId: state.key,
},
labels: {
applicationId: state.label,
},
values: state.values,
labels: state.labels,
},
});
}
Expand Down
13 changes: 12 additions & 1 deletion src/routes/Dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Row, Col, Card, Tooltip, Icon } from 'antd';
import {
ChartCard, MiniArea, Field, HeatMap,
} from '../../components/Charts';
import { axis } from '../../utils/time';
import { axis, generateDuration } from '../../utils/time';
import { avgTimeSeries, redirect } from '../../utils/utils';
import { Panel } from '../../components/Page';
import RankList from '../../components/RankList';
Expand Down Expand Up @@ -105,6 +105,17 @@ export default class Dashboard extends PureComponent {
data={data.getThermodynamic}
duration={this.props.duration}
height={200}
onClick={(duration, responseTimeRange) => redirect(this.props.history, '/trace', { values: { duration: generateDuration({
from() {
return duration.start;
},
to() {
return duration.end;
},
}),
minTraceDuration: responseTimeRange.min,
maxTraceDuration: responseTimeRange.max,
} })}
/>
</ChartCard>
</Col>
Expand Down
7 changes: 5 additions & 2 deletions src/utils/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

import moment from 'moment';

export function axis({ display }, data, tranformFunc) {
return display.range.map((v, i) =>
Expand All @@ -28,19 +29,21 @@ export function generateDuration({ from, to }) {
const lenght = mlist.length;
const { measureType, step, format, displayFormat } = mlist
.find((_, index) => ((index + 1 >= lenght) || end.diff(start, _.measureType) > 1));
const range = Array.from({ length: end.diff(start, measureType) + 2 },
(v, i) => start.clone().add(i, measureType).format(displayFormat));
return {
input: {
start: start.format(format),
end: end.format(format),
step,
},
display: {
range: Array.from({ length: end.diff(start, measureType) + 1 },
(v, i) => start.clone().add(i, measureType).format(displayFormat)),
range: range.slice(0, range.length - 1),
},
raw: {
start,
end,
range: range.map(_ => moment(_, displayFormat)),
},
};
}
Expand Down

0 comments on commit c960050

Please sign in to comment.