Skip to content

Commit

Permalink
id on texts and chart axises
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Luotonen committed May 22, 2024
1 parent 99011a4 commit 01dae7a
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 14 deletions.
6 changes: 6 additions & 0 deletions packages/abstract-chart/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [7.2.0] - 2024-05-22

### Added

- Support for id on abstract chart axises

## [7.1.0] - 2024-05-10

### Added
Expand Down
16 changes: 10 additions & 6 deletions packages/abstract-chart/src/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type AxisBase = {
readonly axisColor?: AI.Color;
readonly tickFontSize?: number;
readonly axisFontSize?: number;
readonly id?: string;
};

export type LinearAxis = AxisBase & { readonly type: "linear"; readonly min: number; readonly max: number };
Expand All @@ -25,9 +26,10 @@ export function createLinearAxis(
labelRotation?: number,
tickLabelDisp?: number,
thickness?: number,
axisColor?: AI.Color
axisColor?: AI.Color,
id?: string
): LinearAxis {
return { type: "linear", min, max, label, labelColor, labelRotation, tickLabelDisp, thickness, axisColor };
return { type: "linear", min, max, label, labelColor, labelRotation, tickLabelDisp, thickness, axisColor, id };
}

export type LogarithmicAxis = AxisBase & { readonly type: "logarithmic"; readonly min: number; readonly max: number };
Expand All @@ -40,9 +42,10 @@ export function createLogarithmicAxis(
labelRotation?: number,
tickLabelDisp?: number,
thickness?: number,
axisColor?: AI.Color
axisColor?: AI.Color,
id?: string
): LogarithmicAxis {
return { type: "logarithmic", min, max, labelColor, label, labelRotation, tickLabelDisp, thickness, axisColor };
return { type: "logarithmic", min, max, labelColor, label, labelRotation, tickLabelDisp, thickness, axisColor, id };
}

export type DiscreteAxis = AxisBase & { readonly type: "discrete"; readonly points: ReadonlyArray<DiscreteAxisPoint> };
Expand All @@ -59,9 +62,10 @@ export function createDiscreteAxis(
labelRotation?: number,
tickLabelDisp?: number,
thickness?: number,
axisColor?: AI.Color
axisColor?: AI.Color,
id?: string
): DiscreteAxis {
return { type: "discrete", points, labelColor, label, labelRotation, tickLabelDisp, thickness, axisColor };
return { type: "discrete", points, labelColor, label, labelRotation, tickLabelDisp, thickness, axisColor, id };
}

const linearMultiples = [1, 2, 5];
Expand Down
6 changes: 4 additions & 2 deletions packages/abstract-chart/src/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,8 @@ export function generateXAxisLabel(
verticalGrowthDirection,
0,
axis.labelColor ?? AI.black,
false
false,
axis.id
);
}

Expand Down Expand Up @@ -756,7 +757,8 @@ export function generateYAxisLabel(
verticalGrowthDirection,
0,
axis.labelColor ?? AI.black,
false
false,
axis.id
);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/abstract-image/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [8.1.0] - 2024-05-22

### Added

- Support for id on text components

## [8.0.0] - 2024-05-19

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ function Component({ component }: { readonly component: AbstractImage.Component
{tSpans}
</text>
)}
<text style={{ ...baseStyle, fill: colorToRgb(component.textColor) }} transform={transform}>
<text
style={{ ...baseStyle, fill: colorToRgb(component.textColor) }}
transform={transform}
id={makeIdAttr(component.id)}
>
{tSpans}
</text>
</>
Expand Down
5 changes: 4 additions & 1 deletion packages/abstract-image/src/model/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export interface Text {
readonly strokeThickness: number;
readonly strokeColor: Color.Color;
readonly italic: boolean;
readonly id: string | undefined;
}

