Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the definition of background #18

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/components/FlowPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { getTemplateSrv } from '@grafana/runtime';
import { GrafanaTheme2, PanelProps, toDataFrame } from '@grafana/data';
import { FlowOptions, DebuggingCtrs } from '../types';
import { configInit, panelConfigFactory, PanelConfig, siteConfigFactory, SiteConfig } from 'components/Config';
import { HighlighterFactory } from 'components/Highlighter';
import { HighlightState, HighlighterFactory } from 'components/Highlighter';
import { loadSvg, loadYaml } from 'components/Loader';
import { svgInit, svgUpdate, SvgHolder, SvgElementAttribs } from 'components/SvgUpdater';
import { seriesExtend, seriesInterpolate , seriesTransform } from 'components/TimeSeries';
import { TimeSliderFactory } from 'components/TimeSlider';
import { displayColorsInner, displayDataInner, displayMappingsInner, displaySvgInner } from 'components/DebuggingEditor';
import { appendUrlParams, getInstrumenter } from 'components/Utils';
import { appendUrlParams, colorLookup, getInstrumenter } from 'components/Utils';
import { addHook, sanitize } from 'dompurify';

interface Props extends PanelProps<FlowOptions> {}
Expand Down Expand Up @@ -261,10 +261,26 @@ export const FlowPanel: React.FC<Props> = ({ options, data, width, height, timeZ
timeZone: timeZone,
});

//---------------------------------------------------------------------------
// Define the background

const svgAttribs = svgHolder ? svgHolder.attribs : {
width: width,
height: height,
scaleDrive: false,
highlightFactors: {
highlightRgbFactor: 1.0,
lowlightAlphaFactor: 1.0,
}
};
let bgColor = useTheme2().isDark ? panelConfig?.background.darkThemeColor : panelConfig?.background.lightThemeColor;
if (bgColor) {
bgColor = colorLookup(bgColor, HighlightState.Ambient, svgAttribs.highlightFactors);
}

//---------------------------------------------------------------------------
// Define the canvas

const svgAttribs = svgHolder ? svgHolder.attribs : {width: width, height: height, scaleDrive: false};
const svgWidth = svgAttribs.width;
const svgHeight = svgAttribs.height;
const highlighterHeight = highlighterEnabled ? 60 : 0;
Expand All @@ -290,6 +306,7 @@ export const FlowPanel: React.FC<Props> = ({ options, data, width, height, timeZ
display: flex;
padding-left: ${svgPaddingLeft}px;
padding-top: ${svgAttribs.scaleDrive ? svgPaddingTop : 0}px;
${bgColor ? "background-color: " + bgColor : ""};
`
)}>
<div className={cx(
Expand Down
8 changes: 1 addition & 7 deletions src/components/SvgUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SiteConfig, VariableThresholdScalars } from 'components/Config';
import { TimeSeriesData } from 'components/TimeSeries';
import {
cellIdFactory, CellIdMaker, colorLookup, getColor,
cellIdFactory, CellIdMaker, getColor,
primeColorCache,
variableThresholdScalarsInit, variableThresholdScaleValue } from 'components/Utils';
import { HighlightState } from './Highlighter';
Expand Down Expand Up @@ -182,12 +182,6 @@ export function svgInit(doc: Document, grafanaTheme: GrafanaTheme2, panelConfig:
// Initialie the color cache and setup the background
primeColorCache(grafanaTheme, svgAttribs, panelConfig.background);

// Set background according to theme if defined in config
const bgColor = grafanaTheme.isDark ? panelConfig.background.darkThemeColor : panelConfig.background.lightThemeColor;
if (bgColor) {
doc.documentElement.style.backgroundColor = colorLookup(bgColor, HighlightState.Ambient, svgAttribs.highlightFactors);
}

return svgAttribs;
}

Expand Down
Loading