UNPKG

@devexperts/dxcharts-lite

Version:
76 lines (75 loc) 4.17 kB
/* * Copyright (C) 2019 - 2026 Devexperts Solutions IE Limited * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. */ import { getLabelTextColorByBackgroundColor } from '../../utils/canvas/canvas-text-functions.utils'; export const DEFAULT_LABEL_COLOR = '#FF00FF'; export function getPlainLabelTextColor(colorsConfig, textColor, invertedTextColor, yAxisState) { // `plain` label is transparent, so to calculate text color // we need to go down to draw hierarchy // the next is YAxis bg color const yAxisBGColor = colorsConfig.yAxis.backgroundColor; // if yAxis bg color is transparent, then we need to check chart area background color const plainChartBGColor = colorsConfig.chartAreaTheme.backgroundColor; // when chart area bg color is gradient, then we need to check which side yAxis is drawn // because color on the right side and left side is different const leftChartBGColor = colorsConfig.chartAreaTheme.backgroundGradientTopColor; const rightChartBGColor = colorsConfig.chartAreaTheme.backgroundGradientBottomColor; const gradientChartBGColor = yAxisState.align === 'left' ? leftChartBGColor : rightChartBGColor; const chartBGColor = colorsConfig.chartAreaTheme.backgroundMode === 'gradient' ? gradientChartBGColor : plainChartBGColor; const bgColor = yAxisBGColor === 'transparent' ? chartBGColor : yAxisBGColor; return getLabelTextColorByBackgroundColor(bgColor, textColor, invertedTextColor); } export const getPrimaryLabelTextColor = (lastPriceMovement, colors) => { if (lastPriceMovement === 'down') { return colors.lastPrice.textNegative; } else if (lastPriceMovement === 'up') { return colors.lastPrice.textPositive; } else if (lastPriceMovement === 'none') { return colors.lastPrice.textSelected; } else { return colors.lastPrice.textSelected; } }; export const resolveColorForBar = (priceMovement, colors) => { const resolvedColor = colors.barTheme[`${priceMovement}Color`]; return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR; }; export const resolveColorForLine = (priceMovement, colors) => { const resolvedColor = colors.lineTheme[`${priceMovement}Color`]; return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR; }; export const resolveColorForCandle = (priceMovement, colors) => { const resolvedColor = colors.candleTheme[`${priceMovement}Color`]; return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR; }; export const resolveColorForArea = (priceMovement, colors) => { const resolvedColor = colors.areaTheme.lineColor; return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR; }; export const resolveColorForScatterPlot = (priceMovement, colors) => { const resolvedColor = colors.scatterPlot.mainColor; return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR; }; export const resolveColorForHistogram = (priceMovement, colors) => { const resolvedColor = colors.histogram[`${priceMovement}Bright`]; return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR; }; export const resolveColorForBaseLine = (priceMovement, colors) => { const resolvedColor = priceMovement === 'up' ? colors.baseLineTheme.upperSectionStrokeColor : colors.baseLineTheme.lowerSectionStrokeColor; return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR; }; export const resolveColorForTrendAndHollow = (priceMovement, colors) => { const resolvedColor = colors.candleTheme[`${priceMovement}WickColor`]; return resolvedColor !== null && resolvedColor !== void 0 ? resolvedColor : DEFAULT_LABEL_COLOR; }; export const resolveDefaultColorForLabel = () => { console.warn('Fallback for label default color'); return DEFAULT_LABEL_COLOR; };