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

Charts as Web component #32866

Merged
merged 2 commits into from
Oct 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
@@ -1,6 +1,12 @@
import { ElementViewTemplate, html, ref, slotted } from '@microsoft/fast-element';
import { createTabster, getGroupper, getMover, getTabsterAttribute, Types } from 'tabster';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is tabster already available in package dependencies.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't find it in package.json

import type { HorizontalBarChart } from './horizontalbarchart.js';

// During the page startup.
const tabsterCore = createTabster(window);
getMover(tabsterCore);
getGroupper(tabsterCore);

/**
* Generates a template for the HorizontalBarChart component.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { attr, FASTElement } from '@microsoft/fast-element';
import * as d3 from 'd3';
import { createTabster, getGroupper, getMover, getTabsterAttribute, Types } from 'tabster';
import { IChartDataPoint, IChartProps, Variant } from './horizontalbarchart.options.js';

// During the page startup.
const tabsterCore = createTabster(window);
getMover(tabsterCore);
getGroupper(tabsterCore);

/**
* A Horizontal Bar Chart HTML Element.
*
Expand Down Expand Up @@ -202,7 +208,17 @@ export class HorizontalBarChart extends FASTElement {
.data(this.inpData!)
.enter()
.append('div')
.each((d, i, nodes) => this.createSingleChartBars(d, i, nodes));
.each((d, i, nodes) => {
this.createSingleChartBars(d, i, nodes);

//Get the tabster attributes
const attributes = getTabsterAttribute({ root: {} });

//Apply attributes directly to the current node
Object.keys(attributes).forEach(key => {
nodes[i].setAttribute(key, attributes[key]);
});
});
}

public _createBarsAndLegends(data: IChartProps, barNo?: number) {
Expand Down Expand Up @@ -302,13 +318,18 @@ export class HorizontalBarChart extends FASTElement {
)
.attr('y', 0)
.attr('width', value + '%')
.attr('height', barHeight);
.attr('height', barHeight)
.attr('style', `fill: ${point.color}`)
.attr('tabindex', 0)
.attr('data-tabster', '{"groupper": {...}}"')
.attr('data-tabster', '{"mover": {...}}"');
}

const containerDiv = d3.create('div');

const svgEle = containerDiv
.append('svg')
.attr('height', 20)
.attr('aria-label', data?.chartTitle ? data?.chartTitle : '')
.selectAll('g')
.data(data.chartData!)
Expand All @@ -333,7 +354,7 @@ export class HorizontalBarChart extends FASTElement {
}%`,
)
.attr('textAnchor', 'start')
.attr('y', this.barHeight / 2)
.attr('y', this.barHeight / 2 + 6)
.attr('dominantBaseline', 'central')
.attr('transform', `translate(${this._isRTL ? -4 : 4})`)
.attr('aria-label', `Total: ${barLabel}`)
Expand Down
Loading