Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
bcolloran committed Sep 7, 2023
1 parent 553212e commit f493f15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 162 deletions.
125 changes: 5 additions & 120 deletions web-common/src/features/dashboards/leaderboard/Leaderboard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,20 @@
import { useTimeControlStore } from "@rilldata/web-common/features/dashboards/time-controls/time-control-store";
import {
createQueryServiceMetricsViewComparisonToplist,
// createQueryServiceMetricsViewToplist,
MetricsViewDimension,
MetricsViewMeasure,
} from "@rilldata/web-common/runtime-client";
import { useQueryClient } from "@tanstack/svelte-query";
import { runtime } from "../../../runtime-client/runtime-store";
import { SortDirection } from "../proto-state/derived-types";
import { metricsExplorerStore, useDashboardStore } from "../dashboard-stores";
// import { getFilterForComparsion } from "../dimension-table/dimension-table-utils";
import type { FormatPreset } from "../humanize-numbers";
import LeaderboardHeader from "./LeaderboardHeader.svelte";
import {
LeaderboardItemData2,
LeaderboardItemData,
getLabeledComparisonFromComparisonRow,
getQuerySortType,
// prepareLeaderboardItemData,
prepareLeaderboardItemData2,
prepareLeaderboardItemData,
} from "./leaderboard-utils";
import LeaderboardListItem from "./LeaderboardListItem.svelte";
Expand Down Expand Up @@ -110,64 +107,6 @@
$: sortAscending = $dashboardStore.sortDirection === SortDirection.ASCENDING;
$: sortType = $dashboardStore.dashboardSortType;
// $: topListQuery = createQueryServiceMetricsViewToplist(
// $runtime.instanceId,
// metricViewName,
// {
// dimensionName: dimensionName,
// measureNames: [measure?.name],
// timeStart: $timeControlsStore.timeStart,
// timeEnd: $timeControlsStore.timeEnd,
// filter: filterForDimension,
// limit: "250",
// offset: "0",
// sort: [
// {
// name: measure?.name,
// ascending: sortAscending,
// },
// ],
// },
// {
// query: {
// enabled: $timeControlsStore.ready && !!filterForDimension,
// },
// }
// );
// let values: { value: number; label: string | number }[] = [];
// // let comparisonValues = [];
// /** replace data after fetched. */
// $: if (!$topListQuery?.isFetching) {
// values =
// $topListQuery?.data?.data.map((val) => ({
// value: val[measure?.name],
// label: val[dimensionColumn],
// })) ?? [];
// }
// // get all values that are selected but not visible.
// // we'll put these at the bottom w/ a divider.
// $: selectedValuesThatAreBelowTheFold = activeValues
// ?.filter((label) => {
// return (
// // the value is visible within the fold.
// !values.slice(0, slice).some((value) => {
// return value.label === label;
// })
// );
// })
// .map((label) => {
// const existingValue = values.find((value) => value.label === label);
// // return the existing value, or if it does not exist, just return the label.
// // FIX ME return values for label which are not in the query
// return existingValue ? { ...existingValue } : { label };
// })
// .sort((a, b) => {
// return b.value - a.value;
// });
$: contextColumn = $dashboardStore?.leaderboardContextColumn;
// Compose the comparison /toplist query
$: showTimeComparison =
Expand All @@ -181,42 +120,6 @@
$: showContext = $dashboardStore?.leaderboardContextColumn;
// add all sliced and active values to the include filter.
// $: currentVisibleValues =
// $topListQuery?.data?.data
// ?.slice(0, slice)
// ?.concat(selectedValuesThatAreBelowTheFold)
// ?.map((v) => v[dimensionColumn]) ?? [];
// $: updatedFilters = getFilterForComparsion(
// filterForDimension,
// dimensionName,
// currentVisibleValues
// );
// $: comparisonTopListQuery = createQueryServiceMetricsViewToplist(
// $runtime.instanceId,
// metricViewName,
// {
// dimensionName: dimensionName,
// measureNames: [measure?.name],
// timeStart: $timeControlsStore.comparisonTimeStart,
// timeEnd: $timeControlsStore.comparisonTimeEnd,
// filter: updatedFilters,
// limit: currentVisibleValues.length.toString(),
// offset: "0",
// sort: [
// {
// name: measure?.name,
// ascending: sortAscending,
// },
// ],
// },
// {
// query: {
// enabled: Boolean(showTimeComparison && !!updatedFilters),
// },
// }
// );
$: querySortType = getQuerySortType(sortType);
$: sortedQueryBody = {
Expand Down Expand Up @@ -268,12 +171,12 @@
}
/** replace data after fetched. */
let aboveTheFold: LeaderboardItemData2[] = [];
let selectedBelowTheFold: LeaderboardItemData2[] = [];
let aboveTheFold: LeaderboardItemData[] = [];
let selectedBelowTheFold: LeaderboardItemData[] = [];
let noAvailableValues = true;
let showExpandTable = false;
$: if (!$sortedQuery?.isFetching) {
const leaderboardData = prepareLeaderboardItemData2(
const leaderboardData = prepareLeaderboardItemData(
$sortedQuery?.data?.rows?.map((r) =>
getLabeledComparisonFromComparisonRow(r, measure.name)
) ?? [],
Expand All @@ -286,26 +189,8 @@
selectedBelowTheFold = leaderboardData.selectedBelowTheFold;
noAvailableValues = leaderboardData.noAvailableValues;
showExpandTable = leaderboardData.showExpandTable;
// console.log("sortedQuery data", dimensionName, leaderboardData);
}
// $: if (!$sortedQuery.isFetching) {
// console.log(
// "sortedQuery",
// dimensionName,
// $sortedQuery?.data?.rows.map((v) => [
// v.dimensionValue,
// {
// name: v.measureValues[0].measureName,
// base: v.measureValues[0].baseValue,
// comparison: v.measureValues[0].comparisonValue,
// deltaRel: v.measureValues[0].deltaRel,
// deltaAbs: v.measureValues[0].deltaAbs,
// },
// ])
// );
// }
let hovered: boolean;
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import { humanizeDataType } from "../humanize-numbers";
import LongBarZigZag from "./LongBarZigZag.svelte";
import {
LeaderboardItemData2,
LeaderboardItemData,
formatContextColumnValue,
} from "./leaderboard-utils";
import ContextColumnValue from "./ContextColumnValue.svelte";
export let itemData: LeaderboardItemData2;
export let itemData: LeaderboardItemData;
$: label = itemData.dimensionValue;
$: measureValue = itemData.value;
$: selected = itemData.selected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,6 @@ export function getFormatterValueForPercDiff(pct: number | null) {
return formatMeasurePercentageDifference(pct);
}

export type LeaderboardItemData = {
label: string | number;
// main value to be shown in the leaderboard
value: number;
// the comparison value, which may be either the previous value
// (used to calculate the absolute or percentage change) or
// the measure total (used to calculate the percentage of total)
comparisonValue: number;
// selection is not enough to determine if the item is included
// or excluded; for that we need to know the leaderboard's
// include/exclude state
selected: boolean;
};

export function prepareLeaderboardItemData(
values: { value: number; label: string | number }[],
selectedValues: (string | number)[],
comparisonMap: Map<string | number, number>
): LeaderboardItemData[] {
return values.map((v) => {
const selected =
selectedValues.findIndex((value) => value === v.label) >= 0;
const comparisonValue = comparisonMap.get(v.label);

return {
...v,
selected,
comparisonValue,
};
});
}

/**
* A `V1MetricsViewComparisonRow` basically represents a row of data
* in the *dimension detail table*, NOT in the leaderboard. Therefore,
Expand All @@ -73,7 +41,7 @@ export function getLabeledComparisonFromComparisonRow(
};
}

export type LeaderboardItemData2 = {
export type LeaderboardItemData = {
// The dimension value label to be shown in the leaderboard
dimensionValue: string | number;

Expand Down Expand Up @@ -105,7 +73,7 @@ function cleanUpComparisonValue(
v: ComparisonValueWithLabel,
total: number | null,
selected: boolean
): LeaderboardItemData2 {
): LeaderboardItemData {
if (!(Number.isFinite(v.baseValue) || v.baseValue === null)) {
throw new Error(
`Leaderboards only implemented for numeric baseValues or missing data (null). Got: ${JSON.stringify(
Expand Down Expand Up @@ -145,19 +113,19 @@ type ComparisonValueWithLabel = V1MetricsViewComparisonValue & {
* or null if the measure is not valid_percent_of_total
* @returns
*/
export function prepareLeaderboardItemData2(
export function prepareLeaderboardItemData(
values: ComparisonValueWithLabel[],
numberAboveTheFold: number,
selectedValues: (string | number)[],
total: number | null
): {
aboveTheFold: LeaderboardItemData2[];
selectedBelowTheFold: LeaderboardItemData2[];
aboveTheFold: LeaderboardItemData[];
selectedBelowTheFold: LeaderboardItemData[];
noAvailableValues: boolean;
showExpandTable: boolean;
} {
const aboveTheFold: LeaderboardItemData2[] = [];
const selectedBelowTheFold: LeaderboardItemData2[] = [];
const aboveTheFold: LeaderboardItemData[] = [];
const selectedBelowTheFold: LeaderboardItemData[] = [];
let selectedValuesCopy = [...selectedValues];
// console.log({ values, len: values.length, selectedValues });
values.forEach((v, i) => {
Expand Down Expand Up @@ -213,7 +181,7 @@ export function prepareLeaderboardItemData2(
* accounting for the context column type.
*/
export function formatContextColumnValue(
itemData: LeaderboardItemData2,
itemData: LeaderboardItemData,
contextType: LeaderboardContextColumn,
formatPreset: FormatPreset
): string {
Expand Down

0 comments on commit f493f15

Please sign in to comment.