Skip to content

Commit

Permalink
change stats to calcs in config
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed May 3, 2019
1 parent 3358054 commit 7874699
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class FieldDisplayEditor extends PureComponent<Props> {
this.props.onChange({ ...this.props.options, values: val });
};

onStatsChange = (stats: string[]) => {
this.props.onChange({ ...this.props.options, stats });
onCalcsChange = (calcs: string[]) => {
this.props.onChange({ ...this.props.options, calcs });
};

onTitleChange = (event: ChangeEvent<HTMLInputElement>) =>
Expand All @@ -70,7 +70,7 @@ export class FieldDisplayEditor extends PureComponent<Props> {

render() {
const { showPrefixSuffix, options, children } = this.props;
const { title, stats, prefix, suffix, values, limit } = options;
const { title, calcs, prefix, suffix, values, limit } = options;

const titleTooltip = (
<div>
Expand Down Expand Up @@ -122,8 +122,8 @@ export class FieldDisplayEditor extends PureComponent<Props> {
placeholder="Choose Stat"
defaultStat={StatID.mean}
allowMultiple={false}
stats={stats}
onChange={this.onStatsChange}
stats={calcs}
onChange={this.onCalcsChange}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const sharedSingleStatMigrationCheck = (panel: PanelModel<SingleStatBaseO

// Make sure the stats have a valid name
if (valueOptions.stat) {
fieldOptions.stats = getStatsCalculators([valueOptions.stat]).map(s => s.id);
fieldOptions.calcs = getStatsCalculators([valueOptions.stat]).map(s => s.id);
}
}
field.min = old.minValue;
Expand Down
16 changes: 8 additions & 8 deletions packages/grafana-ui/src/utils/fieldDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export interface FieldDisplayOptions {
prefix?: string;
suffix?: string;

values: boolean; // If true show each row value
values?: boolean; // If true show each row value
limit?: number; // if showing all values limit
stats: string[]; // when !values, pick one value for the whole field
calcs: string[]; // when !values, pick one value for the whole field

defaults: Partial<Field>; // Use these values unless otherwise stated
override: Partial<Field>; // Set these values regardless of the source
Expand Down Expand Up @@ -90,13 +90,13 @@ export const DEFAULT_FIELD_DISPLAY_VALUES_LIMIT = 25;
export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): FieldDisplay[] => {
const { data, replaceVariables, fieldOptions, sparkline } = options;
const { defaults, override } = fieldOptions;
const stats = fieldOptions.stats.length ? fieldOptions.stats : [StatID.last];
const calcs = fieldOptions.calcs.length ? fieldOptions.calcs : [StatID.last];

const values: FieldDisplay[] = [];

if (data) {
const limit = fieldOptions.limit ? fieldOptions.limit : DEFAULT_FIELD_DISPLAY_VALUES_LIMIT;
const title = getTitleTemplate(fieldOptions.title, stats, data);
const title = getTitleTemplate(fieldOptions.title, calcs, data);
const usesCellValues = title.indexOf(VAR_CELL_PREFIX) >= 0;
const scopedVars: ScopedVars = {};

Expand Down Expand Up @@ -172,7 +172,7 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi
const results = calculateStats({
series,
fieldIndex: i,
stats, // The stats to calculate
stats: calcs, // The stats to calculate
nullValueMode: NullValueMode.Null,
});

Expand All @@ -187,9 +187,9 @@ export const getFieldDisplayValues = (options: GetFieldDisplayValuesOptions): Fi
nullValueMode: NullValueMode.Null,
});

for (const stat of stats) {
scopedVars[VAR_CALC] = { value: stat, text: stat };
const displayValue = display(results[stat]);
for (const calc of calcs) {
scopedVars[VAR_CALC] = { value: calc, text: calc };
const displayValue = display(results[calc]);
displayValue.title = replaceVariables(title, scopedVars);
values.push({
field,
Expand Down
2 changes: 1 addition & 1 deletion public/app/plugins/panel/gauge/GaugeMigrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const gaugePanelMigrationCheck = (panel: PanelModel<GaugeOptions>): Parti

// Make sure the stats have a valid name
if (valueOptions.stat) {
fieldOptions.stats = getStatsCalculators([valueOptions.stat]).map(s => s.id);
fieldOptions.calcs = getStatsCalculators([valueOptions.stat]).map(s => s.id);
}
}
field.min = old.minValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
exports[`Gauge Panel Migrations from 6.1.1 1`] = `
Object {
"fieldOptions": Object {
"calcs": Array [
"last",
],
"defaults": Object {
"decimals": 3,
"max": "50",
Expand All @@ -21,9 +24,6 @@ Object {
},
],
"prefix": "XX",
"stats": Array [
"last",
],
"suffix": "YY",
"thresholds": Array [
Object {
Expand Down
2 changes: 1 addition & 1 deletion public/app/plugins/panel/piechart/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const defaults: PieChartOptions = {
orientation: VizOrientation.Auto,
fieldOptions: {
...standardFieldDisplayOptions,
stats: [StatID.last],
calcs: [StatID.last],
defaults: {
unit: 'short',
},
Expand Down
2 changes: 1 addition & 1 deletion public/app/plugins/panel/singlestat2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface SingleStatOptions extends SingleStatBaseOptions {
export const standardFieldDisplayOptions: FieldDisplayOptions = {
title: '', // auto title
values: false,
stats: [StatID.mean],
calcs: [StatID.mean],
defaults: {},
override: {},
mappings: [],
Expand Down

0 comments on commit 7874699

Please sign in to comment.