Skip to content

Commit

Permalink
Merge pull request #20 from zilliztech/fix_search_params
Browse files Browse the repository at this point in the history
fix bugs: module exports; search params; hover pointer events
  • Loading branch information
shanghaikid authored Apr 28, 2022
2 parents 1fe822b + 25be0d8 commit f558d10
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
11 changes: 7 additions & 4 deletions esm/Feder.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ export default class Feder {
}
// console.info('feder initialized');
}
getTestIdAndVec() {
async getTestIdAndVec() {
this.initCorePromise && (await this.initCorePromise);
return this.core.getTestIdAndVec();
}
setSearchParams(params) {
async setSearchParams(params) {
this.initCorePromise && (await this.initCorePromise);
this.core.setSearchParams(params);
}
setProjectParams(params) {
async setProjectParams(params) {
this.initCorePromise && (await this.initCorePromise);
this.core.setProjectParams(params);
}
initFederView() {
Expand Down Expand Up @@ -82,7 +85,7 @@ export default class Feder {
}
async searchRandTestVec() {
this.initCorePromise && (await this.initCorePromise);
const [testId, testVec] = this.core.getTestIdAndVec();
const [testId, testVec] = await this.core.getTestIdAndVec();
console.log('random test vector:', testId, testVec);
const targetMediaUrl =
this.viewParams && this.viewParams.mediaCallback
Expand Down
2 changes: 1 addition & 1 deletion esm/FederCore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default class FederCore {
return this.id2Vector[id] || null;
}
setSearchParams(params) {
const newSearchParams = Object.assign(this.searchParams, params);
const newSearchParams = Object.assign({}, this.searchParams, params);
this.searchParams = newSearchParams;
}
search(target) {
Expand Down
8 changes: 5 additions & 3 deletions esm/FederPy/src/federpy/federpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, indexFile, indexSource, width=1000, height=620, mediaType="",
# self.federjs = "http://192.168.0.101:12357/feder_esm.js"

self.actionJs = ""
self.searchParams = ""
self.width = width
self.height = height
self.mediaType = mediaType
Expand Down Expand Up @@ -55,6 +56,9 @@ def searchRandTestVec(self, isDisplay=True):
else:
return self.getHtml()

def setSearchParams(self, searchParams):
self.searchParams = searchParams

def getJs(self):
return """
%s
Expand All @@ -81,9 +85,7 @@ def getHtml(self):
%s
</script>
</html>
</html>
""" % (self.getDiv(), self.getJs())

def showHtml(self):
Expand Down
1 change: 1 addition & 0 deletions esm/FederView/BaseView.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default class BaseView {
top: 0,
width: '240px',
display: 'flex',
pointerEvents: 'none',
// height: '500px',
// borderStyle: 'dashed',
// borderColor: ZYellow,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"exports": {
".": {
"import": "./esm/index.js",
"import": "./dist/index.js",
"default": "./cjs/index.js"
},
"./utils": {
Expand Down
18 changes: 11 additions & 7 deletions test/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13415,7 +13415,7 @@ ${indentData}`);
return this.id2Vector[id2] || null;
}
setSearchParams(params) {
const newSearchParams = Object.assign(this.searchParams, params);
const newSearchParams = Object.assign({}, this.searchParams, params);
this.searchParams = newSearchParams;
}
search(target) {
Expand Down Expand Up @@ -13687,7 +13687,8 @@ ${indentData}`);
left: 0,
top: 0,
width: "240px",
display: "flex"
display: "flex",
pointerEvents: "none"
};
Object.assign(hoveredPanel.style, hoveredPanelStyle);
dom.appendChild(hoveredPanel);
Expand Down Expand Up @@ -16054,13 +16055,16 @@ ${indentData}`);
this.initFederView();
}
}
getTestIdAndVec() {
async getTestIdAndVec() {
this.initCorePromise && await this.initCorePromise;
return this.core.getTestIdAndVec();
}
setSearchParams(params) {
async setSearchParams(params) {
this.initCorePromise && await this.initCorePromise;
this.core.setSearchParams(params);
}
setProjectParams(params) {
async setProjectParams(params) {
this.initCorePromise && await this.initCorePromise;
this.core.setProjectParams(params);
}
initFederView() {
Expand Down Expand Up @@ -16103,7 +16107,7 @@ ${indentData}`);
}
async searchRandTestVec() {
this.initCorePromise && await this.initCorePromise;
const [testId, testVec] = this.core.getTestIdAndVec();
const [testId, testVec] = await this.core.getTestIdAndVec();
console.log("random test vector:", testId, testVec);
const targetMediaUrl = this.viewParams && this.viewParams.mediaCallback ? this.viewParams.mediaCallback(testId) : null;
this.search(testVec, targetMediaUrl);
Expand Down Expand Up @@ -16136,6 +16140,6 @@ ${indentData}`);
window.addEventListener("DOMContentLoaded", async () => {
const feder = await testHNSW("https://assets.zilliz.com/hnswlib_hnsw_voc_17k_1f1dfd63a9.index");
console.log(feder);
feder.searchRandTestVec();
feder.overview();
});
})();
8 changes: 6 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Feder } from '../esm/index.js';
// import { Feder } from '../dist/index.js';
// import { Feder } from '@zilliz/feder';
import * as d3 from 'd3';

Expand Down Expand Up @@ -67,6 +68,9 @@ window.addEventListener('DOMContentLoaded', async () => {
// 'https://assets.zilliz.com/hnswlib_hnsw_voc_17k_1f1dfd63a9.index'
// );
console.log(feder);
// feder.overview();
feder.searchRandTestVec();
feder.overview();
// feder.setSearchParams({
// k: 2,
// });
// feder.searchRandTestVec();
});

0 comments on commit f558d10

Please sign in to comment.