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

Update API for changing label appearance for last price and studies #41

Closed
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
4 changes: 4 additions & 0 deletions src/chart/chart.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ export const getDefaultConfig = (): FullChartConfig => ({
boxNegative: 'rgba(217,44,64,1)',
boxPositive: 'rgba(77,153,83,1)',
boxSelected: 'rgba(255,255,255,1)',
labelTextNegative: 'rgba(217,44,64,1)',
labelTextPositive: 'rgba(77,153,83,1)',
},
countdownToBarClose: {
textNegative: 'rgba(255,255,255,1)',
Expand Down Expand Up @@ -1408,6 +1410,8 @@ export interface YAxisLastPriceLabelColorConfig {
textSelected: string;
textNegative: string;
textPositive: string;
labelTextPositive: string;
labelTextNegative: string;
}

export interface YAxisBidAskLabelColorConfig {
Expand Down
11 changes: 11 additions & 0 deletions src/chart/components/y_axis/label-color.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import { FullChartColors, YAxisLabelsColors } from '../../chart.config';

export const DEFAULT_LABEL_COLOR = '#FF00FF';

export const getPlainLabelTextColor = (lastPriceMovement: PriceMovement, colors: YAxisLabelsColors): string => {
if (lastPriceMovement === 'down') {
return colors.lastPrice.labelTextNegative;
} else if (lastPriceMovement === 'up') {
return colors.lastPrice.labelTextPositive;
} else if (lastPriceMovement === 'none') {
return colors.lastPrice.labelTextPositive;
} else {
return colors.lastPrice.labelTextPositive;
}
};
export const getPrimaryLabelTextColor = (lastPriceMovement: PriceMovement, colors: YAxisLabelsColors): string => {
if (lastPriceMovement === 'down') {
return colors.lastPrice.textNegative;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ export class DataSeriesYAxisLabelsProvider implements YAxisLabelsProvider {
const config = this.series.config;
const paintConfig = config.paintConfig[0] ?? DEFAULT_DATA_SERIES_PAINT_CONFIG;
const bgColor = paintConfig.color;
const textColor = getLabelTextColorByBackgroundColor(bgColor, 'white', 'black');

const textColor = getLabelTextColorByBackgroundColor(
bgColor,
paintConfig.lightTextColor ?? 'white',
paintConfig.darkTextColor ?? 'black ',
);
return {
textColor,
bgColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FullChartConfig, YAxisConfig } from '../../../chart.config';
import { CandleSeriesModel } from '../../../model/candle-series.model';
import { DataSeriesType } from '../../../model/data-series.config';
import { ChartModel, LastCandleLabelHandler } from '../../chart/chart.model';
import { getPrimaryLabelTextColor } from '../label-color.functions';
import { getPlainLabelTextColor, getPrimaryLabelTextColor } from '../label-color.functions';
import { YAxisLabelDrawConfig } from '../y-axis-labels.drawer';
import { LabelGroup, VisualYAxisLabel, YAxisLabelsProvider } from './y-axis-labels.model';
import { lastOf } from '../../../utils/array.utils';
Expand All @@ -30,9 +30,11 @@ export class LastCandleLabelsProvider implements YAxisLabelsProvider {
public getUnorderedLabels(): LabelGroup[] {
const collectedLabels: LabelGroup[] = [];
const visible = this.yAxisConfig.labels.settings.lastPrice.mode !== 'none';

if (visible) {
// main candle series
const yAxisVisualLabel = this.getYAxisVisualLabel(this.chartModel.mainCandleSeries);

const mainCandleSeriesVisualLabel: VisualYAxisLabel | null = yAxisVisualLabel
? {
...yAxisVisualLabel,
Expand Down Expand Up @@ -105,13 +107,18 @@ export class LastCandleLabelsProvider implements YAxisLabelsProvider {
*/
private getLabelDrawConfig(series: CandleSeriesModel, primary: boolean): YAxisLabelDrawConfig {
const colors = series.colors.labels;
const isPlain = this.fullConfig.components.yAxis.labels.settings['lastPrice'].type === 'plain';
const getLabelBoxColor = this.resolveLabelColorFn(series.config.type);
const { rectLabelTextColor, rectLabelInvertedTextColor } = this.chartModel.config.colors.yAxis;
let boxColor = '#FFFFFF';
let textColor = '#FFFFFF';
if (colors) {
boxColor = getLabelBoxColor(series.lastPriceMovement, series.colors);
textColor = primary ? getPrimaryLabelTextColor(series.lastPriceMovement, colors) : rectLabelTextColor;
textColor = isPlain
? getPlainLabelTextColor(series.lastPriceMovement, colors)
: primary
? getPrimaryLabelTextColor(series.lastPriceMovement, colors)
: rectLabelTextColor;
}
return {
bgColor: boxColor,
Expand Down
2 changes: 2 additions & 0 deletions src/chart/model/data-series.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface DataSeriesPaintConfig {
color: string;
lineWidth: number;
hoveredLineWidth: number;
lightTextColor?: string;
darkTextColor?: string;
//add this for TREND_HISTOGRAM study type
// this way not add breaking change
aditionalColor?: string;
Expand Down