rename to xAxisType

This commit is contained in:
Conor Barnes 2022-09-06 14:30:52 -03:00
parent 3ea747fae4
commit 6c87a9e712
4 changed files with 20 additions and 13 deletions

View File

@ -32,7 +32,7 @@ export type DistributionChartProps = {
width?: number; width?: number;
height: number; height: number;
sample?: boolean; sample?: boolean;
xAxis?: "number" | "dateTime"; xAxisType?: "number" | "dateTime";
} & DistributionPlottingSettings; } & DistributionPlottingSettings;
export function defaultPlot(distribution: Distribution): Plot { export function defaultPlot(distribution: Distribution): Plot {
@ -56,7 +56,7 @@ export const DistributionChart: React.FC<DistributionChartProps> = (props) => {
width, width,
logX, logX,
actions = false, actions = false,
xAxis = "number", xAxisType = "number",
} = props; } = props;
const [sized] = useSize((size) => { const [sized] = useSize((size) => {
const shapes = flattenResult( const shapes = flattenResult(

View File

@ -52,7 +52,7 @@ export interface SquiggleChartProps {
/** Specify the upper bound of the x scale */ /** Specify the upper bound of the x scale */
maxX?: number; maxX?: number;
/** Whether the x-axis should be dates or numbers */ /** Whether the x-axis should be dates or numbers */
xAxis?: "number" | "dateTime"; xAxisType?: "number" | "dateTime";
/** Whether to show vega actions to the user, so they can copy the chart spec */ /** Whether to show vega actions to the user, so they can copy the chart spec */
distributionChartActions?: boolean; distributionChartActions?: boolean;
enableLocalSettings?: boolean; enableLocalSettings?: boolean;
@ -81,7 +81,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = React.memo(
maxX, maxX,
color, color,
title, title,
xAxis = "number", xAxisType = "number",
distributionChartActions, distributionChartActions,
enableLocalSettings = false, enableLocalSettings = false,
}) => { }) => {
@ -103,7 +103,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = React.memo(
maxX, maxX,
color, color,
title, title,
xAxis, xAxisType,
actions: distributionChartActions, actions: distributionChartActions,
}; };

View File

@ -17,10 +17,10 @@ export type DistributionChartSpecOptions = {
/** Whether or not to show the band of sample data at the bottom */ /** Whether or not to show the band of sample data at the bottom */
sample?: boolean; sample?: boolean;
/** Whether the x-axis should be dates or numbers */ /** Whether the x-axis should be dates or numbers */
xAxis?: "number" | "dateTime"; xAxisType?: "number" | "dateTime";
}; };
/** X Scales */ /** X Scales */
export const linearXScale: LinearScale = { export const linearXScale: LinearScale = {
name: "xscale", name: "xscale",
clamp: true, clamp: true,
@ -51,7 +51,7 @@ export const timeXScale: TimeScale = {
domain: { data: "domain", field: "x" }, domain: { data: "domain", field: "x" },
}; };
/** Y Scales */ /** Y Scales */
export const linearYScale: LinearScale = { export const linearYScale: LinearScale = {
name: "yscale", name: "yscale",
type: "linear", type: "linear",
@ -77,9 +77,16 @@ const width = 500;
export function buildVegaSpec( export function buildVegaSpec(
specOptions: DistributionChartSpecOptions specOptions: DistributionChartSpecOptions
): VisualizationSpec { ): VisualizationSpec {
const { title, minX, maxX, logX, expY, xAxis = "number" } = specOptions; const {
title,
minX,
maxX,
logX,
expY,
xAxisType = "number",
} = specOptions;
const dateTime = xAxis === "dateTime"; const dateTime = xAxisType === "dateTime";
// some fallbacks // some fallbacks
const format = specOptions?.format const format = specOptions?.format
@ -270,13 +277,13 @@ export function buildVegaSpec(
tooltip: { tooltip: {
signal: dateTime signal: dateTime
? "{ probability: datum.y, value: datetime(datum.x) }" ? "{ probability: datum.y, value: datetime(datum.x) }"
: "{ probability: datum.y, value: datum.x }", : "{ probability: datum.y, value: datum.x }",
}, },
}, },
update: { update: {
x: { x: {
scale: "xscale", scale: "xscale",
field: "x", field: "x",
offset: 0.5, // if this is not included, the circles are slightly left of center. offset: 0.5, // if this is not included, the circles are slightly left of center.
}, },
y: { y: {

View File

@ -87,7 +87,7 @@ could be continuous, discrete or mixed.
args={{ args={{
code: "mx(1661819770311, 1661829770311, 1661839770311)", code: "mx(1661819770311, 1661829770311, 1661839770311)",
width, width,
xAxis: "dateTime", xAxisType: "dateTime",
width, width,
}} }}
> >