Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

refactor: Move vendor files to proper vendor folder (#63861)

Rafael Audibertf75020d48d4a
diff --git a/frontend/src/lib/d3/utils.ts b/frontend/src/lib/d3/utils.ts
deleted file mode 100644
index 1afa8405b026..000000000000
--- a/frontend/src/lib/d3/utils.ts
+++ /dev/null
@@ -1,74 +0,0 @@
-import * as d3 from 'd3'
-
-import { D3Selector, D3Transition } from 'lib/hooks/useD3'
-// eslint-disable-next-line import/no-cycle
-import { INITIAL_CONFIG } from 'scenes/insights/views/Histogram/histogramUtils'
-
-export const getOrCreateEl = (
- container: D3Selector,
- selector: string,
- createCallback: () => D3Selector
-): D3Selector => {
- const el = container.select(selector)
- if (el.empty()) {
- return createCallback()
- }
- return el
-}
-
-export const animate = (
- it: D3Selector,
- transitionDuration: number,
- isAnimated: boolean,
- toAnimate: (_it: D3Transition | D3Selector) => D3Transition | D3Selector = (_it) => _it // everything you want to animate goes here
-): D3Transition | D3Selector => {
- if (isAnimated) {
- return it.transition().duration(transitionDuration).call(toAnimate)
- }
- return it.call(toAnimate)
-}
-
-export const wrap = (
- text: D3Selector,
- width: number,
- lineHeight: number = INITIAL_CONFIG.spacing.labelLineHeight,
- isVertical: boolean = true,
- dx: number = INITIAL_CONFIG.spacing.xLabel
-): D3Selector => {
- const maxWidth = width - 6 // same as padding-{left|right}: 3px;
- text.each(function () {
- const _text = d3.select(this)
- const words: string[] = _text.text().split(/\s+/)
- const y = _text.attr('y'),
- dy = parseFloat(_text.attr('dy'))
-
- let line: string[] = [],
- lineNumber = 0,
- tspan = _text
- .text(null)
- .append('tspan')
- .attr('x', 0)
- .attr('y', y)
- .attr('dx', isVertical ? 0 : -dx + 'px')
- .attr('dy', dy + 'em')
-
- words.forEach((word) => {
- // try appending text. revert and break onto new line if it's just too long
- line.push(word)
- tspan.text(line.join(' '))
- if ((tspan.node()?.getComputedTextLength() || 0) > maxWidth) {
- line.pop()
- tspan.text(line.join(' '))
- line = [word]
- tspan = _text
- .append('tspan')
- .attr('x', 0)
- .attr('y', y)
- .attr('dx', isVertical ? 0 : -dx + 'px')
- .attr('dy', ++lineNumber * lineHeight + dy + 'em')
- .text(word)
- }
- })
- })
- return text
-}
diff --git a/frontend/src/lib/utils/time-tree.ts b/frontend/src/lib/utils/time-tree.ts
index f11e85580638..4e4a86db2309 100644
--- a/frontend/src/lib/utils/time-tree.ts
+++ b/frontend/src/lib/utils/time-tree.ts
@@ -1,5 +1,6 @@
import { Dayjs } from 'lib/dayjs'
-import { RBTree } from 'lib/utils/vendor/bintrees'
+
+import { RBTree } from '~/vendor/bintrees'
export type TimeTreeComparable = {
timestamp: Dayjs
diff --git a/frontend/src/scenes/insights/views/Histogram/Histogram.tsx b/frontend/src/scenes/insights/views/Histogram/Histogram.tsx
index c9153ce93bd8..86de3af9c554 100644
--- a/frontend/src/scenes/insights/views/Histogram/Histogram.tsx
+++ b/frontend/src/scenes/insights/views/Histogram/Histogram.tsx
@@ -5,23 +5,21 @@ import { useActions, useValues } from 'kea'
import { useEffect } from 'react'
import { FunnelLayout } from 'lib/constants'
-// eslint-disable-next-line import/no-cycle
-import { animate, getOrCreateEl, wrap } from 'lib/d3/utils'
import { D3Selector, D3Transition, useD3 } from 'lib/hooks/useD3'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
-// eslint-disable-next-line import/no-cycle
import { histogramLogic } from 'scenes/insights/views/Histogram/histogramLogic'
-import { D3HistogramDatum, INITIAL_CONFIG, createRoundedRectPath, getConfig } from './histogramUtils'
-
-export interface HistogramDatum {
- id: string | number
- bin0: number
- bin1: number
- count: number
- label: string | number
-}
+import {
+ D3HistogramDatum,
+ INITIAL_CONFIG,
+ createRoundedRectPath,
+ getConfig,
+ animate,
+ getOrCreateEl,
+ wrap,
+} from './histogramUtils'
+import { HistogramDatum } from './types'
interface HistogramProps {
data: HistogramDatum[]
diff --git a/frontend/src/scenes/insights/views/Histogram/histogramUtils.ts b/frontend/src/scenes/insights/views/Histogram/histogramUtils.ts
index 16ea04e04960..b80f00190e65 100644
--- a/frontend/src/scenes/insights/views/Histogram/histogramUtils.ts
+++ b/frontend/src/scenes/insights/views/Histogram/histogramUtils.ts
@@ -1,8 +1,15 @@
import * as d3 from 'd3'
import { FunnelLayout } from 'lib/constants'
-// eslint-disable-next-line import/no-cycle
-import { HistogramDatum } from 'scenes/insights/views/Histogram/Histogram'
+import { D3Selector, D3Transition } from 'lib/hooks/useD3'
+
+import { HistogramDatum } from './types'
+
+export interface D3HistogramDatum extends HistogramDatum {
+ labelWidth?: number
+ labelHeight?: number
+ shouldShowInBar?: boolean
+}
export interface HistogramConfig {
layout: FunnelLayout
@@ -160,8 +167,71 @@ export const createRoundedRectPath = (
)
}
-export interface D3HistogramDatum extends HistogramDatum {
- labelWidth?: number
- labelHeight?: number
- shouldShowInBar?: boolean
+export const getOrCreateEl = (
+ container: D3Selector,
+ selector: string,
+ createCallback: () => D3Selector
+): D3Selector => {
+ const el = container.select(selector)
+ if (el.empty()) {
+ return createCallback()
+ }
+ return el
+}
+
+export const animate = (
+ it: D3Selector,
+ transitionDuration: number,
+ isAnimated: boolean,
+ toAnimate: (_it: D3Transition | D3Selector) => D3Transition | D3Selector = (_it) => _it // everything you want to animate goes here
+): D3Transition | D3Selector => {
+ if (isAnimated) {
+ return it.transition().duration(transitionDuration).call(toAnimate)
+ }
+ return it.call(toAnimate)
+}
+
+export const wrap = (
+ text: D3Selector,
+ width: number,
+ lineHeight: number = INITIAL_CONFIG.spacing.labelLineHeight,
+ isVertical: boolean = true,
+ dx: number = INITIAL_CONFIG.spacing.xLabel
+): D3Selector => {
+ const maxWidth = width - 6 // same as padding-{left|right}: 3px;
+ text.each(function () {
+ const _text = d3.select(this)
+ const words: string[] = _text.text().split(/\s+/)
+ const y = _text.attr('y'),
+ dy = parseFloat(_text.attr('dy'))
+
+ let line: string[] = [],
+ lineNumber = 0,
+ tspan = _text
+ .text(null)
+ .append('tspan')
+ .attr('x', 0)
+ .attr('y', y)
+ .attr('dx', isVertical ? 0 : -dx + 'px')
+ .attr('dy', dy + 'em')
+
+ words.forEach((word) => {
+ // try appending text. revert and break onto new line if it's just too long
+ line.push(word)
+ tspan.text(line.join(' '))
+ if ((tspan.node()?.getComputedTextLength() || 0) > maxWidth) {
+ line.pop()
+ tspan.text(line.join(' '))
+ line = [word]
+ tspan = _text
+ .append('tspan')
+ .attr('x', 0)
+ .attr('y', y)
+ .attr('dx', isVertical ? 0 : -dx + 'px')
+ .attr('dy', ++lineNumber * lineHeight + dy + 'em')
+ .text(word)
+ }
+ })
+ })
+ return text
}
diff --git a/frontend/src/scenes/insights/views/Histogram/types.ts b/frontend/src/scenes/insights/views/Histogram/types.ts
new file mode 100644
index 000000000000..2d41b8afcd9f
--- /dev/null
+++ b/frontend/src/scenes/insights/views/Histogram/types.ts
@@ -0,0 +1,7 @@
+export interface HistogramDatum {
+ id: string | number
+ bin0: number
+ bin1: number
+ count: number
+ label: string | number
+}
diff --git a/frontend/src/scenes/paths-v2/renderPaths.ts b/frontend/src/scenes/paths-v2/renderPaths.ts
index 28cbf6dc8c12..d903b586e25b 100644
--- a/frontend/src/scenes/paths-v2/renderPaths.ts
+++ b/frontend/src/scenes/paths-v2/renderPaths.ts
@@ -1,10 +1,10 @@
import * as d3 from 'd3'
import { Dispatch, RefObject, SetStateAction } from 'react'
-import sankey, { sankeyLeft, sankeyLinkHorizontal, SankeyLink, type SankeyLayout } from 'lib/d3/sankey'
import { D3Selector } from 'lib/hooks/useD3'
import { FunnelPathsFilter, PathsFilter } from '~/queries/schema/schema-general'
+import sankey, { sankeyLeft, sankeyLinkHorizontal, SankeyLink, type SankeyLayout } from '~/vendor/d3/sankey'
import { PathNodeData, PathTargetLink, isSelectedPathStartOrEnd } from './pathUtils'
import { Paths } from './types'
diff --git a/frontend/src/scenes/paths/renderPaths.ts b/frontend/src/scenes/paths/renderPaths.ts
index a3fbf8f463c8..70abb4acab30 100644
--- a/frontend/src/scenes/paths/renderPaths.ts
+++ b/frontend/src/scenes/paths/renderPaths.ts
@@ -1,11 +1,11 @@
import * as d3 from 'd3'
import { RefObject } from 'react'
-import sankey, { sankeyJustify, sankeyLinkHorizontal, type SankeyLink, type SankeyLayout } from 'lib/d3/sankey'
import { D3Selector } from 'lib/hooks/useD3'
import { stripHTTP } from 'lib/utils'
import { FunnelPathsFilter, PathsFilter } from '~/queries/schema/schema-general'
+import sankey, { sankeyJustify, sankeyLinkHorizontal, type SankeyLink, type SankeyLayout } from '~/vendor/d3/sankey'
// eslint-disable-next-line import/no-cycle
import { FALLBACK_CANVAS_WIDTH } from './Paths'
diff --git a/frontend/src/lib/utils/vendor/bintrees/index.ts b/frontend/src/vendor/bintrees/index.ts
similarity index 100%
rename from frontend/src/lib/utils/vendor/bintrees/index.ts
rename to frontend/src/vendor/bintrees/index.ts
diff --git a/frontend/src/lib/d3/sankey.ts b/frontend/src/vendor/d3/sankey.ts
similarity index 100%
rename from frontend/src/lib/d3/sankey.ts
rename to frontend/src/vendor/d3/sankey.ts
diff --git a/products/mcp_analytics/frontend/clustering/ClusterJourneySankey.tsx b/products/mcp_analytics/frontend/clustering/ClusterJourneySankey.tsx
index 987852158c5e..69c1aeb462ce 100644
--- a/products/mcp_analytics/frontend/clustering/ClusterJourneySankey.tsx
+++ b/products/mcp_analytics/frontend/clustering/ClusterJourneySankey.tsx
@@ -2,7 +2,7 @@ import { useMemo } from 'react'
import { Tooltip } from '@posthog/lemon-ui'
-import sankey, { sankeyLeft, sankeyLinkHorizontal } from 'lib/d3/sankey'
+import sankey, { sankeyLeft, sankeyLinkHorizontal } from '~/vendor/d3/sankey'
import type { MCPIntentClusterJourneyApi, MCPIntentClusterJourneyPathApi } from '../generated/api.schemas'