The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/expressions/components/Math.tsx

36 lines
1.0 KiB

import { css } from '@emotion/css';
import React, { ChangeEvent, FC } from 'react';
import { InlineField, TextArea } from '@grafana/ui';
import { ExpressionQuery } from '../types';
interface Props {
labelWidth: number;
query: ExpressionQuery;
onChange: (query: ExpressionQuery) => void;
}
const mathPlaceholder =
'Math operations on one more queries, you reference the query by ${refId} ie. $A, $B, $C etc\n' +
'Example: $A + $B\n' +
'Available functions: abs(), log(), is_number(), round(), ceil(), floor(), is_inf(), is_nan(), is_null(), ';
export const Math: FC<Props> = ({ labelWidth, onChange, query }) => {
const onExpressionChange = (event: ChangeEvent<HTMLTextAreaElement>) => {
onChange({ ...query, expression: event.target.value });
};
return (
<InlineField
label="Expression"
labelWidth={labelWidth}
className={css`
align-items: baseline;
`}
>
<TextArea value={query.expression} onChange={onExpressionChange} rows={4} placeholder={mathPlaceholder} />
</InlineField>
);
};