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

#2693 Improves Distribution Comparison for categorical probes #2779

Merged
merged 3 commits into from
Apr 2, 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
37 changes: 29 additions & 8 deletions src/components/DistributionComparisonModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
export let distViewButtonId;

let normalized = $store.productDimensions.normalizationType === 'normalized';
let probeType = $store.probe.type;
let probeKind = $store.probe.details.kind;
let cumulative = false;
let activeCategoricalProbeLabels =
probeKind === 'categorical'
? $store.probe.details.labels.filter((l) =>
$store.activeBuckets.includes(l)
)
: [];

let valueSelector = 'value';
// Change this value to adjust the minimum tick increment on the chart
Expand Down Expand Up @@ -49,9 +57,16 @@
};

const buildDensity = function (chartData) {
let density = normalized
? chartData[densityMetricType]
: convertValueToPercentage(chartData[densityMetricType]);
let density = chartData[densityMetricType];
if (probeKind === 'categorical') {
let categoricalProbeLabels = $store.probe.details.labels;
density = density.filter((v, i) =>
$store.activeBuckets.includes(categoricalProbeLabels[i])
);
}
if (probeType === 'scalar' || !normalized) {
density = convertValueToPercentage(chartData[densityMetricType]);
}
return cumulative ? makeCumulative(density) : density;
};
</script>
Expand Down Expand Up @@ -111,11 +126,13 @@
<div class="outer-flex">
<div class="charts">
<div style="display: flex; padding: 1em;">
<SliderSwitch
bind:checked={cumulative}
label="Cumulative mode: "
design="slider"
/>
{#if probeKind !== 'categorical'}
<SliderSwitch
bind:checked={cumulative}
label="Cumulative mode: "
design="slider"
/>
{/if}
</div>
<div class="chart-fixed">
<p>Reference</p>
Expand All @@ -128,6 +145,7 @@
density={topChartDensity}
{topTick}
{tickIncrement}
{activeCategoricalProbeLabels}
>
<g slot="glam-body">
{#if bottomChartData}
Expand All @@ -139,6 +157,7 @@
{tickIncrement}
sampleCount={topChartSampleCount}
tooltipLocation="bottom"
{activeCategoricalProbeLabels}
/>
{/if}
</g>
Expand All @@ -158,6 +177,7 @@
density={bottomChartDensity}
{topTick}
{tickIncrement}
{activeCategoricalProbeLabels}
>
<g slot="glam-body">
{#if bottomChartData}
Expand All @@ -168,6 +188,7 @@
{topTick}
sampleCount={bottomChartSampleCount}
tooltipLocation="top"
{activeCategoricalProbeLabels}
/>
{/if}
</g>
Expand Down
17 changes: 13 additions & 4 deletions src/components/explore/DistributionChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import { tooltip as tooltipAction } from '@graph-paper/core/actions';
import { distributionComparisonGraph } from '../../utils/constants';
import { formatCompact } from '../../utils/formatters';
import { store } from '../../state/store';

export let innerHeight;
export let innerWidth;
export let density;
export let topTick;
export let sampleCount;
export let tooltipLocation;
export let activeCategoricalProbeLabels;

let height = (innerHeight * distributionComparisonGraph.heightMult) / 2;
let color = 'var(--digital-blue-350)';
Expand All @@ -21,6 +23,7 @@
distributionComparisonGraph.left;
let maxHeight = height - distributionComparisonGraph.top;
let minHeight = distributionComparisonGraph.bottom;
let probeKind = $store.probe.details.kind;
let formatPercent = (t) =>
Intl.NumberFormat('en-US', {
style: 'percent',
Expand All @@ -33,6 +36,15 @@
const spaceBetweenBars = bucketWidth / 10;
const barOffsetX = spaceBetweenBars / 2;
const barWidth = bucketWidth - spaceBetweenBars;

const buildBucketTxt = (index, bin) => {
if (probeKind === 'categorical') {
return activeCategoricalProbeLabels[index];
}
return index === density.length - 1
? `sample value ≥ ${bin}`
: `${bin} ≤ sample value ≤ ${density[index + 1][binSelector]}`;
};
</script>

<style>
Expand Down Expand Up @@ -60,10 +72,7 @@

<g style="fill: {'#fafafa'};">
{#each density as { bin, value }, i}
{@const bucketTxt =
i === density.length - 1
? `sample value ≥ ${bin}`
: `${bin} ≤ sample value ≤ ${density[i + 1][binSelector]}`}
{@const bucketTxt = buildBucketTxt(i, bin)}
{@const valTxt = ` | ${formatPercent(value)} of samples (${formatCompact(
sampleCount * value
)})`}
Expand Down
15 changes: 12 additions & 3 deletions src/components/explore/DistributionComparisonGraph.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@
import { quantile } from 'd3-array';
import DataGraphic from '../datagraphic/DataGraphic.svelte';
import { distributionComparisonGraph } from '../../utils/constants';
import { store } from '../../state/store';

export let innerHeight;
export let innerWidth;
export let topTick;
export let tickIncrement;
export let key = Math.random().toString(36).substring(7);
export let activeCategoricalProbeLabels;

export let density = [];

let probeKind = $store.probe.details.kind;
let bins =
probeKind === 'categorical'
? activeCategoricalProbeLabels
: density.map((d) => d.bin);

export let xTickFormatter = (t) =>
Intl.NumberFormat('en', { notation: 'compact' }).format(t);
probeKind !== 'categorical'
? Intl.NumberFormat('en', { notation: 'compact' }).format(t)
: t;
export let yTickFormatter = (t) =>
Intl.NumberFormat('en-US', {
style: 'percent',
maximumFractionDigits: 2,
}).format(t);

let bins = density.map((d) => d.bin);

const getXTicks = (data) => {
// for probes with too many data points, we only want to get
// a limited amount of ticks to avoid crowding the x axis
Expand Down
1 change: 1 addition & 0 deletions src/components/explore/ProbeExplorer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
topChartData={distViewTopChartData}
bottomChartData={distViewBottomChartData}
{distViewButtonId}
keySet={activeBins}
>
<div slot="comparisonSummary" class="dist-comp-percentile-tbl">
<ComparisonSummary
Expand Down