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

fix: change implementation color function (#2054) #2183

Merged
merged 2 commits into from
Aug 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -268,23 +268,13 @@ function addTemplateTrack(
return templateNew;
}

// Custom function to demonstrate the ability to specify a function instead of color tables
function colorTableFunc(v: number): [number, number, number] {
if (v >= 0 && v < 0.25) return [255, 0.0, 0.0];
else if (v >= 0.25 && v < 0.5) return [182, 182, 0.0];
else if (v >= 0.5 && v < 0.75) return [0.0, 255, 0.0];
else if (v >= 0.75 && v < 1) return [0.0, 182, 182];
else if (v == 1) return [0.0, 0.0, 255];
else return [0, 0, 0];
}

export const Default: StoryObj<typeof StoryTemplate> = {
args: {
id: "Well-Log-Viewer",
horizontal: false,
welllog: require("../../../../example-data/L898MUD.json")[0], // eslint-disable-line
template: require("../../../../example-data/welllog_template_1.json"), // eslint-disable-line
colorTables: colorTableFunc,
colorTables: colorTables,
wellpick: wellpick,
axisTitles: axisTitles,
axisMnemos: axisMnemos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ export function createBooleanItems(): ReactNode[] {

function createColorTableItems(colorTables: ColorTable[]): ReactNode[] {
const nodes: ReactNode[] = [];

if (typeof colorTables === "function") {
nodes.push(<option key="Function"> Function </option>);
return nodes;
}

if (!colorTables) {
console.error(
"colorTables is missed or empty in createColorTableItems()"
Expand Down Expand Up @@ -223,10 +217,7 @@ export class PlotPropertiesDialog extends Component<Props, State> {

// for 'gradientfill' plot
colorTable:
typeof this.props.wellLogView.props.colorTables ===
"function"
? "Function"
: this.props.wellLogView.props.colorTables?.[0]?.name,
this.props.wellLogView.props.colorTables?.[0]?.name,
inverseColorTable: undefined,
colorScale: undefined,
inverseColorScale: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export type TemplatePlotProps = {

fill?: CSSColor; // for 'area' plot
fillOpacity?: number; // for 'area' and 'gradientfill' plots! default 0.25
colorTable?: string; // table id (name) for 'gradientfill' plot
inverseColorTable?: string; // table id (name) for 'gradientfill' plot
colorTable?: string | ((v: number) => [number, number, number]); // table id (name) for 'gradientfill' plot
inverseColorTable?: string | ((v: number) => [number, number, number]); // table id (name) for 'gradientfill' plot
colorScale?: TemplatePlotScaleTypes; // for 'linear' plot scale. default equal to plot scale
inverseColorScale?: TemplatePlotScaleTypes; // for 'linear' plot scale. default equal to plot scale

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { color4ToString } from "./color-table";
let __idGradient = 0;
function createGradient(
g: D3Selection,
colorTable: ColorTable,
colorTable: ColorTable | ((v: number) => [number, number, number]),
rLogarithmic?: number
): string {
const id = "grad" + ++__idGradient; // generate unique id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import type { ColorTable } from "../components/ColorTableTypes";
import type { AreaPlotOptions } from "@equinor/videx-wellog/dist/plots/interfaces";

export interface GradientFillPlotOptions extends AreaPlotOptions {
colorTable?: ColorTable;
inverseColorTable?: ColorTable;
colorTable?: ColorTable | ((v: number) => [number, number, number]);
inverseColorTable?: ColorTable | ((v: number) => [number, number, number]);
colorScale?: "linear" | "log";
inverseColorScale?: "linear" | "log";
}
Expand All @@ -27,7 +27,7 @@ function createGradient(
horizontal: boolean | undefined,
plotdata: number[][],
xscale: Scale,
colorTable: ColorTable,
colorTable: ColorTable | ((v: number) => [number, number, number]),
scale: undefined | string // "linear" | "log"
): CanvasGradient {
const dataFrom = plotdata[0];
Expand Down
12 changes: 6 additions & 6 deletions typescript/packages/well-log-viewer/src/utils/tracks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,18 @@ const defColorTable: ColorTable = {
};

function getColorTable(
id: string | undefined,
id: string | ((v: number) => [number, number, number]) | undefined,
colorTables?: ColorTable[]
): ColorTable | undefined {
): ColorTable | ((v: number) => [number, number, number]) | undefined {
if (id && typeof id === "function") {
return id;
}
if (id && typeof id !== "string") {
console.log("colorTable id='" + id + "' is not string");
return defColorTable;
}
if (id && colorTables) {
const colorTable =
typeof colorTables === "function"
? colorTables
: colorTables.find((value) => value.name === id);
const colorTable = colorTables.find((value) => value.name === id);
if (colorTable) return colorTable;
console.error(
"colorTable id='" + id + "' is not found in getColorTable()"
Expand Down
Loading