일목균형표 수정
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import type { HLineStyle } from './indicatorRegistry';
|
||||
import type { HLineStyle, PlotDef } from './indicatorRegistry';
|
||||
|
||||
const DEFAULT_HIST_UP = '#26A69A';
|
||||
const DEFAULT_HIST_DOWN = '#EF5350';
|
||||
|
||||
/** 업비트/트레이딩뷰 스타일 색상 팔레트 (10×7) */
|
||||
export const COLOR_PALETTE: string[] = [
|
||||
@@ -48,3 +51,44 @@ export const LINE_STYLE_LABELS: Record<HLineStyle, string> = {
|
||||
dashed: '점선',
|
||||
dotted: '도트',
|
||||
};
|
||||
|
||||
/** histogram 막대 색에 투명도(88) 보장 */
|
||||
export function withHistogramAlpha(color: string): string {
|
||||
if (color.startsWith('rgba(') || color.startsWith('rgb(')) return color;
|
||||
if (color.length >= 9 && color.startsWith('#')) return color;
|
||||
if (color.length >= 7 && color.startsWith('#')) return `${color}88`;
|
||||
return `${color}88`;
|
||||
}
|
||||
|
||||
export function resolveHistogramUpColor(plot: PlotDef): string {
|
||||
return plot.histogramUpColor ?? plot.color ?? DEFAULT_HIST_UP;
|
||||
}
|
||||
|
||||
export function resolveHistogramDownColor(plot: PlotDef): string {
|
||||
return plot.histogramDownColor ?? DEFAULT_HIST_DOWN;
|
||||
}
|
||||
|
||||
/** MACD 등 histogram 막대 색 (상승·하락/음수 구분) */
|
||||
export function histogramBarColor(
|
||||
value: number,
|
||||
prev: number | null | undefined,
|
||||
plot: PlotDef,
|
||||
pointColor?: string,
|
||||
): string {
|
||||
if (pointColor) return withHistogramAlpha(pointColor);
|
||||
const isDown = prev != null && !isNaN(prev) && value < prev;
|
||||
const isNeg = value < 0;
|
||||
const raw = (isDown || isNeg) ? resolveHistogramDownColor(plot) : resolveHistogramUpColor(plot);
|
||||
return withHistogramAlpha(raw);
|
||||
}
|
||||
|
||||
export function mapHistogramSeriesData(
|
||||
filtered: Array<{ time: number; value: number; color?: string }>,
|
||||
plot: PlotDef,
|
||||
): Array<{ time: import('lightweight-charts').Time; value: number; color: string }> {
|
||||
return filtered.map((p, idx, arr) => ({
|
||||
time: p.time as import('lightweight-charts').Time,
|
||||
value: p.value,
|
||||
color: histogramBarColor(p.value, idx > 0 ? arr[idx - 1].value : null, plot, p.color),
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user