Skip to content

Commit

Permalink
type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoertl committed Sep 3, 2024
1 parent 64c09eb commit a13174e
Show file tree
Hide file tree
Showing 22 changed files with 270 additions and 211 deletions.
27 changes: 15 additions & 12 deletions src/components/CombinedMapChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mapAustria } from "./utils/mapAustria";
const props = defineProps<{
queries: Array<CorpusQuery>;
resdata: Array<Array<never>>;
resdata: Array<RegionalFrequency>;
mode: string;
}>();
Expand Down Expand Up @@ -42,21 +42,24 @@ const pieInfoWithData: ComputedRef<Array<PieInfoWithData>> = computed(() => {
color: query.color,
name: query.userInput,
}));
const data = values.map((value, index) => ({
y: Math.round(value * 100) / 100,
...queryData[index],
// color: colors[index],
}));
const data = values.map(
(value, index) =>
({
y: Math.round(Number(value) * 100) / 100,
...queryData[index],
// color: colors[index],
}) as { y: number; name: string; color: string },
);
return {
region: region,
region: region as Region,
data,
center: pieInfo.find((pInfo) => pInfo.region === region)?.center,
center: pieInfo.find((pInfo) => pInfo.region === region)!.center,
};
});
});
// calculates biggest value and sets it as index
function getValue(arr: Array<number | undefined>) {
function getValue(arr: Array<number | string>) {
let max = -1;
arr.forEach((v) => {
if (typeof v !== "number" || max > v) return;
Expand All @@ -66,7 +69,7 @@ function getValue(arr: Array<number | undefined>) {
}
const dataByRegion = computed(() => {
const result = usedRegion.map((r) => [r]);
const result: Array<Array<number | string>> = usedRegion.map((r) => [r]);
props.resdata.forEach((rdata) =>
rdata.data.forEach(({ region, relative, absolute }) => {
const idx = usedRegion.findIndex((r) => r === region);
Expand All @@ -79,10 +82,10 @@ const dataByRegion = computed(() => {
// used for the chart; see https://api.highcharts.com/highcharts/tooltip.pointFormatter
function pointFormatter() {
const queryArray = props.queries
// @ts-expect-error todo find out how to type thsi function correctly
// @ts-expect-error todo find out how to type this function correctly
.map((query) => [query.userInput, this[query.userInput], query.color])
.sort((a, b) => b[1] - a[1]);
// @ts-expect-error todo find out how to type thsi function correctly
// @ts-expect-error
return `<b>${this.id}</b><br/>
${queryArray
.map(
Expand Down
3 changes: 2 additions & 1 deletion src/components/CorpsumDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ const t = useTranslations("Corpsum");
<div class="flex items-center justify-end space-x-2 py-4">
<div class="ml-2 flex-1 text-sm">
{{ table.getState().pagination.pageIndex + 1 }} / {{ table.getPageCount() }}.
{{ t("total-of-n-entries", [data?.length || 0]) }}
<!-- @vue-ignore -->
{{ $t("Corpsum.total-of-n-entries", [data?.length || 0]) }}
</div>
<div class="space-x-2">
<Button
Expand Down
82 changes: 45 additions & 37 deletions src/components/DataDisplay/DataDisplayCollocations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,22 @@ const mode: Ref<Mode> = ref("coll_freq");
const expand = ref(false);
// const collocations: Ref<Array<Array<ICollocations>>> = ref([]);
const collocations: Ref<Array<Array<never>>> = ref([]);
const collocationsLoading: Ref<Array<boolean>> = ref([]);
interface CollocationEntry {
word: string;
freq: number;
coll_freq: number;
// todo: do this properly once it is known what is wanted
d: number;
m: number;
t: number;
name: string;
weight: number;
color: string;
}
const collocations: Ref<Array<Array<CollocationEntry>>> = ref([]);
const collocationsLoading: Ref<Array<boolean>> = ref([]);
// defines methods of data collocations
const cbgrfns = "dmt";
const q = computed(() =>
queries.value.map((query, index) => {
Expand All @@ -44,32 +57,33 @@ const q = computed(() =>
cbgrfns,
csortfn: "d",
citemsperpage: 10,
// @ts-expect-error descrtiption wrong
json: JSON.stringify({ concordance_query: queryStore.getQueryWithFacetting(query) }),
});
return response.data;
},
select: (data: Type10Collx) => {
collocations.value[index] = data.Items?.map((item) => {
const d = item.Stats?.find(({ n }) => n === "d");
const m = item.Stats?.find(({ n }) => n === "m");
const t = item.Stats?.find(({ n }) => n === "t");
return {
word: item.str,
freq: item.freq,
coll_freq: item.coll_freq,
// todo: do this properly:
d: d?.s ?? -1,
m: m?.s ?? -1,
t: t?.s ?? -1,
// stats: item.Stats,
// for highCharts
name: item.str,
weight: item.coll_freq,
color: query.color,
};
});
collocations.value[index] =
data.Items?.map((item) => {
const d = item.Stats?.find(({ n }) => n === "d");
const m = item.Stats?.find(({ n }) => n === "m");
const t = item.Stats?.find(({ n }) => n === "t");
return {
word: item.str!,
freq: item.freq!,
coll_freq: item.coll_freq!,
d: d?.s ?? -1,
m: m?.s ?? -1,
t: t?.s ?? -1,
// stats: item.Stats,
// for highCharts
name: item.str!,
weight: item.coll_freq!,
color: query.color,
} as unknown as CollocationEntry;
}) ?? [];
collocationsLoading.value[index] = false;
},
};
Expand All @@ -92,23 +106,13 @@ watch(mode, () => {
}, 10);
});
watch(queries.value, () => {
// console.log("queries chagened", queries.value);
const queryIds = queries.value.map(({ id }) => id);
collocations.value = collocations.value.filter(({ query }) => queryIds.includes(query));
// sometimes there end up duplicates in the regionalFrequencies. prop due to the useQueries, if a query is being deleted
collocations.value = collocations.value.filter(
(a, idx) => collocations.value.findIndex((b) => b.query === a.query) === idx,
);
});
const series = computed(() =>
collocations.value.map((collocation, index) => {
if (collocationsLoading.value[index]) return [];
return [
{
type: "wordcloud",
data: collocation.map((a) => ({
data: collocation.map((a: CollocationEntry) => ({
...a,
weight: a[mode.value],
})),
Expand All @@ -117,7 +121,7 @@ const series = computed(() =>
from: 0,
to: 0,
},
color: (point) => point.color,
color: (point: { color: string }) => point.color,
tooltip: {
pointFormatter,
},
Expand All @@ -126,27 +130,32 @@ const series = computed(() =>
}),
);
//@ts-expect-error TODO find out how to properly type this
useQueries({ queries: q });
function pointFormatter() {
return (
"<b>" +
// @ts-expect-error this is used inside the table rendering. -> todo: find out how to type this
this.name +
"</b><br/>" +
"Frequency: " +
// @ts-expect-error
this.freq +
"<br/>" +
"Collocational Frequency: " +
// @ts-expect-error
this.coll_freq +
"<br/>" +
"D: " +
// @ts-expect-error
this.d +
"<br/>" +
"M: " +
// @ts-expect-error
this.m +
"<br/>" +
"T: " +
// @ts-expect-error
this.t
);
}
Expand Down Expand Up @@ -184,7 +193,6 @@ function pointFormatter() {
</VCardText>

<VExpandTransition v-if="expand">
<!-- @vue-expect-error TODO properly type this -->
<DataDisplaySourceTable
v-if="!loading"
:queries="queries"
Expand Down
7 changes: 3 additions & 4 deletions src/components/DataDisplay/DataDisplayKeywordInContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const q = computed(() =>
}),
);
//@ts-expect-error TODO find out how to properly type this
useQueries({ queries: q });
function open(item: KeywordInContext) {
Expand All @@ -80,7 +79,7 @@ function open(item: KeywordInContext) {
const selectedKWIC: Ref<KeywordInContext | null> = ref(null);
const columns = getKWICColumns(t, open);
const columns = getKWICColumns(t as unknown as (s: string) => string, open);
</script>

<template>
Expand All @@ -93,14 +92,14 @@ const columns = getKWICColumns(t, open);
<VCardText class="py-0">
<div v-for="(query, index) of queries" :key="query.id">
<VCheckbox v-model="showViewOptionsMode" :label="t('viewOptions')"></VCheckbox>
<KWICAttributeSelect v-if="showViewOptionsMode" :query="query" @refresh="refresh()" />
<KWICAttributeSelect v-if="showViewOptionsMode" :query="query" />
<div>
<QueryDisplay :query="query" :loading="KWICresultsLoading[index]" />

<CorpsumDataTable
v-if="!KWICresultsLoading[index]"
:columns="columns"
:data="KWICresults[index]"
:data="KWICresults[index]!"
/>

<KWICDetailDialog
Expand Down
5 changes: 2 additions & 3 deletions src/components/DataDisplay/DataDisplayMediaSource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const q = computed(() =>
};
}),
);
//@ts-expect-error TODO find out how to properly type this
useQueries({ queries: q });
const chartMode: Ref<"seperate" | "stack"> = ref("stack");
Expand Down Expand Up @@ -107,14 +107,13 @@ const isStacked = computed(() => chartMode.value === "stack");
<MediaStackedBarChart
:queries="queries"
:source-distributions="sourceDistributions"
:mode="mode"
:mode="mode as 'absolute' | 'relative'"
:stack="isStacked"
/>
</template>
</VCardText>

<VExpandTransition v-if="expand">
<!-- @vue-expect-error TODO properly type this -->
<DataDisplaySourceTable
:queries="queries"
datatype="mediaSources"
Expand Down
15 changes: 6 additions & 9 deletions src/components/DataDisplay/DataDisplayRegionalFrequencies.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { queries } = storeToRefs(queryStore);
const api = useApiClient();
const regionalFrequencies: Ref<Array<Array<never>>> = ref([]);
const regionalFrequencies: Ref<Array<RegionalFrequency>> = ref([]);
const regionalFrequenciesLoading: Ref<Array<boolean>> = ref([]);
const chartMode: Ref<"combined" | "seperate"> = ref("combined");
Expand Down Expand Up @@ -43,18 +43,16 @@ const q = computed(() =>
return response.data;
},
select: (data: Type11Freqml) => {
//@ts-expect-error TODO properly type this
regionalFrequencies.value[index] = {
//@ts-expect-error TODO properly type this
query: query.id,
data:
data.Blocks?.map(
(block) =>
block.Items?.map((item) => {
return {
region: item.Word![0]!.n,
absolute: item.frq,
relative: item.reltt,
region: item.Word![0]!.n!,
absolute: item.frq!,
relative: item.reltt!,
};
}) ?? [],
)[0] ?? [],
Expand All @@ -64,7 +62,7 @@ const q = computed(() =>
};
}),
);
//@ts-expect-error TODO find out how to properly type this
useQueries({ queries: q });
const loading = computed(() => {
Expand Down Expand Up @@ -122,7 +120,7 @@ const expand = ref(false);
<div v-for="(query, index) of queries" :key="query.id">
<div class="mt-1">
<QueryDisplay :query="query" :loading="regionalFrequenciesLoading[index]" />
<ClientOnly v-if="!regionalFrequenciesLoading[index]">
<ClientOnly v-if="!regionalFrequenciesLoading[index] && regionalFrequencies[index]">
<MapChart
v-if="!isCombined"
:query="query"
Expand All @@ -139,7 +137,6 @@ const expand = ref(false);
</VCardText>

<VExpandTransition v-if="expand">
<!-- @vue-expect-error TODO properly type this -->
<DataDisplaySourceTable
datatype="regionalFrequencies"
:queries="queries"
Expand Down
8 changes: 6 additions & 2 deletions src/components/DataDisplay/DataDisplaySourceTable.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script lang="ts" setup>
// @eslint-ignore-next-line
type legalAny = unknown;
const props = defineProps<{
queries: Array<CorpusQuery>;
datatype: SearchFunctionKey;
loading: Array<boolean>;
data: Array<never>;
data: Array<Array<legalAny>>;
}>();
const tab = ref(null);
Expand All @@ -14,6 +17,7 @@ const columns = computed(() => {
return {
accessorKey: key,
header: () => h("div", { class: "text-right" }, key),
// @ts-ignore this comes from tanstack-table
cell: ({ row }) => {
const value = row.getValue(key);
return h("div", { class: "text-right font-medium" }, value as string);
Expand All @@ -39,7 +43,7 @@ const columns = computed(() => {
<VWindowItem :value="query.id">
<div>
<QueryDisplay :query="query" :loading="loading[index]" />
<CorpsumDataTable v-if="!loading[index]" :columns="columns" :data="data[index]" />
<CorpsumDataTable v-if="!loading[index]" :columns="columns" :data="data[index]!" />
</div>
</VWindowItem>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const q = computed(() =>
};
}),
);
//@ts-expect-error TODO find out how to properly type this
useQueries({ queries: q });
const mode = ref("relative");
Expand Down Expand Up @@ -108,7 +108,6 @@ const expand = ref(false);
</VCardText>

<VExpandTransition v-if="expand">
<!-- @vue-expect-error TODO properly type this -->
<DataDisplaySourceTable
:queries="queries"
:loading="wordFormFrequenciesLoading"
Expand Down
Loading

0 comments on commit a13174e

Please sign in to comment.