WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
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
5 changes: 3 additions & 2 deletions packages/ag-charts-community/src/chart/labelUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function getLabelStyles<TParams, TDatumIndex extends DatumIndexType = Dat
params: TParams,
label: Label<TParams>,
isHighlight: boolean,
activeHighlight: HighlightNodeDatum<TDatumIndex> | undefined
activeHighlight: HighlightNodeDatum<TDatumIndex> | undefined,
labelPath: string[] = ['series', `${series.declarationOrder}`, 'label']
): AgChartLabelStyleOptions & { fontSize: number } {
if (series.visible && label.itemStyler) {
const highlightState = series.getHighlightStateString(
Expand Down Expand Up @@ -83,7 +84,7 @@ export function getLabelStyles<TParams, TDatumIndex extends DatumIndexType = Dat
};
const stylerResult =
series.ctx.optionsGraphService.resolvePartial(
['series', `${series.declarationOrder}`, 'label'],
labelPath,
series.cachedCallWithContext(label.itemStyler, { ...params, ...styleParams }),
{ pick: false }
) ?? {};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,40 @@ describe('SunburstSeries', () => {
}
});

describe('Label itemStyler', () => {
it('should style labels via itemStyler', async () => {
const options: AgChartOptions = {
data: [
{
name: 'Solar',
children: [
{ name: 'Earth', size: 60 },
{ name: 'Mars', size: 20 },
],
},
{
name: 'Gas Giants',
children: [{ name: 'Jupiter', size: 80 }],
},
],
series: [
{
type: 'sunburst',
labelKey: 'name',
sizeKey: 'size',
label: {
itemStyler: () => ({ color: 'lime' }),
},
},
],
};
prepareEnterpriseTestOptions(options);

chart = AgCharts.create(options);
await compare();
});
});

const testPointerEvents = (testParams: {
seriesOptions: any;
chartOptions?: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ export class SunburstSeries extends _ModuleSupport.HierarchySeries<
text.fontStyle = label.fontStyle;
text.fontFamily = label.fontFamily;
text.fontWeight = label.fontWeight;
text.fill = label.color;
text.fillOpacity = highlightOpacity ?? 1;
text.fill = style.color;
text.setBoxing(style);

switch (labelPlacement) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,46 @@ describe('TreemapSeries', () => {
}
});

describe('Label itemStyler', () => {
it('should style labels via itemStyler', async () => {
const options: AgChartOptions = {
data: [
{
name: 'Group',
children: [
{ name: 'Alpha', size: 6 },
{ name: 'Beta', size: 4 },
],
},
],
series: [
{
type: 'treemap',
labelKey: 'name',
sizeKey: 'size',
tile: {
label: {
enabled: true,
itemStyler: () => ({ color: 'lime' }),
},
},
group: {
label: {
enabled: true,
itemStyler: () => ({ color: 'lime' }),
},
},
},
],
animation: { enabled: false },
};
prepareEnterpriseTestOptions(options);

chart = AgCharts.create(options);
await compare();
});
});

const testPointerEvents = (testParams: {
seriesOptions: any;
chartOptions?: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,15 @@ export class TreemapSeries extends _ModuleSupport.HierarchySeries<
text.visible = false;
return;
}
const labelProps = tag === TextNodeTag.Primary ? tile.label : tile.secondaryLabel;
let labelProps;
let labelPath: string[];
if (tag === TextNodeTag.Primary) {
labelProps = isLeaf ? tile.label : group.label;
labelPath = ['series', `${this.declarationOrder}`, isLeaf ? 'tile' : 'group', 'label'];
} else {
labelProps = tile.secondaryLabel;
labelPath = ['series', `${this.declarationOrder}`, 'tile', 'secondaryLabel'];
}

const { opacity: highlightOpacity } = this.getItemStyle(node, isLeaf, highlighted) ?? {};

Expand All @@ -706,20 +714,20 @@ export class TreemapSeries extends _ModuleSupport.HierarchySeries<
sizeName: this.properties.sizeName ?? this.properties.sizeKey,
};
const activeHighlight = this.ctx.highlightManager?.getActiveHighlight();
const style = getLabelStyles(this, node, params, labelProps, highlighted, activeHighlight);
const style = getLabelStyles(this, node, params, labelProps, highlighted, activeHighlight, labelPath);
text.text = label.text;
text.fontSize = label.fontSize;
text.lineHeight = label.lineHeight;
text.fontStyle = label.fontStyle;
text.fontFamily = label.fontFamily;
text.fontWeight = label.fontWeight;
text.fill = label.color;
text.fillOpacity = highlightOpacity ?? 1;
text.fill = style.color;
text.setBoxing(style);
text.textAlign = label.textAlign;
text.textBaseline = label.verticalAlign;
text.x = label.x;
text.y = label.y;
text.setBoxing(style);
text.visible = true;

text.zIndex = 1;
Expand Down
Loading