docs: Add technical design and implementation evaluation for AssetTrendChart#47
Conversation
Created a comprehensive technical design and implementation evaluation report for the AssetTrendChart enhancements. The report details the data flow architecture, interactive canvas implementation using pointerInput, benchmark comparison approach, and a phased rollout plan. Authored in Traditional Chinese (zh-TW) as requested. Co-authored-by: Max97k <14903047+Max97k@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request adds a technical evaluation and implementation plan for enhancing the AssetTrendChart, covering data flow, interactive Canvas gestures, benchmark normalization, and a milestone-based roadmap. The review feedback provides valuable technical improvements: recommending a normalized Room database schema instead of storing serialized lists to optimize caching, suggesting detectHorizontalDragGestures instead of detectDragGestures to prevent blocking vertical scrolling in parent containers, and pointing out a potential division-by-zero bug in the normalization formula when the initial asset value is zero.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| * **5Y/MAX**: 考慮使用週K或月K資料(1wk, 1mo interval)以減少資料量並提升繪製效能。 | ||
|
|
||
| 3. **快取機制優化**: | ||
| 目前的 `historicalDataCache` 是儲存了 2Y 的 1d 資料。未來需將 Cache 結構升級,支援 `(Symbol, Interval) -> List<Pair<Long, Double>>`。可以利用 Room 資料庫進行持久化快取,減少每次啟動時的網路請求。針對分K資料,由於時效性高,可保留在 Memory Cache (如 `MutableStateFlow`)。 |
There was a problem hiding this comment.
When designing the Room database schema for caching historical prices, storing a serialized list of pairs mapped by (Symbol, Interval) as a single row can make querying, updating, or partially clearing the cache difficult.
Instead, it is highly recommended to design a normalized database table where each historical data point is a separate row. This allows leveraging SQL queries for filtering by date ranges, updating specific points, and automatic cleanup of old data.
| 目前的 `historicalDataCache` 是儲存了 2Y 的 1d 資料。未來需將 Cache 結構升級,支援 `(Symbol, Interval) -> List<Pair<Long, Double>>`。可以利用 Room 資料庫進行持久化快取,減少每次啟動時的網路請求。針對分K資料,由於時效性高,可保留在 Memory Cache (如 `MutableStateFlow`)。 | |
| 目前的 `historicalDataCache` 是儲存了 2Y 的 1d 資料。未來需將 Cache 結構升級,在 Room 資料庫中設計一個正規化的資料表(以 `symbol`、`interval` 與 `timestamp` 作為複合主鍵),以支援高效的區間查詢與單點更新,避免直接序列化儲存整個 List。針對分K資料,由於時效性高,可保留在 Memory Cache (如 `MutableStateFlow`)。 |
| detectDragGestures( | ||
| onDragStart = { offset -> /* 計算 selectedIndex */ }, | ||
| onDrag = { change, _ -> | ||
| val x = change.position.x | ||
| /* 根據 X 座標找出最近的資料點更新 selectedIndex */ | ||
| }, | ||
| onDragEnd = { selectedIndex = null }, | ||
| onDragCancel = { selectedIndex = null } | ||
| ) |
There was a problem hiding this comment.
Using detectDragGestures will intercept and consume drag gestures in all directions (both horizontal and vertical). If the chart is placed inside a scrollable container (such as a LazyColumn or a scrollable Column), this will prevent the user from scrolling the page when dragging vertically over the chart area.
Since the interactive cursor only tracks horizontal movement (the X coordinate) to select the data point, it is highly recommended to use detectHorizontalDragGestures instead. This ensures vertical scroll gestures are correctly propagated to parent scrollable containers, providing a much smoother user experience.
| detectDragGestures( | |
| onDragStart = { offset -> /* 計算 selectedIndex */ }, | |
| onDrag = { change, _ -> | |
| val x = change.position.x | |
| /* 根據 X 座標找出最近的資料點更新 selectedIndex */ | |
| }, | |
| onDragEnd = { selectedIndex = null }, | |
| onDragCancel = { selectedIndex = null } | |
| ) | |
| detectHorizontalDragGestures( | |
| onDragStart = { offset -> /* 計算 selectedIndex */ }, | |
| onHorizontalDrag = { change, _ -> | |
| val x = change.position.x | |
| /* 根據 X 座標找出最近的資料點更新 selectedIndex */ | |
| }, | |
| onDragEnd = { selectedIndex = null }, | |
| onDragCancel = { selectedIndex = null } | |
| ) |
|
|
||
| 2. **基期歸一化 (Normalization)**: | ||
| 將選定時間區間的**第一個資料點**作為基準點(0% 或 100%)。 | ||
| 計算公式:`NormalizedValue(t) = (Value(t) / Value(t_0)) - 1.0` (得出如 +0.05 代表 5%)。 |
There was a problem hiding this comment.
The normalization formula NormalizedValue(t) = (Value(t) / Value(t_0)) - 1.0 assumes that Value(t_0) (the value at the start of the selected time range) is always non-zero.
However, in real-world scenarios, Value(t_0) can be zero (e.g., if the user had no assets at that time, or if there is a temporary data anomaly/missing price). If Value(t_0) == 0, this formula will result in a division by zero, leading to NaN or Infinity values, which will crash the Canvas rendering or result in an empty chart.
Please update the design to explicitly handle the case where Value(t_0) == 0 (e.g., fallback to 0.0 or use a small epsilon/alternative baseline).
| 計算公式:`NormalizedValue(t) = (Value(t) / Value(t_0)) - 1.0` (得出如 +0.05 代表 5%)。 | |
| 計算公式:`NormalizedValue(t) = if (Value(t_0) != 0.0) (Value(t) / Value(t_0)) - 1.0 else 0.0` (需特別處理 `Value(t_0) == 0` 的邊界情況,避免除以零導致 `NaN` 或 `Infinity` 造成圖表繪製崩潰)。 |
This PR introduces the technical evaluation document for enhancing the AssetTrendChart functionality in the
money2project. The requested file,docs/asset_chart_implementation_evaluation.md, contains a detailed assessment covering:pointerInput.The report is written in Traditional Chinese (zh-TW).
PR created automatically by Jules for task 12783142609625590144 started by @Max97k