Skip to content

Commit 2490b9d

Browse files
committed
Merge remote-tracking branch 'origin/main' into 68-soundings-in-plot
2 parents 604d00c + edf3e1f commit 2490b9d

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

apps/class-solid/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "class-solid",
33
"private": true,
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"type": "module",
66
"scripts": {
77
"dev": "vinxi dev",

apps/class-solid/src/components/plots/ChartContainer.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from "solid-js";
99
import { type SetStoreFunction, createStore } from "solid-js/store";
1010

11-
type SupportedScaleTypes =
11+
export type SupportedScaleTypes =
1212
| d3.ScaleLinear<number, number, never>
1313
| d3.ScaleLogarithmic<number, number, never>;
1414
const supportedScales = {
@@ -34,6 +34,7 @@ interface Chart {
3434
scaleY: SupportedScaleTypes;
3535
formatX: (value: number) => string;
3636
formatY: (value: number) => string;
37+
transformX?: (x: number, y: number, scaleY: SupportedScaleTypes) => number;
3738
}
3839
type SetChart = SetStoreFunction<Chart>;
3940
const ChartContext = createContext<[Chart, SetChart]>();
@@ -95,6 +96,7 @@ export function Chart(props: {
9596
title?: string;
9697
formatX?: (value: number) => string;
9798
formatY?: (value: number) => string;
99+
transformX?: (x: number, y: number, scaleY: SupportedScaleTypes) => number;
98100
}) {
99101
const [hovering, setHovering] = createSignal(false);
100102
const [coords, setCoords] = createSignal<[number, number]>([0, 0]);
@@ -108,12 +110,20 @@ export function Chart(props: {
108110
if (props.formatY) {
109111
updateChart("formatY", () => props.formatY);
110112
}
113+
if (props.transformX) {
114+
updateChart("transformX", () => props.transformX);
115+
}
116+
117+
const onMouseMove = (e: MouseEvent) => {
118+
let x = e.offsetX - marginLeft;
119+
const y = e.offsetY - marginTop;
120+
121+
if (chart.transformX) {
122+
x = chart.transformX(x, y, chart.scaleY);
123+
}
111124

112-
const onMouseMove = (e: MouseEvent) =>
113-
setCoords([
114-
chart.scaleX.invert(e.offsetX - marginLeft),
115-
chart.scaleY.invert(e.offsetY - marginTop),
116-
]);
125+
setCoords([chart.scaleX.invert(x), chart.scaleY.invert(y)]);
126+
};
117127

118128
const renderXCoord = () =>
119129
hovering() ? `x: ${chart.formatX(coords()[0])}` : "";

apps/class-solid/src/components/plots/skewTlogP.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
import * as d3 from "d3";
33
import { For, createSignal } from "solid-js";
44
import { AxisBottom, AxisLeft } from "./Axes";
5-
import type { ChartData } from "./ChartContainer";
5+
import type { ChartData, SupportedScaleTypes } from "./ChartContainer";
66
import { Chart, ChartContainer, useChartContext } from "./ChartContainer";
77
import { Legend } from "./Legend";
8-
98
interface SoundingRecord {
109
p: number;
1110
T: number;
@@ -17,6 +16,10 @@ const tan = Math.tan(55 * deg2rad);
1716
const basep = 1050;
1817
const topPressure = 100;
1918

19+
function getTempAtCursor(x: number, y: number, scaleY: SupportedScaleTypes) {
20+
return x + 0.5 - (scaleY(basep) - y) / tan;
21+
}
22+
2023
function ClipPath() {
2124
const [chart, updateChart] = useChartContext();
2225

@@ -152,6 +155,7 @@ export function SkewTPlot({
152155
title="Thermodynamic diagram"
153156
formatX={d3.format(".0d")}
154157
formatY={d3.format(".0d")}
158+
transformX={getTempAtCursor}
155159
>
156160
<AxisBottom
157161
domain={() => [-45, 50]}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"scripts": {
55
"build": "turbo build",
66
"dev": "turbo dev",

packages/class/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@classmodel/class",
33
"description": "Chemistry Land-surface Atmosphere Soil Slab (CLASS) model",
44
"type": "module",
5-
"version": "0.1.2",
5+
"version": "0.1.3",
66
"exports": {
77
"./package.json": "./package.json",
88
"./class": {

packages/form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@classmodel/form",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Generate form from JSON schema with Solid UI components",
55
"type": "module",
66
"repository": {

0 commit comments

Comments
 (0)