export function createText(
Expand All @@ -240,7 +241,8 @@ export function createText(
verticalGrowthDirection: GrowthDirection,
strokeThickness: number,
strokeColor: Color.Color,
italic: boolean
italic: boolean,
id?: string
): Text {
return {
type: "text",
Expand All @@ -257,6 +259,7 @@ export function createText(
strokeThickness,
strokeColor,
italic,
id,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,28 @@ function generateLineChart(hovered: string): AbstractChart.Chart {
label: "Point",
}),
],
xAxisBottom: AbstractChart.createLinearAxis(xMin, xMax, "Days with cold"),
yAxisLeft: AbstractChart.createLinearAxis(yMin, yMax + 1, "Badness"),
xAxisBottom: AbstractChart.createLinearAxis(
xMin,
xMax,
"Days with cold",
undefined,
undefined,
undefined,
undefined,
undefined,
"x-bottom"
),
yAxisLeft: AbstractChart.createLinearAxis(
yMin,
yMax + 1,
"Badness",
undefined,
undefined,
undefined,
undefined,
undefined,
"y-left"
),
labelLayout: "center",
textOutlineColor: AbstractImage.white,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const pngEncoded =
"iVBORw0KGgoAAAANSUhEUgAAAMgAAACWCAIAAAAUvlBOAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAwaSURBVHhe7Z0/T9tcG4d5X8WWW0OU0MgFKRKKGnXojL8BUhFTN8asMLwLYmNmq1g6lJWRrVNFpXyDZO5QpYqQIkGj9EmUJ24t28NrJy6N49uxj+1DnPC7FOlxeKgJ9sV93+ePz/nPz3J1DYC0+a/7XwBSBWIBLkAswAWIBbgAsQAXIBbgAsQCXIBYgAsQC3ABYgEuQCzABYgFuACxABcgFuACxAJcgFiACxALcAFiAS5ALMAFiAW4ALEAFyAW4ALEAlyAWIALEAtwAU9Ch2GZdV37bI6+mmsNQ3e/OEYVpbU18c1z8UCS93KC+1UwJjWx6v3Ooea57gSipNp3QhAPNiLdifaoezwYNtx3fxClWv7lhRThRurd/d7UPxfz55vKUc59F4ZZH/Xf+396MKqYP90swrAJKYmld1/0hu5xVCRVLn4syhX3rQ9rsH/fC7qvamHnZj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FZQmeIgnW/Ez4PUU6lM/WF0mqZ7EySFTJ0TGsbwrHe7e//3fu/e351pelrN1bmwDHSyk2Wx7Lvin/o3JuVhHOYT0tkwYHinsl6ePBiYEDxXmCLE1D+blKczxDghnQ0DY4DzYODWdi2RGAExlewwywApiZWTZ9YacNbHCrgQ3u+UVJmeqDRhb8N3P8T5z7rYLnqfsp/5JL47oYol9odnhLd5fxCS5k1HyckXSrXp6MXW6LCv5Hlppxn0RHyucCqznfAPiWaFhIIV/RZDW9e+/NY+OXP3dO96cZKzWIMgvhPkqiQ++RX9APCS8RoLLCsQC3ABYgEuQCzABYgFuACxABcgFuACxAJcgFiACxALcAFiAS5ALMAFiAW4ALEAFyAW4ALEAlyAWIALEAtwAWIBLkAswAWIBbgAsQAXIBbgAsQCHFhb+z9FDDmDWJC9LAAAAABJRU5ErkJggg==";

export function AbstractImageExampleReact(): JSX.Element {
const [hovered, setHovered] = React.useState("");
const subComponents = [
AbstractImage.createLine(
AbstractImage.createPoint(0, 0),
Expand Down Expand Up @@ -64,7 +65,7 @@ export function AbstractImageExampleReact(): JSX.Element {
AbstractImage.transparent
),
AbstractImage.createText(
AbstractImage.createPoint(60, 50),
AbstractImage.createPoint(120, 50),
"Hej<sub>12</sub>",
"Helvetica",
12,
Expand All @@ -76,7 +77,8 @@ export function AbstractImageExampleReact(): JSX.Element {
"uniform",
0,
AbstractImage.black,
false
false,
"my-text"
),
];
const image = AbstractImage.createAbstractImage(
Expand All @@ -87,11 +89,13 @@ export function AbstractImageExampleReact(): JSX.Element {
);
const svg = AbstractImage.createReactSvg(image, {
onClick: (id, position) => window.alert(JSON.stringify({ id, position })),
onMouseMove: (id) => setHovered(id ?? ""),
});
return (
<div>
<h1>React</h1>
<div>{svg}</div>
<div>{hovered}</div>
</div>
);
}

0 comments on commit 01dae7a

Please sign in to comment.