diff --git a/server/swagger.json b/server/swagger.json index 2e6394b48..508ee2be0 100644 --- a/server/swagger.json +++ b/server/swagger.json @@ -4349,39 +4349,141 @@ "format": "uuid4" }, "x": { - "description": "X-coordinate of Cell in the Layout", + "description": "X-coordinate of Cell in the Dashboard", "type": "integer", "format": "int32" }, "y": { - "description": "Y-coordinate of Cell in the Layout", + "description": "Y-coordinate of Cell in the Dashboard", "type": "integer", "format": "int32" }, "w": { - "description": "Width of Cell in the Layout", + "description": "Width of Cell in the Dashboard", "type": "integer", - "format": "int32" + "format": "int32", + "minimum": 1, + "default": 4 }, "h": { - "description": "Height of Cell in the Layout", + "description": "Height of Cell in the Dashboard", "type": "integer", - "format": "int32" + "format": "int32", + "minimum": 1, + "default": 4 }, "name": { - "description": "Cell name", + "description": "Title of Cell in the Dashboard", "type": "string" }, "queries": { - "description": "Time-series data queries for Cell.", + "description": "Time-series data queries for Cell", "type": "array", "items": { - "$ref": "#/definitions/LayoutQuery" + "$ref": "#/definitions/DashboardQuery" + } + }, + "axes": { + "description": "The viewport for a Cell's visualizations", + "type": "object", + "properties": { + "x": { + "$ref": "#/definitions/Axis" + }, + "y": { + "$ref": "#/definitions/Axis" + }, + "y2": { + "$ref": "#/definitions/Axis" + } } }, "type": { "description": "Cell visualization type", - "type": "string" + "type": "string", + "enum": [ + "single-stat", + "line", + "line-plus-single-stat", + "line-stacked", + "line-stepplot", + "bar", + "gauge", + "table" + ], + "default": "line" + }, + "colors": { + "description": "Colors define encoding data into a visualization", + "type": "array", + "items": { + "$ref": "#/definitions/DashboardColor" + } + }, + "legend": { + "description": + "Legend define encoding of the data into a cell's legend", + "type": "object", + "properties": { + "type": { + "description": "type is the style of the legend", + "type": "string", + "enum": ["static"] + }, + "orientation": { + "description": + "orientation is the location of the legend with respect to the cell graph", + "type": "string", + "enum": ["top", "bottom", "left", "right"] + } + } + }, + "tableOptions": { + "timeFormat": { + "description": + "timeFormat describes the display format for time values according to moment.js date formatting", + "type": "string" + }, + "verticalTimeAxis": { + "description": + "verticalTimeAxis describes the orientation of the table by indicating whether the time axis will be displayed vertically", + "type": "boolean" + }, + "sortBy": { + "description": + "sortBy contains the name of the series that is used for sorting the table", + "type": "object", + "$ref": "#/definitions/RenamableField" + }, + "wrapping": { + "description": + "wrapping describes the text wrapping style to be used in table cells", + "type": "string", + "enum": ["truncate", "wrap", "single-line"] + }, + "fieldNames": { + "description": + "fieldNames represent the fields retrieved by the query with customization options", + "type": "array", + "items": { + "$ref": "#/definitions/RenamableField" + } + }, + "fixFirstColumn": { + "description": + "fixFirstColumn indicates whether the first column of the table should be locked", + "type": "boolean" + } + }, + "links": { + "type": "object", + "properties": { + "self": { + "type": "string", + "description": "Self link mapping to this resource", + "format": "url" + } + } } }, "example": { @@ -4558,154 +4660,9 @@ "format": "int64" }, "cells": { - "description": "a list of dashboard visualizations", "type": "array", "items": { - "description": "cell visualization information", - "type": "object", - "properties": { - "x": { - "description": "X-coordinate of Cell in the Dashboard", - "type": "integer", - "format": "int32" - }, - "y": { - "description": "Y-coordinate of Cell in the Dashboard", - "type": "integer", - "format": "int32" - }, - "w": { - "description": "Width of Cell in the Dashboard", - "type": "integer", - "format": "int32", - "minimum": 1, - "default": 4 - }, - "h": { - "description": "Height of Cell in the Dashboard", - "type": "integer", - "format": "int32", - "minimum": 1, - "default": 4 - }, - "name": { - "description": "Name of Cell in the Dashboard", - "type": "string" - }, - "queries": { - "description": "Time-series data queries for Cell.", - "type": "array", - "items": { - "$ref": "#/definitions/DashboardQuery" - } - }, - "axes": { - "description": "The viewport for a cell's visualizations", - "type": "object", - "properties": { - "x": { - "$ref": "#/definitions/Axis" - }, - "y": { - "$ref": "#/definitions/Axis" - }, - "y2": { - "$ref": "#/definitions/Axis" - } - } - }, - "type": { - "description": "Cell visualization type", - "type": "string", - "enum": [ - "single-stat", - "line", - "line-plus-single-stat", - "line-stacked", - "line-stepplot", - "bar" - ], - "default": "line" - }, - "colors": { - "description": - "Colors define encoding data into a visualization", - "type": "array", - "items": { - "$ref": "#/definitions/DashboardColor" - } - }, - "legend": { - "description": - "Legend define encoding of the data into a cell's legend", - "type": "object", - "properties": { - "type": { - "description": "type is the style of the legend", - "type": "string", - "enum": ["static"] - }, - "orientation": { - "description": - "orientation is the location of the legend with respect to the cell graph", - "type": "string", - "enum": ["top", "bottom", "left", "right"] - } - } - }, - "tableOptions": { - "description": - "visualization options for a cell with table type", - "type": "object", - "properties": { - "timeFormat": { - "description": - "timeFormat describes the display format for time values according to moment.js date formatting", - "type": "string" - }, - "verticalTimeAxis": { - "description": - "verticalTimeAxis describes the orientation of the table by indicating whether the time axis will be displayed vertically", - "type": "boolean" - }, - "sortBy": { - "description": - "sortBy contains the name of the series that is used for sorting the table", - "type": "object", - "$ref": "#/definitions/RenamableField" - }, - "wrapping": { - "description": - "wrapping describes the text wrapping style to be used in table cells", - "type": "string", - "enum": ["truncate", "wrap", "single-line"] - }, - "fieldNames": { - "description": - "fieldNames represent the fields retrieved by the query with customization options", - "type": "array", - "items": { - "$ref": "#/definitions/RenamableField" - } - }, - "fixFirstColumn": { - "description": - "fixFirstColumn indicates whether this field should be visible on the table", - "type": "boolean" - } - } - }, - "links": { - "type": "object", - "properties": { - "self": { - "type": "string", - "description": "Self link mapping to this resource", - "format": "url" - } - } - } - } + "$ref": "#/definitions/Cell" } }, "name": { diff --git a/ui/src/shared/components/LineGraph.js b/ui/src/shared/components/LineGraph.js index 7cb2ca484..25905e317 100644 --- a/ui/src/shared/components/LineGraph.js +++ b/ui/src/shared/components/LineGraph.js @@ -4,7 +4,7 @@ import Dygraph from 'shared/components/Dygraph' import shallowCompare from 'react-addons-shallow-compare' import SingleStat from 'src/shared/components/SingleStat' -import timeSeriesToDygraph from 'utils/timeSeriesToDygraph' +import timeSeriesToDygraph from 'utils/timeSeriesTransformers' import {SINGLE_STAT_LINE_COLORS} from 'src/shared/graphs/helpers' diff --git a/ui/src/shared/components/MiniGraph.js b/ui/src/shared/components/MiniGraph.js new file mode 100644 index 000000000..2b25a1547 --- /dev/null +++ b/ui/src/shared/components/MiniGraph.js @@ -0,0 +1,129 @@ +import React from 'react' +import PropTypes from 'prop-types' +import Dygraph from './Dygraph' +import shallowCompare from 'react-addons-shallow-compare' + +import timeSeriesToDygraph from 'utils/timeSeriesTransformers' + +export default React.createClass({ + displayName: 'MiniGraph', + propTypes: { + data: PropTypes.array.isRequired, // eslint-disable-line react/forbid-prop-types + title: PropTypes.string, + queryDescription: PropTypes.string, + yRange: PropTypes.arrayOf(PropTypes.number.isRequired), + options: PropTypes.shape({ + combineSeries: PropTypes.bool, + }), + }, + + getDefaultProps() { + return { + options: {}, + } + }, + + shouldComponentUpdate(nextProps, nextState) { + return shallowCompare(this, nextProps, nextState) + }, + + render() { + const results = timeSeriesToDygraph(this.props.data) + const {fields, timeSeries} = this.props.options.combineSeries + ? this.combineSeries(results) + : results + + if (!timeSeries.length) { + return null + } + + const options = { + labels: fields, + showLabelsOnHighlight: false, + fillGraph: false, + connectSeparatedPoints: true, + axisLineColor: '#23232C', + gridLineColor: '#2E2E38', + gridLineWidth: 1, + strokeWidth: 1.5, + highlightCircleSize: 0, + highlightSeriesOpts: { + strokeWidth: 0, + highlightCircleSize: 0, + }, + highlightCallback() {}, + legend: 'never', + axes: { + x: { + drawGrid: false, + drawAxis: false, + }, + y: { + drawGrid: false, + drawAxis: false, + }, + }, + title: this.props.title, + rightGap: 0, + yRangePad: 10, + interactionModel: {}, + } + + const truncPrecision = 100000 + const latestValue = timeSeries[timeSeries.length - 1][1] + const truncated = Math.round(latestValue * truncPrecision) / truncPrecision + + const statText = ( +