mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-06 11:41:28 +00:00
Refactored nodedetails to support multiple data sets, probably broke some tests Allow api requests to out-of-view topologies Fix ESC behavior with details panel Stack details panel like cards Details pain side-by-side Details panel piles Fix node details table header styles Render load and not-found captions like relatives Fix topology click action Make node detail tables sortable Grouped metrics for details health Group metrics in same style Link node details children Fix scroll issues on double-details Fix DESC sort order for node details table Save selected node labels in state - allows rendering of node labels from other topologies before details are loaded Change detail card UX, newest one at top, pile at bottom Details panel one pile w/ animation Sort details table nodes by metadata too Animate sidepanel from children too Fix radial layout Dont set origin if a node was already selected, suppresses animation stack effect: shift top cards to the left, shrink lower cards vertically Clear details card stack if sibling is selected Check if node is still selected on API response Make detail table sorters robust against non-uniform metadata Dont show scrollbar all the time, fix sort icon issue Button to show topology for relative Overflow metrics for details panel health Fix JS error when no metrics are available for container image details Column-based rendering of node details table Fix JS tests Review feedback (UI)
127 lines
3.7 KiB
JavaScript
127 lines
3.7 KiB
JavaScript
// Forked from: https://github.com/KyleAMathews/react-sparkline at commit a9d7c5203d8f240938b9f2288287aaf0478df013
|
|
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import d3 from 'd3';
|
|
|
|
export default class Sparkline extends React.Component {
|
|
componentDidMount() {
|
|
return this.renderSparkline();
|
|
}
|
|
|
|
renderSparkline() {
|
|
// If the sparkline has already been rendered, remove it.
|
|
const el = ReactDOM.findDOMNode(this);
|
|
while (el.firstChild) {
|
|
el.removeChild(el.firstChild);
|
|
}
|
|
|
|
const data = this.props.data.slice();
|
|
|
|
// Do nothing if no data is passed in.
|
|
if (data.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const x = d3.scale.linear().range([2, this.props.width - 2]);
|
|
const y = d3.scale.linear().range([this.props.height - 2, 2]);
|
|
|
|
// react-sparkline allows you to pass in two types of data.
|
|
// Data tied to dates and linear data. We need to change our line and x/y
|
|
// functions depending on the type of data.
|
|
|
|
// These are objects with a date key
|
|
let line;
|
|
let lastX;
|
|
let lastY;
|
|
let title;
|
|
if (data[0].date) {
|
|
// Convert dates into D3 dates
|
|
data.forEach(d => {
|
|
d.date = d3.time.format.iso.parse(d.date);
|
|
});
|
|
|
|
line = d3.svg.line().
|
|
interpolate(this.props.interpolate).
|
|
x(d => x(d.date)).
|
|
y(d => y(d.value));
|
|
|
|
const first = this.props.first ? d3.time.format.iso.parse(this.props.first) : d3.min(data, d => d.date);
|
|
const last = this.props.last ? d3.time.format.iso.parse(this.props.last) : d3.max(data, d => d.date);
|
|
x.domain([first, last]);
|
|
|
|
y.domain([
|
|
this.props.min || d3.min(data, d => d.value),
|
|
this.props.max || d3.max(data, d => d.value)
|
|
]);
|
|
|
|
lastX = x(data[data.length - 1].date);
|
|
lastY = y(data[data.length - 1].value);
|
|
title = 'Last ' + d3.round((last - first) / 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);
|
|
} else {
|
|
line = d3.svg.line().
|
|
interpolate(this.props.interpolate).
|
|
x((d, i) => x(i)).
|
|
y(d => y(d));
|
|
|
|
x.domain([
|
|
this.props.first || 0,
|
|
this.props.last || data.length
|
|
]);
|
|
|
|
y.domain([
|
|
this.props.min || d3.min(data),
|
|
this.props.max || d3.max(data)
|
|
]);
|
|
|
|
lastX = x(data.length - 1);
|
|
lastY = y(data[data.length - 1]);
|
|
title = data.length + ' samples, min: ' + d3.round(d3.min(data), 2) + ', max: ' + d3.round(d3.max(data), 2) + ', mean: ' + d3.round(d3.mean(data), 2);
|
|
}
|
|
|
|
d3.select(ReactDOM.findDOMNode(this)).attr('title', title);
|
|
|
|
const svg = d3.select(ReactDOM.findDOMNode(this)).
|
|
append('svg').
|
|
attr('width', this.props.width).
|
|
attr('height', this.props.height).
|
|
append('g');
|
|
|
|
svg.append('path').
|
|
datum(data).
|
|
attr('class', 'sparkline').
|
|
style('fill', 'none').
|
|
style('stroke', this.props.strokeColor).
|
|
style('stroke-width', this.props.strokeWidth).
|
|
attr('d', line);
|
|
|
|
svg.append('circle').
|
|
attr('class', 'sparkcircle').
|
|
attr('cx', lastX).
|
|
attr('cy', lastY).
|
|
attr('fill', '#46466a').
|
|
attr('fill-opacity', 0.6).
|
|
attr('stroke', 'none').
|
|
attr('r', this.props.circleDiameter);
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div/>
|
|
);
|
|
}
|
|
|
|
componentDidUpdate() {
|
|
return this.renderSparkline();
|
|
}
|
|
}
|
|
|
|
Sparkline.defaultProps = {
|
|
width: 80,
|
|
height: 16,
|
|
strokeColor: '#7d7da8',
|
|
strokeWidth: '0.5px',
|
|
interpolate: 'basis',
|
|
circleDiameter: 1.75,
|
|
data: [1, 23, 5, 5, 23, 0, 0, 0, 4, 32, 3, 12, 3, 1, 24, 1, 5, 5, 24, 23] // Some semi-random data.
|
|
};
|