fix: 분봉 툴팁 등락률을 당일시가대비 → 전일대비로 (현재 등락율과 일치)

당일시가대비(vs 오늘 시가)는 갭하락 때 현재 등락율과 어긋남(예: 삼성전자
시가대비 -4.1% vs 전일대비 -7%대). 관리자 요청대로 그 봉 종가 vs 전일종가
기준으로 변경 → 마지막 봉이 현재 등락율(-7%대)과 일치.
- meta.dayOpen 제거, meta.prevClose(=ref_price) 주입
- _setOhlcText: '당일시가대비' → '전일대비' 라인
- day_open 캡처/파라미터 제거(불필요)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hyowons
2026-06-10 14:23:23 +09:00
parent 8bfaecbd1e
commit af058cf36d
2 changed files with 8 additions and 11 deletions
+5 -7
View File
@@ -7317,11 +7317,11 @@ def render_html() -> str:
'xTipTxt.appendChild(_mkTspan({"font-size":24,"font-weight":500},_pctStr(c.l,c.o),lcol));'
'xTipTxt.appendChild(_mkTspan({x:16,dy:34,"font-size":28,"font-weight":700},""+c.c.toLocaleString()+" ",ccol));'
'xTipTxt.appendChild(_mkTspan({"font-size":24,"font-weight":700},_pctStr(c.c,c.o),ccol));'
# 분봉: 당일 시가(첫 봉) 대비 등락률 — 그 시점까지의 오늘 누적 등락.
'var hasDO=meta.dayOpen&&meta.dayOpen>0;'
'if(hasDO){xTipTxt.appendChild(_mkTspan({x:16,dy:32,"font-size":23,"font-weight":600},"당일시가대비 "+_pctStr(c.c,meta.dayOpen),_col(c.c,meta.dayOpen)));}'
# 분봉: 전일종가 대비 등락률 — 그 봉 종가 vs 전일종가 (현재 등락율과 일치).
'var hasPC=meta.prevClose&&meta.prevClose>0;'
'if(hasPC){xTipTxt.appendChild(_mkTspan({x:16,dy:32,"font-size":23,"font-weight":600},"전일대비 "+_pctStr(c.c,meta.prevClose),_col(c.c,meta.prevClose)));}'
# 팝업 위치 — vline 의 반대 쪽으로 자동 배치 (좌/우). 화면 벗어남 방지 clamp.
'var tipW=340,tipH=hasDO?212:176,gap=10;'
'var tipW=340,tipH=hasPC?212:176,gap=10;'
# 당일시가 라인 유무에 따라 배경 박스·닫기버튼 위치 동적 조정.
'xTipBg.setAttribute("width",tipW);xTipBg.setAttribute("height",tipH);'
'closeG.setAttribute("transform","translate("+(tipW-20)+",20)");'
@@ -10024,8 +10024,6 @@ class Handler(BaseHTTPRequestHandler):
if not mins:
self.send_error(404, 'no minute candles')
return
# 당일 시가 = 오늘 첫 봉 시가. range 슬라이스 전에 캡처 — 구간을 좁혀도 baseline 고정.
day_open = mins[0].get('open') or 0
# range 슬라이스 — 최근 N 봉만.
if range_minutes is not None:
num_bars = max(1, range_minutes // tic_scope)
@@ -10063,7 +10061,7 @@ class Handler(BaseHTTPRequestHandler):
prev_close = _pc
except Exception:
pass
svg = sa.render_svg_chart(snap, range_key='1Y', ref_price=prev_close, intraday=True, day_open=day_open)
svg = sa.render_svg_chart(snap, range_key='1Y', ref_price=prev_close, intraday=True)
body = svg.encode('utf-8')
body, enc = _maybe_gzip(body, self.headers.get('Accept-Encoding'))
self.send_response(200)
@@ -546,7 +546,7 @@ VOL_BOT = VOL_TOP + VOL_PANEL_H
CHART_RANGE_DAYS = {'1Y': 250, '6M': 120, '1M': 21}
def render_svg_chart(snap: dict, range_key: str = '1Y', ref_price: float | None = None, intraday: bool = False, day_open: float | None = None) -> str:
def render_svg_chart(snap: dict, range_key: str = '1Y', ref_price: float | None = None, intraday: bool = False) -> str:
"""캔들 + SMA 3선 + 거래량 막대 인라인 SVG.
range_key: '1Y' (250일) | '6M' (120일) | '1M' (21일). 같은 snapshot 데이터에서 슬라이스만.
@@ -611,9 +611,8 @@ def render_svg_chart(snap: dict, range_key: str = '1Y', ref_price: float | None
],
'ymin': y_min,
'ymax': y_max,
# 분봉일 때만 당일 시가 — 크로스헤어 툴팁의 '당일시가 대비 등락률'용.
# day_open(슬라이스 전 오늘 첫 봉 시가)을 caller가 넘기면 그걸 baseline으로 (구간 슬라이스 영향 X).
'dayOpen': (int(day_open) if (intraday and day_open) else 0),
# 분봉일 때만 전일종가(ref_price) — 크로스헤어 툴팁의 '전일대비 등락률'용 (현재 등락율과 일치).
'prevClose': (int(ref_price) if (intraday and ref_price) else 0),
'priceTop': PRICE_TOP,
'priceBot': PRICE_BOT,
'volTop': VOL_TOP,