Skip to content

Commit

Permalink
Add option to force 0 based origin
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal committed Feb 7, 2025
1 parent f92f052 commit 6f3ecdb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
8 changes: 5 additions & 3 deletions web-common/src/features/canvas/components/charts/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ export function createYEncoding(
field: sanitizeValueForVega(config.y.field),
title: metaData?.displayName || config.y.field,
type: config.y.type,
scale: {
zero: false,
},
...(config.y.zeroBasedOrigin !== true && {
scale: {
zero: false,
},
}),
axis: {
...(config.y.type === "quantitative" && {
formatType: config.y.field,
Expand Down
3 changes: 1 addition & 2 deletions web-common/src/features/canvas/components/charts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type { ComponentType, SvelteComponent } from "svelte";

export interface FieldConfig {
field: string;
label?: string;
format?: string;
showAxisTitle?: boolean; // Default is false
zeroBasedOrigin?: boolean; // Default is false
type: "quantitative" | "ordinal" | "nominal" | "temporal";
timeUnit?: string; // For temporal fields
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@
>
<span class="ml-2">Show axis title</span>
</DropdownMenu.CheckboxItem>
{#if !isDimension}
<DropdownMenu.CheckboxItem
checked={fieldConfig?.zeroBasedOrigin}
on:click={async () => {
updateFieldProperty(
"zeroBasedOrigin",
!fieldConfig?.zeroBasedOrigin,
);
}}
>
<span class="ml-2">Zero based origin</span>
</DropdownMenu.CheckboxItem>
{/if}
</DropdownMenu.Content>
</DropdownMenu.Root>
</div>
Expand Down

0 comments on commit 6f3ecdb

Please sign in to comment.