Skip to content

DevOverlayの精度履歴をreact-native-svgの折れ線グラフで再実装 - #6125

Merged
TinyKitten merged 1 commit into
devfrom
claude/devoverlay-accuracy-graph-J0PY0
Jun 4, 2026
Merged

TinyKitten merged 1 commit into
devfrom
claude/devoverlay-accuracy-graph-J0PY0

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

概要

DevOverlay の精度履歴表示を、ASCII ブロック文字(▇▆▅▄▃▂▁)による擬似バーから react-native-svg ベースの折れ線グラフに再実装した。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • src/components/AccuracyHistoryChart.tsx を新規追加し、react-native-svg の Svg / Line / Circle で精度履歴を折れ線グラフ描画。値が大きい(=精度が悪い)サンプルほど上端側に配置する。
  • 精度帯ごとに線・点を色分け(良好=#38bdf8 / 警告=#facc15 / 超過=#f87171、DevOverlay のメトリクスカード配色と統一)。線分は両端のうち精度が悪い側の色で塗り、悪化区間を強調する。
  • 有効サンプルが無い場合は --- プレースホルダー、1 サンプルのみの場合は中央に 1 点を表示する。
  • src/utils/accuracyChart.ts の generateAccuracyChart(ブロック文字生成)を、描画サイズ非依存の正規化済み点列を返す buildAccuracyChartSeries に置き換え、色定数 ACCURACY_CHART_COLORS を公開。
  • src/components/DevOverlay.tsx の縦・横レイアウト双方のチャート描画を AccuracyHistoryChart に差し替え、不要になった Text import・generateAccuracyChart・chartValue 系スタイルを削除。
  • 関連テストを更新・追加(accuracyChart.test.ts を新 API 向けに刷新、AccuracyHistoryChart.test.tsx を新規追加、DevOverlay.test.tsx のチャート系アサーションを描画点数ベースへ更新)。

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

スクリーンショット(任意)


Generated by Claude Code

Summary by CodeRabbit

リリースノート

  • 新機能

    • 精度履歴をテキストベースから折れ線グラフ形式に変更。各データポイントを視覚的に表示し、精度の良悪を色分けで表現します。
  • テスト

    • 新しい精度チャート表示形式に対応するテストを追加・更新しました。

@github-actions github-actions Bot added the react label Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

精度履歴表示をASCII文字ベースから SVG 折れ線グラフへ移行します。ユーティリティ層で点系列データ型と閾値ベースの色判定を新規実装し、新しい React Native コンポーネント AccuracyHistoryChart でグラフをレンダリング、DevOverlay に統合することで視覚的な精度トレンド表示を実現します。

Changes

精度チャート表示の完全移行

Layer / File(s) Summary
精度チャート基盤ロジック:点系列と色判定
src/utils/accuracyChart.ts, src/utils/accuracyChart.test.ts
AccuracyChartPoint 型を新規導入し、buildAccuracyChartSeries で NaN/Infinity/負値を除外したうえで min/max から正規化値を計算します。ACCURACY_CHART_COLORS 定数と getAccuracyColor 関数で閾値ベースの色判定(good/warning/danger)をエクスポート化し、対応テストで点系列の正規化・色判定の各ケースを検証します。
AccuracyHistoryChart コンポーネント:SVG グラフレンダリング
src/components/AccuracyHistoryChart.tsx, src/components/AccuracyHistoryChart.test.tsx
新規 React Native コンポーネントで点系列を SVG 座標に変換し、等間隔 X 軸と正規化値 Y 軸マッピングを実装、点が存在する場合は折れ線と円を描画、空の場合はプレースホルダ(---)を表示、testID を付与してテスト可能にします。
DevOverlay の統合と更新
src/components/DevOverlay.tsx, src/components/DevOverlay.test.tsx
古い generateAccuracyChart + テキスト描画から AccuracyHistoryChart コンポーネントへ置き換え、関連 import を削除・追加、useMemo ロジックを削除、風景・縦向きレイアウト両方で layout サイズ計算を更新し、テストで精度ポイント個数の検証へ切り替えます。

Sequence Diagram

sequenceDiagram
  participant DevOverlay as DevOverlay
  participant buildAccuracyChartSeries as buildAccuracyChartSeries
  participant getAccuracyColor as getAccuracyColor
  participant ACCURACY_CHART_COLORS as ACCURACY_CHART_COLORS
  participant AccuracyHistoryChart as AccuracyHistoryChart
  participant SVGRenderer as SVGRenderer

  DevOverlay->>AccuracyHistoryChart: 精度履歴 + width/height を渡す
  AccuracyHistoryChart->>buildAccuracyChartSeries: 精度履歴配列を渡す
  buildAccuracyChartSeries->>buildAccuracyChartSeries: NaN/Infinity/負値をフィルタリング
  buildAccuracyChartSeries->>buildAccuracyChartSeries: min/max から正規化値を計算
  loop 各点ごと
    buildAccuracyChartSeries->>getAccuracyColor: 正規化値で色を決定
    getAccuracyColor->>ACCURACY_CHART_COLORS: 閾値に基づいて色種別を選択
    ACCURACY_CHART_COLORS-->>getAccuracyColor: good/warning/danger 色HEXを返す
    getAccuracyColor-->>buildAccuracyChartSeries: 点カラーが決定
  end
  buildAccuracyChartSeries-->>AccuracyHistoryChart: AccuracyChartPoint[] を返す
  alt 点列が存在
    AccuracyHistoryChart->>AccuracyHistoryChart: SVG座標計算(x: 等間隔、y: 正規化値)
    AccuracyHistoryChart->>SVGRenderer: 折れ線 + 円を描画
  else 点列が空
    AccuracyHistoryChart->>SVGRenderer: プレースホルダ(---)を描画
  end
  SVGRenderer-->>DevOverlay: レンダリング完了
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6113: src/utils/accuracyChart.ts の getAccuracyColor 関数を精度閾値ベースの色分岐として実装する部分が両 PR で同系統に更新されており、コードレベルで関連します。
  • TrainLCD/MobileApp#5982: DevOverlay.tsx の精度履歴チャート周りのサンプリングデータと描画処理を変更するもので、同コンポーネントの精度チャート実装・テスト期待値に直結します。
  • TrainLCD/MobileApp#6116: MAX_PERMIT_ACCURACY 変更に伴う色判定テスト更新が、main PR の src/utils/accuracyChart における精度→色(good/warning/danger)ロジックの閾値・色分岐と同じ領域を扱うため関連します。

Suggested labels

react

Poem

📊 折れ線で精度の道を描き出す
古き ASCII から SVG の世界へ
点ごとに色分け、閾値で判定
グラフが語る、精度の物語よ
🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PRタイトルはDevOverlay の精度履歴表示を ASCII ブロック文字から react-native-svg の折れ線グラフに置き換えるという主要な変更を明確かつ簡潔に記述しており、変更内容を正確に反映している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed PRの説明は必須セクション(概要、変更内容、テスト実施状況)が完備され、具体的で詳細な技術情報を含んでいます。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/devoverlay-accuracy-graph-J0PY0

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


Comment @coderabbitai help to get the list of available commands and usage tips.

@TinyKitten TinyKitten self-assigned this Jun 4, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/utils/accuracyChart.test.ts (1)

7-131: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

afterEach で jest.clearAllMocks() を追加してください。

このテストファイルに afterEach が無く、モック状態の持ち越しを防ぐ統一ルールに未準拠です。

As per coding guidelines **/*.test.{ts,tsx}: テストの afterEach で jest.clearAllMocks() を呼び出してください。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/accuracyChart.test.ts` around lines 7 - 131, Add a global afterEach
hook to this test file that calls jest.clearAllMocks() to prevent mock state
leakage between tests; place it at top-level (outside the describe blocks) in
the file that contains the describe('buildAccuracyChartSeries'...) and
describe('getAccuracyColor'...) suites so all tests (including those exercising
buildAccuracyChartSeries and getAccuracyColor) run with cleared mocks after each
spec.
🧹 Nitpick comments (1)
src/utils/accuracyChart.test.ts (1)

119-129: ⚡ Quick win

閾値境界テストの固定値は定数参照に置き換えると安全です。

Line 120, Line 124, Line 128 の 2000/200/199 は、MAX_PERMIT_ACCURACY / BAD_ACCURACY_THRESHOLD を直接使う方が将来の閾値変更に追従できます。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/accuracyChart.test.ts` around lines 119 - 129, Replace hard-coded
numeric literals in the tests with the corresponding constants so they follow
future threshold changes: update the assertions in tests referencing
getAccuracyColor and ACCURACY_CHART_COLORS to use MAX_PERMIT_ACCURACY instead of
2000, BAD_ACCURACY_THRESHOLD instead of 200 for the boundary case, and
BAD_ACCURACY_THRESHOLD - 1 instead of 199 for the just-below-boundary case; this
ensures tests remain correct when MAX_PERMIT_ACCURACY or BAD_ACCURACY_THRESHOLD
values change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/AccuracyHistoryChart.test.tsx`:
- Around line 6-87: Add an afterEach hook that calls jest.clearAllMocks() in the
AccuracyHistoryChart test suite: inside the describe('AccuracyHistoryChart',
...) block add afterEach(() => { jest.clearAllMocks(); }) so all mocks are reset
between tests (ensures tests using getAllByTestId / processColor /
ACCURACY_CHART_COLORS are not affected by prior mock state).

---

Outside diff comments:
In `@src/utils/accuracyChart.test.ts`:
- Around line 7-131: Add a global afterEach hook to this test file that calls
jest.clearAllMocks() to prevent mock state leakage between tests; place it at
top-level (outside the describe blocks) in the file that contains the
describe('buildAccuracyChartSeries'...) and describe('getAccuracyColor'...)
suites so all tests (including those exercising buildAccuracyChartSeries and
getAccuracyColor) run with cleared mocks after each spec.

---

Nitpick comments:
In `@src/utils/accuracyChart.test.ts`:
- Around line 119-129: Replace hard-coded numeric literals in the tests with the
corresponding constants so they follow future threshold changes: update the
assertions in tests referencing getAccuracyColor and ACCURACY_CHART_COLORS to
use MAX_PERMIT_ACCURACY instead of 2000, BAD_ACCURACY_THRESHOLD instead of 200
for the boundary case, and BAD_ACCURACY_THRESHOLD - 1 instead of 199 for the
just-below-boundary case; this ensures tests remain correct when
MAX_PERMIT_ACCURACY or BAD_ACCURACY_THRESHOLD values change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f5c18256-69e6-4d59-92c8-dc0c50147036

📥 Commits

Reviewing files that changed from the base of the PR and between e402499 and 8976cdd.

📒 Files selected for processing (6)
  • src/components/AccuracyHistoryChart.test.tsx
  • src/components/AccuracyHistoryChart.tsx
  • src/components/DevOverlay.test.tsx
  • src/components/DevOverlay.tsx
  • src/utils/accuracyChart.test.ts
  • src/utils/accuracyChart.ts

@TinyKitten
TinyKitten merged commit 93095a0 into dev Jun 4, 2026
6 checks passed
@TinyKitten
TinyKitten deleted the claude/devoverlay-accuracy-graph-J0PY0 branch June 4, 2026 11:24
@TinyKitten TinyKitten mentioned this pull request Jun 4, 2026
4 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants