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

Enable tick marks #51

Merged
merged 1 commit into from
Nov 12, 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
1 change: 1 addition & 0 deletions examples/plots/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export * from "./rawData.js";
export * from "./sortXbyY.js";
export * from "./sortYbyX.js";
export * from "./text.js";
export * from "./tick.js";
export * from "./xLabelRotate.js";
2 changes: 1 addition & 1 deletion examples/plots/line.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderPlot } from "../util/renderPlotClient.js";
// This code is both displayed in the browser and executed
const codeString = `// Standard area chart
const codeString = `// Standard line chart
duckplot
.table("stocks")
.x("Date")
Expand Down
11 changes: 11 additions & 0 deletions examples/plots/tick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { renderPlot } from "../util/renderPlotClient.js";
// This code is both displayed in the browser and executed
const codeString = `duckplot
.table("stocks")
.x("Date")
.fy("Symbol")
.color("Close")
.mark("tickX")
`;

export const tick = (options) => renderPlot("stocks.csv", codeString, options);
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,12 @@ export class DuckPlot {
// Here, we want to add the primary mark if x and y are defined OR if an
// aggregate has been specifid. Not a great rule, but works for now for
// showing aggregate marks with only one dimension
const isValidTickChart =
(this._mark.markType === "tickX" && currentColumns.includes("x")) ||
(this._mark.markType === "tickY" && currentColumns.includes("y"));

const primaryMark =
!isValidTickChart &&
(!currentColumns.includes("x") || !currentColumns.includes("y")) &&
!this._config.aggregate
? []
Expand Down
10 changes: 9 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import type { MarkOptions, PlotOptions } from "@observablehq/plot";

// TODO: all plot chart types?
export type ChartType = "dot" | "areaY" | "line" | "barX" | "barY" | "text";
export type ChartType =
| "dot"
| "areaY"
| "line"
| "barX"
| "barY"
| "text"
| "tickX"
| "tickY";

export type SqlSort = {
column: string;
Expand Down