Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix axios and allow umap visualization #211

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/components/FilterEditorWindow/config/RequestFromCode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { bigIntJSON } from '../../../common/bigIntJSON';
import { axiosInstance } from '../../../common/axios';

function parseDataToRequest(reqBody) {
// Validate color_by
Expand Down Expand Up @@ -62,7 +62,7 @@ export async function requestFromCode(dataRaw, collectionName) {

async function actionFromCode(collectionName, data, action) {
try {
const response = await axios({
const response = await axiosInstance({
method: 'POST',
url: `collections/${collectionName}/points/${action || 'scroll'}`,
data: data.reqBody,
Expand Down
8 changes: 6 additions & 2 deletions src/components/VisualizeChart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { bigIntJSON } from '../../common/bigIntJSON';

const SCORE_GRADIENT_COLORS = ['#EB5353', '#F9D923', '#36AE7C'];

const VisualizeChart = ({ scrollResult }) => {
const VisualizeChart = ({ scrollResult, algorithm = null }) => {
const { enqueueSnackbar } = useSnackbar();
const [openViewPoints, setOpenViewPoints] = useState(false);
const [viewPoints, setViewPoint] = useState([]);
Expand Down Expand Up @@ -180,7 +180,10 @@ const VisualizeChart = ({ scrollResult }) => {
};

if (scrollResult.data.result?.points?.length > 0) {
worker.postMessage(scrollResult.data);
worker.postMessage({
...scrollResult.data,
algorithm: algorithm,
});
}

return () => {
Expand All @@ -199,6 +202,7 @@ const VisualizeChart = ({ scrollResult }) => {

VisualizeChart.propTypes = {
scrollResult: PropTypes.object.isRequired,
algorithm: PropTypes.string,
};

export default VisualizeChart;
5 changes: 4 additions & 1 deletion src/components/VisualizeChart/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const MESSAGE_INTERVAL = 200;

self.onmessage = function (e) {
let now = new Date().getTime();

const algorithm = e?.data?.algorithm || 'TSNE';

const data1 = e.data;
const data = [];

Expand Down Expand Up @@ -64,7 +67,7 @@ self.onmessage = function (e) {
return;
}
if (data.length) {
const D = new druid['TSNE'](data, {}); // ex params = { perplexity : 50,epsilon :5}
const D = new druid[algorithm](data, {}); // ex params = { perplexity : 50,epsilon :5}
const next = D.generator(); // default = 500 iterations
let i = {};
for (i of next) {
Expand Down
15 changes: 14 additions & 1 deletion src/pages/Visualize.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const query = `
// - 'vector_name': specify which vector to use for visualization
// if there are multiple.
//
// - 'algorithm': specify algorithm to use for visualization. Available options: 'TSNE', 'UMAP'.
//
// Minimal example:

{
Expand All @@ -58,6 +60,7 @@ function Visualize() {
const theme = useTheme();
const [code, setCode] = useState(query);
const [result, setResult] = useState(defaultResult);
const [algorithm, setAlgorithm] = useState('TSNE');
// const [errorMessage, setErrorMessage] = useState(null); // todo: use or remove
const navigate = useNavigate();
const params = useParams();
Expand All @@ -70,6 +73,10 @@ function Visualize() {
}, [height, VisualizeChartWrapper]);

const onEditorCodeRun = async (data, collectionName) => {
if (data?.algorithm) {
setAlgorithm(data.algorithm);
}

const result = await requestFromCode(data, collectionName);
setResult(result);
};
Expand Down Expand Up @@ -106,6 +113,12 @@ function Visualize() {
type: 'string',
nullable: true,
},
algorithm: {
description: 'Algorithm to use for visualization',
type: 'string',
enum: ['TSNE', 'UMAP'],
default: 'TSNE',
},
},
});

Expand Down Expand Up @@ -146,7 +159,7 @@ function Visualize() {
</Paper>
</Box>
<Box ref={VisualizeChartWrapper} height={visualizeChartHeight} width={'100%'}>
<VisualizeChart scrollResult={result} />
<VisualizeChart scrollResult={result} algorithm={algorithm} />
</Box>
</Box>
</Panel>
Expand Down
Loading