Загрузка данных


private applyMode(target: PriceScaleTarget): void {
  const pane = this.getPaneById(target.paneId);

  if (!pane) {
    return;
  }

  const priceScale = pane.getPriceScale(
    target.priceScaleId,
  );

  const {
    autoScale,
    mode: currentMode,
  } = priceScale.options();

  const nextMode = this.getActiveMode(target);

  const visibleRange = this.getVisibleRangeSnapshot({
    priceScale,
    autoScale,
    currentMode,
    nextMode,
  });

  priceScale.applyOptions({
    mode: nextMode,
  });

  if (visibleRange) {
    priceScale.setVisibleRange(visibleRange);
  } else {
    priceScale.setAutoScale(autoScale);
  }
}

private getVisibleRangeSnapshot({
  priceScale,
  autoScale,
  currentMode,
  nextMode,
}: {
  priceScale: IPriceScaleApi;
  autoScale: boolean;
  currentMode: PriceScaleMode;
  nextMode: PriceScaleMode;
}): IRange<number> | null {
  if (autoScale) {
    return null;
  }

  const shouldRestoreRange =
    currentMode === PriceScaleMode.Logarithmic &&
    nextMode === PriceScaleMode.Normal;

  return shouldRestoreRange
    ? priceScale.getVisibleRange()
    : null;
}