Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/components/OgImage/Package.takumi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const KIND_ICONS: Record<string, string> = {
<script setup lang="ts">
import type { JsDelivrFileNode } from '#shared/types'
import { joinURL } from 'ufo'
import { smoothPath, useCharts } from '~/composables/useCharts'
import { useCharts } from '~/composables/useCharts'
import { createSmoothPath as smoothPath } from 'vue-data-ui/utils'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
import { createSmoothPath as smoothPath } from 'vue-data-ui/utils'
import { createSmoothPath } from 'vue-data-ui/utils'

nit: It seems that the usage of this fuction is only here in the project (https://github.com/npmx-dev/npmx.dev/pull/2647/changes#diff-989803a8350f5b506a5bdea17a1237c410d7eee66b2e7015b0bd46378a78e097R243)
Maybe we could refactor to use the original exported name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@shuuji3 thank you :) It is cleaner indeed


const REPO_PROVIDER_ICONS: Record<string, string> = {
github: 'i-simple-icons:github',
Expand Down
40 changes: 0 additions & 40 deletions app/composables/useCharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,46 +66,6 @@ function mergeDailyPoints(points: DailyRawPoint[]): DailyRawPoint[] {
.map(([day, value]) => ({ day, value }))
}

function roundToHundredths(value: number): number {
return Math.round(value * 100) / 100
}

/** Catmull-Rom monotone cubic spline — same algorithm as vue-data-ui's smoothPath for OG Images */
export function smoothPath(pts: { x: number; y: number }[]): string {
if (pts.length < 2) return '0,0'
const n = pts.length - 1
const out = [`${roundToHundredths(pts[0]!.x)},${roundToHundredths(pts[0]!.y)}`]
const dx: number[] = []
const dy: number[] = []
const m: number[] = []
const t: number[] = []

for (let i = 0; i < n; i++) {
dx[i] = pts[i + 1]!.x - pts[i]!.x
dy[i] = pts[i + 1]!.y - pts[i]!.y
m[i] = dx[i] === 0 ? 0 : dy[i]! / dx[i]!
}

t[0] = m[0]!
t[n] = m[n - 1]!
for (let i = 1; i < n; i++) {
t[i] = m[i - 1]! * m[i]! <= 0 ? 0 : (2 * m[i - 1]! * m[i]!) / (m[i - 1]! + m[i]!)
}

for (let i = 0; i < n; i++) {
const x0 = pts[i]!.x,
y0 = pts[i]!.y
const x1 = pts[i + 1]!.x,
y1 = pts[i + 1]!.y
const seg = x1 - x0
out.push(
`C ${roundToHundredths(x0 + seg / 3)},${roundToHundredths(y0 + (t[i]! * seg) / 3)} ${roundToHundredths(x1 - seg / 3)},${roundToHundredths(y1 - (t[i + 1]! * seg) / 3)} ${roundToHundredths(x1)},${roundToHundredths(y1)}`,
)
}

return out.join(' ')
}

const npmDailyRangeCache = import.meta.client ? new Map<string, Promise<DailyRawPoint[]>>() : null
const likesEvolutionCache = import.meta.client ? new Map<string, Promise<DailyRawPoint[]>>() : null
const contributorsEvolutionCache = import.meta.client
Expand Down
1 change: 0 additions & 1 deletion test/nuxt/components/OgImagePackage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ vi.mock('~/composables/useCharts', () => ({
useCharts: vi.fn().mockReturnValue({
fetchPackageDownloadEvolution: mockFetchPackageDownloadEvolution,
}),
smoothPath: vi.fn().mockReturnValue(''),
}))

import OgImagePackage from '~/components/OgImage/Package.takumi.vue'
Expand Down
Loading