Skip to content

Commit

Permalink
Merge pull request #1230 from weaveworks/1224-format-sparkline
Browse files Browse the repository at this point in the history
Apply format to tooltips in sparkline hovers
  • Loading branch information
davkal committed Apr 7, 2016
2 parents 0badd93 + d803e00 commit b7c2db6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function NodeDetailsHealthItem(props) {
<div className="node-details-health-item">
<div className="node-details-health-item-value">{formatMetric(props.value, props)}</div>
<div className="node-details-health-item-sparkline">
<Sparkline data={props.samples} max={props.max}
<Sparkline data={props.samples} max={props.max} format={props.format}
first={props.first} last={props.last} />
</div>
<div className="node-details-health-item-label">{props.label}</div>
Expand Down
9 changes: 6 additions & 3 deletions client/app/scripts/components/sparkline.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import React from 'react';
import d3 from 'd3';

import { formatMetricSvg } from '../utils/string-utils';

const parseDate = d3.time.format.iso.parse;

export default class Sparkline extends React.Component {
Expand Down Expand Up @@ -56,10 +58,11 @@ export default class Sparkline extends React.Component {
const lastValue = data[data.length - 1].value;
const lastX = this.x(lastDate);
const lastY = this.y(lastValue);
const min = formatMetricSvg(d3.min(data, d => d.value), this.props);
const max = formatMetricSvg(d3.max(data, d => d.value), this.props);
const mean = formatMetricSvg(d3.mean(data, d => d.value), this.props);
const title = `Last ${d3.round((lastDate - firstDate) / 1000)} seconds, ` +
`${data.length} samples, min: ${d3.round(d3.min(data, d => d.value), 2)}` +
`, max: ${d3.round(d3.max(data, d => d.value), 2)}` +
`, mean: ${d3.round(d3.mean(data, d => d.value), 2)}`;
`${data.length} samples, min: ${min}, max: ${max}, mean: ${mean}`;

return {title, lastX, lastY, data};
}
Expand Down

0 comments on commit b7c2db6

Please sign in to comment.