Skip to content

Commit

Permalink
Wrap dateTime handling on visualization paragraphs.
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Fitzgibbons <peter.fitzgibbons@gmail.com>
  • Loading branch information
pjfitzgibbons committed Dec 20, 2023
1 parent bfd8c93 commit 6d20f85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
10 changes: 8 additions & 2 deletions public/components/custom_panels/helpers/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,15 @@ export const renderSavedVisualization = async ({
const dynamicLayoutFromQueryData = (queryData) => {
const labelCount = queryData.jsonData.length;
const legendLines = min([labelCount, 10]);
const legendLineHeight = 30;
const graphHeight = 280;
const legendVerticalOffset = -0.5;
const legendOffsetPerLine = -0.4;
const legendOffset = legendVerticalOffset + legendOffsetPerLine * legendLines;

const height = graphHeight + legendLines * legendLineHeight;
const y = legendOffset;

const height = 230 + legendLines * 30;
const y = -0.35 + -0.15 * legendLines;
return {
height,
legend: { orientation: 'h', x: 0, y },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { EuiCodeBlock, EuiSpacer, EuiText } from '@elastic/eui';
import MarkdownRender from '@nteract/markdown';
import { Media } from '@nteract/outputs';
import moment from 'moment';
import React, { useState } from 'react';
import { VisualizationContainer } from '../../../../components/custom_panels/panel_modules/visualization_container';
import PPLService from '../../../../services/requests/ppl';
Expand All @@ -18,6 +17,7 @@ import {
import { ParaType } from '../../../../../common/types/notebooks';
import { getOSDHttp, getPPLService, uiSettingsService } from '../../../../../common/utils';
import { QueryDataGridMemo } from './para_query_grid';
import { convertDateTime } from '../../../common/query_utils';

const createQueryColumns = (jsonColumns: any[]) => {
let index = 0;
Expand Down Expand Up @@ -99,7 +99,11 @@ const OutputBody = ({
* TODO: add table rendering
*/
const dateFormat = uiSettingsService.get('dateFormat');

const from = convertDateTime(visInput?.timeRange?.from, true, false);
const to = convertDateTime(visInput?.timeRange?.from, false, false);
const displayFrom = convertDateTime(visInput?.timeRange?.from, true) || 'Invalid date';
const displayTo = convertDateTime(visInput?.timeRange?.from, false) || 'Invalid date';
console.log('display', { displayFrom, displayTo, from, to, dateFormat });
if (typeOut !== undefined) {
switch (typeOut) {
case 'QUERY':
Expand All @@ -111,32 +115,25 @@ const OutputBody = ({
</EuiText>
);
case 'VISUALIZATION':
let from = moment(visInput?.timeRange?.from).format(dateFormat);
let to = moment(visInput?.timeRange?.to).format(dateFormat);
from = from === 'Invalid date' ? visInput.timeRange.from : from;
to = to === 'Invalid date' ? visInput.timeRange.to : to;
return (
<>
<EuiText size="s" style={{ marginLeft: 9 }}>
{`${from} - ${to}`}
{`${displayFrom} - ${displayTo}`}
</EuiText>
<DashboardContainerByValueRenderer input={visInput} onInputUpdated={setVisInput} />
</>
);
case 'OBSERVABILITY_VISUALIZATION':
const http = getOSDHttp();
const pplService = getPPLService();
let fromObs = moment(visInput?.timeRange?.from).format(dateFormat);
let toObs = moment(visInput?.timeRange?.to).format(dateFormat);
fromObs = fromObs === 'Invalid date' ? visInput.timeRange.from : fromObs;
toObs = toObs === 'Invalid date' ? visInput.timeRange.to : toObs;

const onEditClick = (savedVisualizationId: string) => {
window.location.assign(`observability-logs#/explorer/${savedVisualizationId}`);
};
return (
<>
<EuiText size="s" style={{ marginLeft: 9 }}>
{`${fromObs} - ${toObs}`}
{`${displayFrom} - ${displayTo}`}
</EuiText>
<div style={{ height: '300px', width: '100%' }}>
<VisualizationContainer
Expand All @@ -146,8 +143,8 @@ const OutputBody = ({
onEditClick={onEditClick}
savedVisualizationId={visInput.visSavedObjId}
pplService={pplService}
fromTime={visInput?.timeRange?.from}
toTime={visInput?.timeRange?.to}
fromTime={from}
toTime={to}
onRefresh={false}
pplFilterValue={''}
usedInNotebooks={true}
Expand Down

0 comments on commit 6d20f85

Please sign in to comment.