/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type YAxis from '../component/YAxis'; import View from './View'; export default class CandleLastPriceView extends View { override drawImp(ctx: CanvasRenderingContext2D): void { const widget = this.getWidget(); const pane = widget.getPane(); const bounding = widget.getBounding(); const chartStore = pane.getChart().getChartStore(); const priceMarkStyles = chartStore.getStyles().candle.priceMark; const lastPriceMarkStyles = priceMarkStyles.last; const lastPriceMartViewStyles = lastPriceMarkStyles.line; if ( priceMarkStyles.show && lastPriceMarkStyles.show && lastPriceMartViewStyles.show ) { const yAxis = pane.getAxisComponent() as YAxis; const dataList = chartStore.getDataList(); const data = dataList[dataList.length - 1]; if (data != null) { const { close, open } = data; const priceY = yAxis.convertToNicePixel(close); let color: string; if (close > open) { color = lastPriceMarkStyles.upColor; } else if (close < open) { color = lastPriceMarkStyles.downColor; } else { color = lastPriceMarkStyles.noChangeColor; } this.createFigure({ name: 'line', attrs: { coordinates: [ { x: 0, y: priceY }, { x: bounding.width, y: priceY }, ], }, styles: { style: lastPriceMartViewStyles.style, color, size: lastPriceMartViewStyles.size, dashedValue: lastPriceMartViewStyles.dashedValue, }, })?.draw(ctx); } } } }