Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
lineColor = threshold.lineColor;
break;
}
}
// fill
if (threshold.fill) {
if (threshold.yaxis === 'right' && this.hasSecondYAxis) {
options.grid.markings.push({
y2axis: { from: threshold.value, to: limit },
color: getColorFromHexRgbOrName(fillColor),
});
} else {
options.grid.markings.push({
yaxis: { from: threshold.value, to: limit },
color: getColorFromHexRgbOrName(fillColor),
});
}
}
if (threshold.line) {
if (threshold.yaxis === 'right' && this.hasSecondYAxis) {
options.grid.markings.push({
y2axis: { from: threshold.value, to: threshold.value },
color: getColorFromHexRgbOrName(lineColor),
});
} else {
options.grid.markings.push({
yaxis: { from: threshold.value, to: threshold.value },
color: getColorFromHexRgbOrName(lineColor),
});
}
}
lineColor = threshold.lineColor;
break;
}
}
// fill
if (threshold.fill) {
if (threshold.yaxis === 'right' && this.hasSecondYAxis) {
options.grid.markings.push({
y2axis: { from: threshold.value, to: limit },
color: getColorFromHexRgbOrName(fillColor),
});
} else {
options.grid.markings.push({
yaxis: { from: threshold.value, to: limit },
color: getColorFromHexRgbOrName(fillColor),
});
}
}
if (threshold.line) {
if (threshold.yaxis === 'right' && this.hasSecondYAxis) {
options.grid.markings.push({
y2axis: { from: threshold.value, to: threshold.value },
color: getColorFromHexRgbOrName(lineColor),
});
} else {
options.grid.markings.push({
yaxis: { from: threshold.value, to: threshold.value },
color: getColorFromHexRgbOrName(lineColor),
});
}
}
options.grid.markings.push({
yaxis: { from: threshold.value, to: limit },
color: getColorFromHexRgbOrName(fillColor),
});
}
}
if (threshold.line) {
if (threshold.yaxis === 'right' && this.hasSecondYAxis) {
options.grid.markings.push({
y2axis: { from: threshold.value, to: threshold.value },
color: getColorFromHexRgbOrName(lineColor),
});
} else {
options.grid.markings.push({
yaxis: { from: threshold.value, to: threshold.value },
color: getColorFromHexRgbOrName(lineColor),
});
}
}
}
}
}
let skip = true;
for (let i = 0; i < steps.length; i++) {
const step = steps[i];
if (skip) {
if (first === step) {
skip = false;
}
continue;
}
const prev = steps[i - 1];
formatted.push({ value: step.value, color: getColorFromHexRgbOrName(prev!.color, theme.type) });
if (step === last) {
break;
}
}
formatted.push({ value: max, color: getColorFromHexRgbOrName(last.color, theme.type) });
return formatted;
}
data.colorMap = panel.colors.map((color: string) => getColorFromHexRgbOrName(color, config.theme.type));
}
max: panel.sparkline.ymax,
},
xaxis: {
show: false,
mode: 'time',
min: ctrl.range.from.valueOf(),
max: ctrl.range.to.valueOf(),
},
grid: { hoverable: false, show: false },
};
elem.append(plotCanvas);
const plotSeries = {
data: data.sparkline,
color: getColorFromHexRgbOrName(panel.sparkline.lineColor, config.theme.type),
};
$.plot(plotCanvas, [plotSeries], options);
}
const rangeStep = 10;
const valuesRange = d3.range(0, legendWidth, rangeStep);
const legendRects = legend.selectAll('.heatmap-opacity-legend-rect').data(valuesRange);
legendRects
.enter()
.append('rect')
.attr('x', d => d)
.attr('y', 0)
.attr('width', rangeStep)
.attr('height', legendHeight)
.attr('stroke-width', 0)
.attr(
'fill',
getColorFromHexRgbOrName(
options.cardColor,
contextSrv.user.lightTheme ? GrafanaThemeType.Light : GrafanaThemeType.Dark
)
)
.style('opacity', d => legendOpacityScale(d));
}
}
if (timeRegion.colorMode === 'custom') {
return {
fill: timeRegion.fill && timeRegion.fillColor ? getColorFromHexRgbOrName(timeRegion.fillColor, theme) : null,
line: timeRegion.line && timeRegion.lineColor ? getColorFromHexRgbOrName(timeRegion.lineColor, theme) : null,
};
}
const colorMode = colorModes[timeRegion.colorMode];
if (colorMode.themeDependent === true) {
return theme === GrafanaThemeType.Light ? colorMode.lightColor : colorMode.darkColor;
}
return {
fill: timeRegion.fill ? getColorFromHexRgbOrName(colorMode.color.fill, theme) : null,
line: timeRegion.fill ? getColorFromHexRgbOrName(colorMode.color.line, theme) : null,
};
}
getFormattedThresholds(): Threshold[] {
const { field, theme } = this.props;
const isPercent = field.thresholds?.mode === ThresholdsMode.Percentage;
const steps = field.thresholds!.steps;
let min = field.min!;
let max = field.max!;
if (isPercent) {
min = 0;
max = 100;
}
const first = getActiveThreshold(min, steps);
const last = getActiveThreshold(max, steps);
const formatted: Threshold[] = [];
formatted.push({ value: min, color: getColorFromHexRgbOrName(first.color, theme.type) });
let skip = true;
for (let i = 0; i < steps.length; i++) {
const step = steps[i];
if (skip) {
if (first === step) {
skip = false;
}
continue;
}
const prev = steps[i - 1];
formatted.push({ value: step.value, color: getColorFromHexRgbOrName(prev!.color, theme.type) });
if (step === last) {
break;
}
}
formatted.push({ value: max, color: getColorFromHexRgbOrName(last.color, theme.type) });