Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lightweight chart lib #3279

Merged
merged 11 commits into from
May 30, 2024
Merged

Conversation

DavideSegullo
Copy link
Collaborator

@DavideSegullo DavideSegullo commented May 25, 2024

What is the purpose of the change:

This PR implements the lightweight charts library which allows us to fix some bugs, but also introduces some features:

  • Mobile gesture support
  • Better chart rendering, now we use html canvas instead of svg
  • Right now is disabled, but we can also use zoom functionality inside the chart
  • Support for candles charts

Right now we're only using this implementation for the token info pages, we can replace chart in other places but I'll do it in a different PR.

Linear Tasks

Fix Chart Rendering
Switch to lightweight charts library

Brief Changelog

Testing and Verifying

Copy link

vercel bot commented May 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
osmosis-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2024 8:53pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
osmosis-frontend-dev ⬜️ Ignored (Inspect) Visit Preview May 30, 2024 8:53pm
osmosis-frontend-edgenet ⬜️ Ignored (Inspect) May 30, 2024 8:53pm
osmosis-testnet ⬜️ Ignored (Inspect) Visit Preview May 30, 2024 8:53pm

Copy link
Contributor

coderabbitai bot commented May 29, 2024

Walkthrough

The updates introduce new chart controllers for different chart types (area and line) using the Lightweight Charts library. A React component, HistoricalPriceChartV2, is added to render historical price data. The ChartController class is enhanced to manage chart events and options. The TokenChart component is updated to use the new HistoricalPriceChartV2.

Changes

File Path Change Summary
.../area-chart.ts Added AreaChartController class for managing area chart series.
.../chart-controller.ts Introduced ChartController class with methods for chart management and event handling.
.../chart.tsx Added Chart React component for rendering customizable time-based charts.
.../line-chart.ts Added LineChartController class for managing line chart series.
.../linear-chart.ts Added LinearChartController class extending AreaChartController for tooltip management.
.../price-historical-v2.tsx Added HistoricalPriceChartV2 component for rendering historical price data.
.../assets/[denom].tsx Replaced HistoricalPriceChart with HistoricalPriceChartV2 in TokenChart component.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant TokenChart
    participant HistoricalPriceChartV2
    participant AreaChartController
    participant LineChartController

    User->>TokenChart: Load page
    TokenChart->>HistoricalPriceChartV2: Render chart with data
    HistoricalPriceChartV2->>AreaChartController: Initialize area chart
    HistoricalPriceChartV2->>LineChartController: Initialize line chart
    AreaChartController->>HistoricalPriceChartV2: Return chart instance
    LineChartController->>HistoricalPriceChartV2: Return chart instance
    HistoricalPriceChartV2->>TokenChart: Display chart
Loading

Poem

In the realm of charts, a tale unfolds,
Of lines and areas, their stories told.
Controllers guide with options vast,
Historical prices, a view so fast.
A rabbit cheers with joy and glee,
For charts that dance in harmony.
📈🌟


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 039a8dc and f977a25.

Files selected for processing (2)
  • packages/web/components/chart/light-weight-charts/chart-controller.ts (1 hunks)
  • packages/web/components/chart/light-weight-charts/chart.tsx (1 hunks)
Additional context used
Biome
packages/web/components/chart/light-weight-charts/chart-controller.ts

[error] 1-11: Some named imports are only used as types.

packages/web/components/chart/light-weight-charts/chart.tsx

[error] 1-10: Some named imports are only used as types.


[error] 10-18: Some named imports are only used as types.


[error] 21-26: All these imports are only used as types.

Additional comments not posted (2)
packages/web/components/chart/light-weight-charts/chart-controller.ts (1)

32-84: The ChartController class is well-structured and encapsulates the functionality needed for chart management effectively. However, consider adding error handling for operations that interact with external APIs or DOM elements.

packages/web/components/chart/light-weight-charts/chart.tsx (1)

163-214: The Chart component is correctly using React hooks for lifecycle management and state handling. Ensure that the component's dependencies are correctly listed in the useEffect hooks to avoid unnecessary re-renders or stale data issues.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DavideSegullo DavideSegullo changed the title feat: add new charts feat: add lightweight chart lib May 29, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (4)
packages/web/pages/assets/[denom].tsx (4)

Line range hint 444-444: Avoid non-null assertion.

Using non-null assertions can lead to runtime errors if the value turns out to be null. Consider adding null checks or using optional chaining.


Line range hint 603-603: Simplify the computed expression.

Consider simplifying this expression to improve readability and potentially enhance performance.


Line range hint 1-13: Use import type for type-only imports.

To clarify that these imports are used only for type checking and to potentially optimize bundling, consider using import type { TypeName } from 'module-name'; for these imports.

Also applies to: 15-16, 20-21, 42-49


Line range hint 577-577: Use const for variables that are only assigned once.

This variable is only assigned once and does not change, making it a candidate for const to ensure immutability and clarity in the code.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
packages/web/components/chart/light-weight-charts/chart.tsx (1)

36-66: The timepointToString function is a utility for formatting time points. It's well-implemented but consider adding comments to clarify the logic, especially around the handling of different time formats.

@DavideSegullo DavideSegullo merged commit 2fa9cb5 into stage May 30, 2024
26 of 27 checks passed
@DavideSegullo DavideSegullo deleted the DavideSegullo/feat-charts branch May 30, 2024 20:54
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.

4 participants