Skip to content

Commit

Permalink
feat(label): implement label color inheritance from dependent elements (
Browse files Browse the repository at this point in the history
#6536)

* feat(label): implement label color inheritance from dependent elements

Implement the ability for labels to inherit colors from their associated
graphical elements. This allows labels to automatically match the color
of the elements they are describing.

- Add style inheritance in label creation
- Pass element style information to label callbacks
- Add test case to verify the implementation

* refactor(label): improve style callback compatibility and clarity

- Remove Proxy usage in label style callback to prevent browser compatibility issues
- Rename style parameter to elementStyle for better semantic clarity
- Update documentation to clarify elementStyle parameter usage in label callbacks

* refactor: simplify object property using shorthand notation
  • Loading branch information
BQXBQX authored Dec 5, 2024
1 parent 9e57dfe commit 56c0a3e
Show file tree
Hide file tree
Showing 6 changed files with 1,687 additions and 4 deletions.
35 changes: 35 additions & 0 deletions __tests__/integration/issue-5474.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { issue5474 as render } from '../plots/bugfix/issue-5474';
import { createNodeGCanvas } from './utils/createNodeGCanvas';
import { sleep } from './utils/sleep';
import './utils/useSnapshotMatchers';

describe('issue5474', () => {
const canvas = createNodeGCanvas(800, 500);

it('issue5474.render() should render chart with labels matching element colors', async () => {
const { chart } = render({
canvas,
container: document.createElement('div'),
});

await chart.render();
await sleep(20);

const labels = canvas.document.getElementsByClassName('label');
expect(labels.length).toBeGreaterThan(0);

labels.forEach((label) => {
expect(label.style.fill).toBe(
// @ts-ignore
label.__data__.dependentElement.attributes.fill,
);
});

const dir = `${__dirname}/snapshots/bugfix`;
await expect(canvas).toMatchDOMSnapshot(dir, render.name);
});

afterAll(() => {
canvas?.destroy();
});
});
Loading

0 comments on commit 56c0a3e

Please sign in to comment.