Skip to content

Commit

Permalink
Merge pull request #60 from zilliztech/compatible_with_feder_0_x
Browse files Browse the repository at this point in the history
compatible with feder_v0.x
  • Loading branch information
alwayslove2013 committed Sep 14, 2022
2 parents e1caa6a + 431f68e commit dbb1492
Show file tree
Hide file tree
Showing 105 changed files with 400 additions and 6,657 deletions.
8 changes: 8 additions & 0 deletions federjs/Feder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as d3 from 'd3';
import {
EActionType,
EIndexType,
EMediaType,
ESourceType,
EViewType,
TId,
Expand Down Expand Up @@ -37,8 +38,15 @@ export class Feder {
const { viewType = EViewType.default } = viewParams;
this.viewType = viewType;

// Compatible with feder_v0.x
if (!viewParams.mediaContent && !!viewParams.mediaCallback)
viewParams.mediaContent = viewParams.mediaCallback;
if (viewParams.mediaType === 'img') viewParams.mediaType = EMediaType.image;
if (!!viewParams.projectSeed && !viewParams?.projectParams?.projectSeed)
viewParams.projectParams = Object.assign({}, viewParams.projectParams, {
projectSeed: viewParams.projectSeed,
});

this.viewParams = viewParams;

this.searchParams = {};
Expand Down
1 change: 0 additions & 1 deletion federjs/FederIndex/id2VectorHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const getId2VectorMap = {

export default function id2VectorHandler(index: TIndexStructure) {
const indexType = index.indexType;

const getId2Vector = getId2VectorMap[indexType];
const id2Vector = getId2Vector(index);
return id2Vector;
Expand Down
1 change: 1 addition & 0 deletions federjs/FederLayout/visDataHandler/ivfflat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const layoutParamsIvfflatDefault = {
nonTopkNodeR: 3,
minVoronoiRadius: 5,
projectPadding: [20, 30, 20, 30],
staticPanelWidth: 240,
};
export default class FederLayoutIvfflat implements TFederLayoutHandler {
overviewLayoutParams: TLayoutParamsIvfflat = {};
Expand Down
16 changes: 13 additions & 3 deletions federjs/FederLayout/visDataHandler/ivfflat/search/finePolar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ export const ivfflatSearchViewLayoutFinePolar = ({
polarMaxR: number;
}) =>
new Promise<TVisDataIvfflatSearchViewNode[]>((resolve) => {
const { numForceIterations, nonTopkNodeR, canvasScale, polarRadiusUpperBound } = layoutParams;
const {
numForceIterations,
nonTopkNodeR,
canvasScale,
polarRadiusUpperBound,
} = layoutParams;
const clusterId2cluster = {} as {
[clusterId: TId]: TVisDataIvfflatSearchViewCluster;
};
Expand All @@ -41,8 +46,13 @@ export const ivfflatSearchViewLayoutFinePolar = ({
searchViewNodes.sort((a, b) => a.distance - b.distance);

// distance scale
const minDis = getPercentile(searchViewNodes, 'distance', 0);
const maxDis = getPercentile(searchViewNodes, 'distance', polarRadiusUpperBound);
const minDis =
searchViewNodes[Math.min(searchViewNodes.length - 1, 1)].distance;
const maxDis = getPercentile(
searchViewNodes,
'distance',
polarRadiusUpperBound
);
const r = d3
.scaleLinear()
.domain([minDis, maxDis])
Expand Down
16 changes: 12 additions & 4 deletions federjs/FederLayout/visDataHandler/ivfflat/search/fineProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ivfflatSearchViewLayoutFineProject = ({
new Promise<void>((resolve) => {
const {
projectPadding,
staticPanelWidth,
width,
height,
canvasScale,
Expand All @@ -44,13 +45,20 @@ export const ivfflatSearchViewLayoutFineProject = ({
node.projection = searchviewNodesProjection[i];
});

const xRange = targetNode.isLeft_coarseLevel
? [
projectPadding[3] * canvasScale,
(width - projectPadding[1]) * canvasScale -
staticPanelWidth * canvasScale,
]
: [
projectPadding[3] * canvasScale + staticPanelWidth * canvasScale,
(width - projectPadding[1]) * canvasScale,
];
const x = d3
.scaleLinear()
.domain(d3.extent(searchViewNodes, (node) => node.projection[0]))
.range([
projectPadding[3] * canvasScale,
(width - projectPadding[1]) * canvasScale,
]);
.range(xRange);
const y = d3
.scaleLinear()
.domain(d3.extent(searchViewNodes, (node) => node.projection[1]))
Expand Down
6 changes: 6 additions & 0 deletions federjs/FederView/hnswView/defaultViewParamsHnsw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,11 @@ export const defaultViewParamsHnsw = {
tipLineWidth: 2,

mediaContentCount: 9,

staticPanelWidth: 240,
hoveredPanelWidth: 250,
clickedPanelWidth: 210,

getVectorById: async () => [],
} as TViewParamsHnsw;
export default defaultViewParamsHnsw;
29 changes: 23 additions & 6 deletions federjs/FederView/hnswView/infoPanelStyles.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
import { hexWithOpacity } from 'FederView/renderUtils2D';

export const staticPanelStyles = ({ width, height, padding }) => ({
export const staticPanelStyles = ({
height,
staticPanelWidth,
}: {
height: number;
staticPanelWidth?: number;
}) => ({
position: 'absolute',
left: '16px',
top: '16px',
width: padding ? `${padding[3] + 10}px` : `${width * 0.3}px`,

width: `${staticPanelWidth}px`,
'max-height': `${height - 110}px`,
overflow: 'auto',
borderColor: '#FFFFFF',
backgroundColor: hexWithOpacity('#000000', 0.6),
// pointerEvents: 'none',
});

export const clickedPanelStyles = ({ width, height, padding }) => ({
export const clickedPanelStyles = ({
height,
clickedPanelWidth,
}: {
height: number;
clickedPanelWidth?: number;
}) => ({
position: 'absolute',
right: '16px',
top: '16px',
width: padding ? `${padding[1] - 10}px` : `${width * 0.3}px`,
width: `${clickedPanelWidth}px`,
'max-height': `${height - 60}px`,
overflow: 'auto',
borderColor: '#FFFFFF',
backgroundColor: hexWithOpacity('#000000', 0.6),
});

export const hoveredPanelStyles = ({ width }) => ({
export const hoveredPanelStyles = ({
hoveredPanelWidth,
}: {
hoveredPanelWidth: number;
}) => ({
position: 'absolute',
width: `${width * 0.3}px`,
width: `${hoveredPanelWidth}px`,
paddingLeft: '6px',
left: 0,
top: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default async function updateHoveredPanelNodeView(
hasBorder: false,
content: [
{ title: `Row No. ${node.id}` },
{ text: `distance: ${node.distance.toFixed(3)}` },
{
text: `belong to cluster-${node.clusterId}`,
},
Expand Down
5 changes: 5 additions & 0 deletions federjs/FederView/ivfflatView/defaultViewParamsIvfflat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const defaltViewParamsIvfflat = {
transitionNodesMoveTime: 800,

mediaContentCount: 9,
staticPanelWidth: 240,
hoveredPanelWidth: 250,
clickedPanelWidth: 210,

getVectorById: async () => []
} as TViewParamsIvfflat;

export default defaltViewParamsIvfflat;
20 changes: 8 additions & 12 deletions federjs/FederView/ivfflatView/infoPanelStyles.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { hexWithOpacity } from 'FederView/renderUtils2D';

export const staticPanelStyles = ({
width,
height,
padding,
staticPanelWidth,
}: {
width: number;
height: number;
padding?: number[];
staticPanelWidth?: number;
}) => ({
position: 'absolute',
left: '16px',
top: '16px',
width: padding ? `${padding[3] + 10}px` : `${width * 0.3}px`,
width: `${staticPanelWidth}px`,
'max-height': `${height - 110}px`,
overflow: 'auto',
borderColor: '#FFFFFF',
Expand All @@ -21,27 +19,25 @@ export const staticPanelStyles = ({
});

export const clickedPanelStyles = ({
width,
height,
padding,
clickedPanelWidth,
}: {
width: number;
height: number;
padding?: number[];
clickedPanelWidth?: number;
}) => ({
position: 'absolute',
right: '16px',
top: '16px',
width: padding ? `${padding[1] - 10}px` : `${width * 0.3}px`,
width: `${clickedPanelWidth}px`,
'max-height': `${height - 60}px`,
overflow: 'auto',
borderColor: '#FFFFFF',
backgroundColor: hexWithOpacity('#000000', 0.6),
});

export const hoveredPanelStyles = ({ width }) => ({
export const hoveredPanelStyles = ({ hoveredPanelWidth }: {hoveredPanelWidth: number}) => ({
position: 'absolute',
width: `${width * 0.3}px`,
width: `${hoveredPanelWidth}px`,
paddingLeft: '6px',
left: 0,
top: 0,
Expand Down
4 changes: 4 additions & 0 deletions federjs/Types/visData/visDataHnswDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export interface TViewParamsHnsw extends TViewParams {
tipLineAngle?: number;
tipLineColor?: string;
tipLineWidth?: number;

staticPanelWidth?: number;
hoveredPanelWidth: number;
clickedPanelWidth: number;
}

export interface TLayoutParamsHnsw {
Expand Down
5 changes: 5 additions & 0 deletions federjs/Types/visData/visDataIvfflat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface TLayoutParamsIvfflat {
polarRadiusUpperBound?: number;

projectPadding?: [number, number, number, number];
staticPanelWidth?: number;
}

export interface TViewParamsIvfflat extends TViewParams {
Expand Down Expand Up @@ -127,4 +128,8 @@ export interface TViewParamsIvfflat extends TViewParams {
transitionReplaceTime: number;
transitionNodesEnterTime: number;
transitionNodesMoveTime: number;

staticPanelWidth?: number;
hoveredPanelWidth: number;
clickedPanelWidth: number;
}
Loading

0 comments on commit dbb1492

Please sign in to comment.