-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor index.ts file to extract methods (#65)
* Update getSorts method * Extract derivePlotOptions to separate file * Add mockDuckPlot and derivePlotOptions files * Pass instance to processRawData * Pass instance to preprareChartData * Move getMarkOptions to own file * Move click even to legendCategorical * Pass instance into legendContinuous * Move handleProperty to its own file * Organize into folders * Remove unused import * Move getMarks to its own file * Rename markType to mark * Move visibleSeries default logic into legendCategorical * Extract render into its own file * Add some light error handling * Remove getter/setters that just reset variables * Fix error catchign * Rename chartData to data, fix tests * Reorganize functions * Reorganizing * Clarify primaryMark logic, pass through r and fx options * Remove mock-duck plot, make options sync functions
- Loading branch information
Showing
26 changed files
with
948 additions
and
768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ duckplot | |
.color("Open") | ||
.mark("dot") | ||
.options({ | ||
width: 600, | ||
color: { | ||
scheme: "blues" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { renderPlot } from "../util/renderPlotClient.js"; | ||
// This code is both displayed in the browser and executed | ||
const codeString = `// No mark specified so render should error | ||
duckplot | ||
.table("stocks") | ||
.x("Date") | ||
.y("Close") | ||
.fy("Symbol") | ||
.options({ height: 300}) | ||
`; | ||
|
||
export const error = (options) => renderPlot("stocks.csv", codeString, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { PlotOptions } from "@observablehq/plot"; | ||
import type { DuckPlot } from "."; | ||
import { IncomingColumType, PlotProperty } from "./types"; | ||
import equal from "fast-deep-equal"; | ||
import { isColor } from "./options/getPlotOptions"; | ||
|
||
export function handleProperty<T extends keyof PlotOptions>( | ||
instance: DuckPlot, | ||
prop: PlotProperty<T>, | ||
column?: IncomingColumType, | ||
options?: PlotOptions[T], | ||
propertyName?: string | ||
): PlotProperty<T> | DuckPlot { | ||
// Because we store empty string for falsey values, we need to check them | ||
const columnValue = column === false || column === null ? "" : column; | ||
|
||
if (column !== undefined && !equal(columnValue, prop.column)) { | ||
// Special case handling that we don't need data if color is/was a color | ||
if ( | ||
!( | ||
propertyName === "color" && | ||
isColor(prop.column) && | ||
typeof column === "string" && | ||
isColor(column) | ||
) | ||
) { | ||
instance.newDataProps = true; // When changed, we need to requery the data | ||
} | ||
} | ||
if (column === false || column === null) { | ||
prop.column = ""; | ||
prop.options = undefined; | ||
} else { | ||
if (column !== undefined) prop.column = column; | ||
if (options !== undefined) prop.options = options; | ||
} | ||
return column === undefined ? prop : instance; | ||
} |
Oops, something went wrong.