Skip to content
Open
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
97 changes: 63 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"package": "pbiviz package",
"eslint": "npx eslint . --ext .js,.jsx,.ts,.tsx",
"test": "karma start",
"cert": "pbiviz --create-cert"
"cert": "pbiviz --create-cert",
"debug": "karma start --browsers=Chrome --single-run=false"
},
"author": {
"name": "Microsoft",
Expand Down
46 changes: 19 additions & 27 deletions src/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,24 +775,6 @@ export class DotPlot implements IVisual {

xAxisProperties.axis.tickValues(tickValues);

const tickWidth: number = (tickValues.length > DotPlot.MinAmountOfTicks
? scale(tickValues[1]) - scale(tickValues[0])
: pixelSpan) - DotPlot.TickWidthOffset;

xAxisProperties.axis.tickFormat((index: number) => {
if (!this.formattingSettings.categoryAxis.show.value || !this.data.dataGroups[index]) {
return DotPlot.DefaultTickValue;
}

const textProperties: TextProperties = DotPlot.getCategoryTextProperties(
this.data.dataGroups[index].category.value);

return textMeasurementService.getTailoredTextOrDefault(
textProperties,
tickWidth
);
});

if (this.formattingSettings.categoryAxis.show.value) {
// Should handle the label, units of the label and the axis style
xAxisProperties.axisLabel = this.data.categoryAxisName;
Expand Down Expand Up @@ -825,20 +807,30 @@ export class DotPlot implements IVisual {
}

if (this.formattingSettings.categoryAxis.show.value) {
const pixelSpan: number = this.dataViewport.width - this.data.maxLabelWidth;
const scale: any = this.xAxisProperties.axis.scale();
const tickValues: any[] = this.xAxisProperties.axis.tickValues();
const tickWidth: number = (tickValues.length > DotPlot.MinAmountOfTicks
? scale(tickValues[1]) - scale(tickValues[0])
: pixelSpan) - DotPlot.TickWidthOffset;

this.xAxisSelection.selectAll(DotPlot.TickTextSelector.selectorName)
.text((index: number) => {
return this.data.dataGroups[index]
&& this.data.dataGroups[index].category.value;
});
} else {
this.xAxisSelection.selectAll(DotPlot.TickTextSelector.selectorName)
.append("title")
.text((index: number) => {
return this.data.dataGroups[index]
&& this.data.dataGroups[index].category.value;
});
&& textMeasurementService.getTailoredTextOrDefault(
DotPlot.getCategoryTextProperties(this.data.dataGroups[index].category.value),
tickWidth
);
Comment thread
dsukhankin marked this conversation as resolved.
Comment thread
dsukhankin marked this conversation as resolved.
})
}

this.xAxisSelection.selectAll(DotPlot.TickTextSelector.selectorName)
.append("title")
.text((index: number) => {
return this.data.dataGroups[index]
&& this.data.dataGroups[index].category.value;
});

this.xAxisSelection
.selectAll("line")
.style("opacity", this.formattingSettings.categoryAxis.show.value
Expand Down
14 changes: 7 additions & 7 deletions test/visualData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export class DotPlotData extends TestDataViewBuilder {
public static ColumnValues: string = "Value";

public static ValuesCategoryLongNames: string[] = [
"Sir Demetrius",
"Sir Montgomery",
"Sir Remington",
"Sir Forrester",
"Sir Christopher",
"Miss Annabelle",
"Miss Emmaline"
"Very long label that should be truncated",
"Extremely long label that should be truncated",
"Quite a long label that should be truncated",
"Long label that should be truncated",
"Label that should be truncated",
"Short label",
"Label that should be truncated",
];

public valuesCategory: string[] = [
Expand Down
15 changes: 13 additions & 2 deletions test/visualTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ describe("DotPlot", () => {
});
});

it("xAxis tick labels are truncated if they don't fit", done => {
defaultDataViewBuilder.valuesCategory = DotPlotData.ValuesCategoryLongNames;
dataView = defaultDataViewBuilder.getDataView();

visualBuilder.updateRenderTimeout(dataView, () => {
expect(visualBuilder.xAxisTickText
.some((textElement: SVGTextElement) => textElement.textContent!.includes("..."))).toBe(true);

done();
});
});

it("should correctly render duplicates in categories", done => {
dataView.categorical!.categories![0].values[1] =
dataView.categorical!.categories![0].values[0];
Expand Down Expand Up @@ -264,7 +276,7 @@ describe("DotPlot", () => {
};
});

it("show", () => {
fit("show", () => {
(dataView.metadata.objects as any).categoryAxis.show = true;

visualBuilder.updateFlushAllD3Transitions(dataView);
Expand All @@ -279,7 +291,6 @@ describe("DotPlot", () => {
visualBuilder.xAxisTicks
.map(e => e.querySelector("text")!)
.forEach((e: SVGTextElement) => {
expect(e.children.length).toBe(0);
expect(e.tagName).not.toBe("title");
expect(e.textContent!).toBeTruthy();
});
Expand Down