Skip to content

Commit

Permalink
feat: 3d topic cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
nreinartz committed Nov 15, 2023
1 parent 62aa0f1 commit 89803a7
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/results/Topics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="card h-100 shadow-sm" style="min-height: 70vh">
<div class="card-body">
<template v-if="resultsStore.topicDiscoveryResultsAvailable">
<TopicClusters />
<TopicClusters3D />
</template>
<Loader v-else :message="loadingMessage" :is-intermediate="loadingMessage === undefined" />
</div>
Expand Down Expand Up @@ -68,7 +68,7 @@ import Loader from '../common/Loader.vue';
import { computed, ref } from 'vue';
import { QueryProgress } from '@/types/api-models';
import TopicChart from './charts/TopicChart.vue';
import TopicClusters from './charts/TopicClusters.vue';
import TopicClusters3D from './charts/TopicClusters3D.vue';
const resultsStore = useResultsStore();
const activeTab = ref(0);
Expand Down
86 changes: 86 additions & 0 deletions src/components/results/charts/TopicClusters3D.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<template>
<div id="cluster-chart" class="h-100"></div>
</template>

<script setup lang="ts">
import echarts from "@/utils/echarts";
import { useResultsStore } from '@/stores/results';
import { onMounted, watch } from 'vue';
const resultsStore = useResultsStore();
onMounted(() => {
if (resultsStore.topicDiscoveryResultsAvailable) {
plotDiscoveredTopics();
}
else {
watch(() => resultsStore.topicDiscoveryResultsAvailable, () => {
plotDiscoveredTopics();
});
}
});
function plotDiscoveredTopics() {
const clusters = resultsStore.topicDiscoveryResults?.clusters!;
const miscIndexes = clusters.topic_labels.map((label, index) => label === -1 || index > 9 ? index : -1)
.filter(index => index !== -1);
//const dataSeries = [];
const dataSeries = []
for (let i = 0; i < 10; i++) {
const points = [];
for (let j = 0; j < clusters.topic_labels.length; j++) {
if (clusters.topic_labels[j] === i) {
points.push([clusters.points_x[j], clusters.points_y[j], clusters.points_z[j]]);
}
}
dataSeries.push({
name: resultsStore.topicDiscoveryResults?.topics![i]!,
type: 'scatter3D',
data: points
})
}
dataSeries.push({
name: "Miscellaneous",
type: 'scatter3D',
data: miscIndexes.map(index => [clusters.points_x[index], clusters.points_y[index], clusters.points_z[index]]),
itemStyle: {
color: 'rgba(0, 0, 0, 0.1)'
},
})
const option = {
title: {
text: 'Topic clusters'
},
grid3D: {
top: 150
},
tooltip: {
// trigger: 'axis',
showDelay: 0,
axisPointer: {
show: true
}
},
legend: {
left: 'center',
orient: "horizontal",
top: 50
},
xAxis3D: { type: 'value' },
yAxis3D: { type: 'value' },
zAxis3D: { type: 'value' },
series: dataSeries
};
const chartDom = document.getElementById('cluster-chart')!;
const myChart = echarts.init(chartDom);
myChart.setOption(option);
window.addEventListener('resize', () => myChart.resize());
}
</script>
1 change: 1 addition & 0 deletions src/types/api-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ interface DiscoveredTopic {
interface ClusteringResults {
points_x: number[];
points_y: number[];
points_z: number[];
topic_labels: number[];
}

Expand Down
14 changes: 7 additions & 7 deletions src/utils/echarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
ToolboxComponent,
VisualMapComponent,
BrushComponent,
MarkLineComponent,
MarkAreaComponent
MarkLineComponent
} from 'echarts/components';

import { SVGRenderer, CanvasRenderer } from 'echarts/renderers';
import { ScatterGLChart } from 'echarts-gl/charts';
import { SVGRenderer } from 'echarts/renderers';
import { Scatter3DChart } from 'echarts-gl/charts';
import { Grid3DComponent } from 'echarts-gl/components';

echarts.use([
BarChart,
Expand All @@ -33,11 +33,11 @@ echarts.use([
ToolboxComponent,
VisualMapComponent,
BrushComponent,
MarkAreaComponent,
MarkLineComponent,
UniversalTransition,
ScatterGLChart,
CanvasRenderer
Scatter3DChart,
Grid3DComponent,
SVGRenderer
]);

export default echarts;

0 comments on commit 89803a7

Please sign in to comment.