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

feat(graph): add component tokens #11355

Merged
merged 1 commit into from
Jan 24, 2025
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
53 changes: 40 additions & 13 deletions packages/calcite-components/src/components/graph/graph.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
import { newE2EPage, E2EPage } from "@arcgis/lumina-compiler/puppeteerTesting";
import { describe, expect, it, beforeEach } from "vitest";
import { accessible, defaults, hidden, renders } from "../../tests/commonTests";
import { accessible, defaults, hidden, renders, themed } from "../../tests/commonTests";
import { html } from "../../../support/formatting";
import type { Graph } from "./graph";
import { CSS } from "./resources";

async function createGraphWithData(): Promise<E2EPage> {
const page = await newE2EPage();
await page.setContent(html`<calcite-graph highlight-min="25" highlight-max="75"></calcite-graph>`);
await page.$eval("calcite-graph", (el: Graph["el"]) => {
el.data = [
[0, 0],
[10, 80],
[20, 20],
[30, 30],
[40, 42],
[50, 50],
[60, 55],
[70, 48],
[80, 30],
[90, 10],
[100, 0],
];
});
await page.waitForChanges();
return page;
}

describe("calcite-graph", () => {
describe("renders", () => {
Expand All @@ -20,18 +44,7 @@ describe("calcite-graph", () => {
let page: E2EPage;

beforeEach(async () => {
page = await newE2EPage();
await page.setContent("<calcite-graph></calcite-graph>");
await page.$eval("calcite-graph", (el: Graph["el"]) => {
el.data = [
[0, 4],
[1, 7],
[4, 6],
[6, 2],
];
});

await page.waitForChanges();
page = await createGraphWithData();
});

accessible(() => ({ tag: "calcite-graph", page }));
Expand Down Expand Up @@ -92,4 +105,18 @@ describe("calcite-graph", () => {

expect(fill).toBe(`url(#${linearGradientId})`);
});

describe("theme", () => {
themed(
async () => {
return { tag: "calcite-graph", page: await createGraphWithData() };
},
{
"--calcite-graph-highlight-fill-color": {
shadowSelector: `.${CSS.graphPathHighlight}`,
targetProp: "fill",
},
},
);
});
});
10 changes: 9 additions & 1 deletion packages/calcite-components/src/components/graph/graph.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* CSS Custom Properties
*
* These properties can be overridden using the component's tag as selector.
*
* @prop --calcite-graph-highlight-fill-color: Specifies the fill color of the `highlight` element, when present.
*/

:host {
@apply block;
block-size: 100%;
Expand All @@ -9,7 +17,7 @@
@apply m-0 block h-full w-full p-0;

.graph-path--highlight {
fill: var(--calcite-color-brand);
fill: var(--calcite-graph-highlight-fill-color, var(--calcite-color-brand));
@apply opacity-50;
}
}
Expand Down
13 changes: 7 additions & 6 deletions packages/calcite-components/src/components/graph/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createObserver } from "../../utils/observers";
import { ColorStop, DataSeries, Point } from "./interfaces";
import { area, range, translate } from "./util";
import { styles } from "./graph.scss";
import { CSS } from "./resources";

declare global {
interface DeclareElements {
Expand Down Expand Up @@ -87,7 +88,7 @@ export class Graph extends LitElement {
return (
<svg
ariaHidden="true"
class="svg"
class={CSS.svg}
height={height}
preserveAspectRatio="none"
viewBox={`0 0 ${width} ${height}`}
Expand Down Expand Up @@ -117,7 +118,7 @@ export class Graph extends LitElement {
return (
<svg
ariaHidden="true"
class="svg"
class={CSS.svg}
height={height}
preserveAspectRatio="none"
viewBox={`0 0 ${width} ${height}`}
Expand Down Expand Up @@ -174,12 +175,12 @@ export class Graph extends LitElement {
/>
</mask>,

<path class="graph-path" d={areaPath} fill={fill} mask={`url(#${id}1)`} />,
<path class="graph-path--highlight" d={areaPath} fill={fill} mask={`url(#${id}2)`} />,
<path class="graph-path" d={areaPath} fill={fill} mask={`url(#${id}3)`} />,
<path class={CSS.graphPath} d={areaPath} fill={fill} mask={`url(#${id}1)`} />,
<path class={CSS.graphPathHighlight} d={areaPath} fill={fill} mask={`url(#${id}2)`} />,
<path class={CSS.graphPath} d={areaPath} fill={fill} mask={`url(#${id}3)`} />,
]
) : (
<path class="graph-path" d={areaPath} fill={fill} />
<path class={CSS.graphPath} d={areaPath} fill={fill} />
)}
</svg>
);
Expand Down
5 changes: 5 additions & 0 deletions packages/calcite-components/src/components/graph/resources.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const CSS = {
svg: "svg",
graphPath: "graph-path",
graphPathHighlight: "graph-path--highlight",
};
4 changes: 3 additions & 1 deletion packages/calcite-components/src/custom-theme.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { chips, chipTokens } from "./custom-theme/chips";
import { comboboxItem } from "./custom-theme/combobox-item";
import { datePicker } from "./custom-theme/date-picker";
import { dropdown } from "./custom-theme/dropdown";
import { graph, graphTokens } from "./custom-theme/graph";
import { handle, handleTokens } from "./custom-theme/handle";
import { icon } from "./custom-theme/icon";
import { input, inputTokens } from "./custom-theme/input";
Expand Down Expand Up @@ -133,7 +134,7 @@ const kitchenSink = (args: Record<string, string>, useTestValues = false) =>
</div>
<div class="demo-column">
${datePicker} ${tabs} ${tabsBordered} ${label} ${link} ${list} ${loader} ${calciteSwitch} ${avatarIcon}
${avatarInitials} ${avatarThumbnail} ${progress} ${handle} ${textArea} ${popover} ${tile} ${tooltip}
${avatarInitials} ${avatarThumbnail} ${progress} ${handle} ${graph} ${textArea} ${popover} ${tile} ${tooltip}
${comboboxItem}
</div>
<div class="demo-column">
Expand Down Expand Up @@ -162,6 +163,7 @@ const componentTokens = {
...checkboxTokens,
...chipTokens,
...handleTokens,
...graphTokens,
...inputTokens,
...labelTokens,
...linkTokens,
Expand Down
25 changes: 25 additions & 0 deletions packages/calcite-components/src/custom-theme/graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { html } from "../../support/formatting";

export const graphTokens = {
calciteGraphHighlightFillColor: "",
};

export const graph = html`<div style="width:300px; height:100px">
<calcite-graph id="my-graph" highlight-min="25" highlight-max="75"></calcite-graph>
</div>
<script>
const data = [
[0, 0],
[10, 80],
[20, 20],
[30, 30],
[40, 42],
[50, 50],
[60, 55],
[70, 48],
[80, 30],
[90, 10],
[100, 0],
];
document.getElementById("my-graph").data = data;
</script>`;
8 changes: 8 additions & 0 deletions packages/calcite-components/src/demos/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
</div>
</div>

<!-- Themed -->
<div class="parent" style="--calcite-graph-highlight-fill-color: purple">
<div class="child right-aligned-text">Themed</div>
<div class="child">
<calcite-graph class="highlight-range color-stops"></calcite-graph>
</div>
</div>

<script>
// Fill all graphs with the same data.
const data = [
Expand Down
Loading