Skip to content

Commit baa1792

Browse files
committed
improve chart formatting and query loading
Signed-off-by: Daniel Rowe <[email protected]>
1 parent 51e498e commit baa1792

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/plugins/discover/public/application/components/visualizations/vislib/line/to_expression.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,11 @@ const createVegaSpec = (rows: OpenSearchSearchHit[], indexPattern: IndexPattern)
8080
];
8181

8282
for (let i = 1; i < columns.length; i++) {
83-
const colorIndex = (i - 1) % colorPalette.length;
84-
const color = colorPalette[colorIndex];
85-
8683
const yAxisParam = {
8784
field: columns[i].name,
8885
type: 'quantitative',
8986
scale: { zero: false },
90-
axis: { titleColor: color, title: columns[i].name },
87+
axis: { title: '' },
9188
};
9289

9390
const tooltipParam = [
@@ -119,8 +116,10 @@ const createVegaSpec = (rows: OpenSearchSearchHit[], indexPattern: IndexPattern)
119116
range: colorPalette.slice(0, columns.length - 1),
120117
},
121118
legend: {
122-
title: 'Series',
123-
labelExpr: "datum.label + ': ' + '" + columns[i].field + "'",
119+
title: '',
120+
labelExpr: "'" + columns[i].field + "'",
121+
orient: 'bottom',
122+
labelLimit: 999,
124123
},
125124
},
126125
};

src/plugins/discover/public/application/view_components/utils/use_prometheus.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { useState, useEffect, useCallback, useMemo } from 'react';
6+
import { useState, useEffect, useCallback, useMemo, useRef } from 'react';
77
import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public';
88
import { DiscoverViewServices } from '../../../build_services';
99

@@ -33,16 +33,14 @@ export const usePrometheus = (): PrometheusContext => {
3333
const [labelNames, setLabelNames] = useState<string[]>([]);
3434

3535
const updateLabels = useCallback(async () => {
36-
const labels = await prometheusResourceClient.getLabels('my_prometheus', selectedMetricName);
36+
const labels = await prometheusResourceClient.getLabels('my_prometheus');
3737
setLabelNames(labels.sort());
38-
}, [prometheusResourceClient, selectedMetricName]);
38+
}, [prometheusResourceClient]);
3939

4040
const updateMetrics = useCallback(async () => {
4141
const metricMetadata = await prometheusResourceClient.getMetricMetadata('my_prometheus');
4242
const metrics = Object.keys(metricMetadata).sort();
43-
const defaultMetric = metrics[0];
4443
setMetricNames(metrics);
45-
setSelectedMetricName(defaultMetric);
4644
}, [prometheusResourceClient]);
4745

4846
useEffect(() => {
@@ -54,9 +52,11 @@ export const usePrometheus = (): PrometheusContext => {
5452
}, [selectedMetricName, updateLabels]);
5553

5654
useEffect(() => {
57-
data.query.queryString.setQuery({
58-
query: selectedMetricName,
59-
});
55+
if (selectedMetricName) {
56+
data.query.queryString.setQuery({
57+
query: selectedMetricName,
58+
});
59+
}
6060
/* eslint-disable-next-line react-hooks/exhaustive-deps */
6161
}, [selectedMetricName]);
6262

0 commit comments

Comments
 (0)