Skip to content

Perp chart tooltip#1710

Open
gemdev111 wants to merge 3 commits intomainfrom
perp-chart-tooltip
Open

Perp chart tooltip#1710
gemdev111 wants to merge 3 commits intomainfrom
perp-chart-tooltip

Conversation

@gemdev111
Copy link
Contributor

@gemdev111 gemdev111 commented Feb 17, 2026

Show a floating tooltip with Open, Close, Low/High range bar, and Volume when tapping a candle on the perpetual chart.

closes #1695

images:

 Show a floating tooltip with Open, High, Low, Close, and Volume data when the
   user taps and holds on a candle in the perpetual chart.

  - Tooltip appears near the top of the chart, flipping sides based on candle
  position
  - Includes a visual Low-High range bar with close position indicator
  - Volume displayed in abbreviated format (M/B)
  - Uses TextValue + TextStyle pattern consistent with ListItemView
  - Extracted RangeBarView / RangeBarViewModel as reusable components
  - Deduplicated price model creation in CandlestickChartView
  - Replaced inline color logic with PriceChangeColor.color(for:)
Use the full "Volume" label in the candle tooltip, add extra bottom padding to the RangeBarView and Divider to improve tooltip layout, and remove several unused localization entries (close, high, low, open) from Localized.swift.
@gemdev111 gemdev111 self-assigned this Feb 17, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gemdev111, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the perpetual chart by adding an interactive tooltip feature. This allows users to gain immediate, detailed insights into individual candlesticks by simply tapping on them. The change improves the user experience by providing crucial financial data like open, close, low, high, and volume in an easily accessible and visually intuitive manner, directly within the chart interface.

Highlights

  • Interactive Candlestick Tooltip: Implemented a floating tooltip that appears when a user taps on a candle in the perpetual chart, displaying detailed information.
  • Detailed Candle Information: The tooltip shows Open, Close, Low/High range bar, and Volume for the selected candlestick.
  • Dynamic Tooltip Positioning: The tooltip dynamically adjusts its position based on the selected candle's location on the chart to ensure visibility.
  • Refactored Price Color Logic: Centralized the logic for determining price change colors, improving consistency across the chart elements.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • Features/Perpetuals/Sources/ViewModels/CandleTooltipViewModel.swift
    • Added a new ViewModel to encapsulate and format data for the candle tooltip, including open, close, volume, and range bar details.
  • Features/Perpetuals/Sources/ViewModels/RangeBarViewModel.swift
    • Added a new ViewModel to define the data structure for the low/high range bar component within the tooltip.
  • Features/Perpetuals/Sources/Views/CandleTooltipView.swift
    • Added a new SwiftUI View responsible for rendering the visual layout and content of the candle tooltip, utilizing the new ViewModels.
  • Features/Perpetuals/Sources/Views/CandlestickChartView.swift
    • Imported the Components module to access shared UI components.
    • Updated the selectedCandle state variable to directly store ChartCandleStick objects, simplifying data handling.
    • Modified the chart's drag gesture to correctly identify and store the selected ChartCandleStick.
    • Integrated a new tooltipOverlay function to display the CandleTooltipView when a candle is selected.
    • Refactored the color determination for current price and candlestick marks to use a consistent PriceChangeColor.color(for:) utility.
    • Adjusted selectionMarks to directly use properties of the selectedCandle for drawing selection indicators.
    • Introduced selectedPriceModel and a helper priceModel function to generate ChartPriceViewModel instances based on selected or current candles.
    • Implemented dynamic positioning logic for the tooltip to prevent it from going off-screen.
  • Features/Perpetuals/Sources/Views/RangeBarView.swift
    • Added a new SwiftUI View to visually represent the low/high price range of a candle, including a movable indicator for the close price.
Activity
  • No specific review comments or activities have been recorded for this pull request yet, beyond its initial creation by gemdev111.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a floating tooltip for the perpetual chart, displaying Open, Close, Low/High range, and Volume when a candle is tapped. This is a great feature for enhancing user experience by providing detailed information on demand. The refactoring to use ChartCandleStick directly for selectedCandle and deriving ChartPriceViewModel via selectedPriceModel is a good separation of concerns. Additionally, the use of PriceChangeColor.color for consistent color application is a positive change. However, there are a few areas for improvement regarding consistency in style definitions and a critical layout issue with the tooltip's padding that could cause it to go off-screen.

Comment on lines +248 to +251
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: isRightHalf ? .topLeading : .topTrailing)
.padding(.leading, Spacing.small)
.padding(.top, Spacing.small)
.padding(.trailing, Spacing.extraLarge + Spacing.medium)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The padding applied to the CandleTooltipView is unconditional. Specifically, padding(.trailing, Spacing.extraLarge + Spacing.medium) is applied even when the tooltip is aligned to the trailing edge (isRightHalf is false). This will cause the tooltip to be pushed off-screen to the right, leading to a poor user experience. The padding should be conditional based on the isRightHalf flag to ensure the tooltip remains within the visible chart bounds.

Consider applying leading padding when isRightHalf is false (aligned trailing) and trailing padding when isRightHalf is true (aligned leading).

Suggested change
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: isRightHalf ? .topLeading : .topTrailing)
.padding(.leading, Spacing.small)
.padding(.top, Spacing.small)
.padding(.trailing, Spacing.extraLarge + Spacing.medium)
CandleTooltipView(model: CandleTooltipViewModel(candle: candle, formatter: formatter))
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: isRightHalf ? .topLeading : .topTrailing)
.padding(.top, Spacing.small)
.padding(isRightHalf ? .leading : .trailing, Spacing.small)
.padding(isRightHalf ? .trailing : .leading, Spacing.extraLarge + Spacing.medium)
.transition(.opacity)


private let candle: ChartCandleStick
private let formatter: CurrencyFormatter
private static let volumeFormatter = CurrencyFormatter(type: .abbreviated, currencyCode: Currency.usd.rawValue)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The currencyCode for volumeFormatter is hardcoded to Currency.usd.rawValue. While rawValue provides the string, it's still a specific currency. If the application is intended to support multiple currencies, this should ideally be dynamic or configurable rather than hardcoded to USD, to prevent potential inconsistencies or future maintenance issues if other currencies need to be displayed for volume.

Comment on lines +47 to +48
highTitle: TextValue(text: "High", style: TextStyle(font: .system(size: .space8), color: Colors.green, fontWeight: .medium)),
lowValue: TextValue(text: formatter.string(double: candle.low), style: StyleDefaults.rangePrice),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The TextStyle for lowTitle and highTitle is defined inline here. For consistency and better maintainability, it would be beneficial to define these styles within the StyleDefaults struct, similar to label, value, small, and rangePrice. This centralizes style definitions and makes them easier to manage and update across the application.

Suggested change
highTitle: TextValue(text: "High", style: TextStyle(font: .system(size: .space8), color: Colors.green, fontWeight: .medium)),
lowValue: TextValue(text: formatter.string(double: candle.low), style: StyleDefaults.rangePrice),
lowTitle: TextValue(text: "Low", style: StyleDefaults.lowTitle),
highTitle: TextValue(text: "High", style: StyleDefaults.highTitle),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show more information when you tap and hold on candle

1 participant