samples in own shape

This commit is contained in:
Conor Barnes 2022-09-07 09:18:01 -03:00
parent 00a0005e56
commit 0c614a3fcf
3 changed files with 22 additions and 47 deletions

View File

@ -32,7 +32,6 @@ export type DistributionChartProps = {
environment: environment; environment: environment;
width?: number; width?: number;
height: number; height: number;
sample?: boolean;
xAxisType?: "number" | "dateTime"; xAxisType?: "number" | "dateTime";
} & DistributionPlottingSettings; } & DistributionPlottingSettings;
@ -64,7 +63,7 @@ export const DistributionChart: React.FC<DistributionChartProps> = (props) => {
name: x.name, name: x.name,
// color: x.color, // not supported yet // color: x.color, // not supported yet
...pointSet.asShape(), ...pointSet.asShape(),
samples: [] as number[], // samples: [] as number[],
})) }))
) )
); );
@ -78,6 +77,7 @@ export const DistributionChart: React.FC<DistributionChartProps> = (props) => {
} }
// if this is a sample set, include the samples // if this is a sample set, include the samples
const samples: number[] = [];
const sampleSets = plot?.distributions.filter( const sampleSets = plot?.distributions.filter(
(dist) => dist.distribution.tag === SqDistributionTag.SampleSet (dist) => dist.distribution.tag === SqDistributionTag.SampleSet
); );
@ -85,7 +85,8 @@ export const DistributionChart: React.FC<DistributionChartProps> = (props) => {
for (const { distribution } of sampleSets) { for (const { distribution } of sampleSets) {
if (distribution.tag === SqDistributionTag.SampleSet) { if (distribution.tag === SqDistributionTag.SampleSet) {
// this conditional must be duplicated to please typescript, more elegant solution probably exists // this conditional must be duplicated to please typescript, more elegant solution probably exists
shapes.value[0].samples.push(...distribution.value()); samples.push(...distribution.value());
// shapes.value[0].samples.push(...distribution.value());
} }
} }
} }
@ -112,7 +113,7 @@ export const DistributionChart: React.FC<DistributionChartProps> = (props) => {
) : ( ) : (
<Vega <Vega
spec={spec} spec={spec}
data={{ data: shapes.value, domain }} data={{ data: shapes.value, domain, samples }}
width={widthProp - 10} width={widthProp - 10}
height={height} height={height}
actions={actions} actions={actions}

View File

@ -14,8 +14,6 @@ export type DistributionChartSpecOptions = {
title?: string; title?: string;
/** The formatting of the ticks */ /** The formatting of the ticks */
format?: string; format?: string;
/** Whether or not to show the band of sample data at the bottom */
sample?: boolean;
/** Whether the x-axis should be dates or numbers */ /** Whether the x-axis should be dates or numbers */
xAxisType?: "number" | "dateTime"; xAxisType?: "number" | "dateTime";
}; };
@ -77,14 +75,7 @@ const width = 500;
export function buildVegaSpec( export function buildVegaSpec(
specOptions: DistributionChartSpecOptions specOptions: DistributionChartSpecOptions
): VisualizationSpec { ): VisualizationSpec {
const { const { title, minX, maxX, logX, expY, xAxisType = "number" } = specOptions;
title,
minX,
maxX,
logX,
expY,
xAxisType = "number",
} = specOptions;
const dateTime = xAxisType === "dateTime"; const dateTime = xAxisType === "dateTime";
@ -299,40 +290,23 @@ export function buildVegaSpec(
}, },
], ],
}, },
{ ],
name: "sample_distributions",
type: "group",
from: {
facet: {
name: "sample_facet",
data: "distribution_facet",
field: "samples",
}, },
},
marks: [
{ {
name: "samples", name: "sampleset",
type: "rect", type: "rect",
from: { data: "sample_facet" }, from: { data: "samples" },
encode: { encode: {
enter: { enter: {
x: { scale: "xscale", field: "data"}, x: { scale: "xscale", field: "data" },
width: { value: 0.1 }, width: { value: 0.1 },
y: { value: 25, offset: { signal: "height" } }, y: { value: 25, offset: { signal: "height" } },
height: { value: 5 }, height: { value: 5 },
fill: {
scale: "color",
field: { parent: "name" },
},
fillOpacity: { value: 1 },
}, },
}, },
}, },
],
},
],
},
{ {
type: "text", type: "text",
name: "announcer", name: "announcer",