Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Brings an ability to change Dots radius (#17)
Browse files Browse the repository at this point in the history
* Brings ability to change dot radius

Dot's radius used to be hardcoded but now this value moved to Format
Panel -> Dots

Work item #25653

* Covers ability to change radius by Unit Test
  • Loading branch information
ignatvilesov committed May 14, 2018
1 parent db37b8b commit 9820a80
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 19 deletions.
11 changes: 9 additions & 2 deletions capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
}
},
"dataPoint": {
"displayName": "Data colors",
"displayNameKey": "Visual_DataColors",
"displayName": "Dots",
"displayNameKey": "Visual_Dots",
"properties": {
"fill": {
"displayName": "Fill",
Expand All @@ -100,6 +100,13 @@
}
}
}
},
"radius": {
"displayName": "Radius",
"displayNameKey": "Visual_Radius",
"type": {
"numeric": true
}
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-visuals-dotplot",
"version": "1.2.1",
"version": "1.3.0",
"description": "A dot plot is used to show a representation of the distribution of frequencies. It is most often used to show counts of an occurrence.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -47,15 +47,15 @@
"karma-typescript-preprocessor": "0.3.1",
"lodash": "4.17.4",
"powerbi-models": "^1.0.2",
"powerbi-visuals-tools": "1.11.0",
"powerbi-visuals-utils-typeutils": "^1.1.0",
"powerbi-visuals-tools": "^1.11.3",
"powerbi-visuals-utils-chartutils": "1.2.0",
"powerbi-visuals-utils-dataviewutils": "1.2.0",
"powerbi-visuals-utils-formattingutils": "2.1.0",
"powerbi-visuals-utils-interactivityutils": "3.1.0",
"powerbi-visuals-utils-svgutils": "^1.1.0",
"powerbi-visuals-utils-testutils": "1.2.1",
"powerbi-visuals-utils-tooltiputils": "^1.0.0",
"powerbi-visuals-utils-typeutils": "^1.1.0",
"tslint": "5.4.3",
"tslint-microsoft-contrib": "^5.0.1"
}
Expand Down
2 changes: 1 addition & 1 deletion pbiviz.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "Dot Plot",
"guid": "DotPlot1442374105856",
"visualClassName": "DotPlot",
"version": "1.2.1",
"version": "1.3.0",
"description": "A dot plot is used to show a representation of the distribution of frequencies. It is most often used to show counts of an occurrence.",
"supportUrl": "http://community.powerbi.com",
"gitHubUrl": "https://github.com/Microsoft/powerbi-visuals-dotplot"
Expand Down
13 changes: 12 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ module powerbi.extensibility.visual {
}

export class DataPointSettings {
private minRadius: number = 1;
private maxRadius: number = 15;

public fill: string = "#00B8AA";
public radius: number = 5;

public parse(): void {
this.radius = Math.min(
this.maxRadius,
Math.max(this.minRadius, this.radius)
);
}
}

export class LabelsSettings {
Expand All @@ -50,7 +61,7 @@ module powerbi.extensibility.visual {
public labelDisplayUnits: number = 0;
public labelPrecision: number = 2;
public fontSize: number = dataLabelUtils.DefaultFontSizeInPt;
public orientation: DotPlotLabelsOrientation = DotPlotLabelsOrientation.Horizontal;
public orientation: DotPlotLabelsOrientation = DotPlotLabelsOrientation.Horizontal;

}

Expand Down
17 changes: 9 additions & 8 deletions src/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ module powerbi.extensibility.visual {
private static DataLabelAngle: number = -90;
private static DataLabelXOffsetIndex: number = 0.3;

private static DefaultRadius: number = 5;
private static DefaultStrokeWidth: number = 1;

private static DefaultFontSize: number = 11;
Expand Down Expand Up @@ -187,7 +186,6 @@ module powerbi.extensibility.visual {
private interactivityService: IInteractivityService;
private scaleType: string = AxisScale.linear;

private radius: number = 5;
private strokeWidth: number = 1;
private static verticalLabelMarginRatio: number = 0.2;

Expand All @@ -210,7 +208,6 @@ module powerbi.extensibility.visual {
dataView: DataView,
height: number,
colors: IColorPalette,
radius: number,
visualHost: IVisualHost,
layout: VisualLayout
): DotPlotData {
Expand Down Expand Up @@ -296,6 +293,8 @@ module powerbi.extensibility.visual {
? maxLabelWidth
: 0;

const radius: number = settings.dataPoint.radius;

const diameter: number = DotPlot.RadiusFactor * radius + DotPlot.ExtraDiameter,
dotsTotalHeight: number = height - maxXAxisHeight
- radius * DotPlot.RadiusFactor - labelFontSize - layout.margin.top - maxLabelHeight,
Expand Down Expand Up @@ -383,6 +382,8 @@ module powerbi.extensibility.visual {
settings.labels.labelPrecision),
LabelsSettings.MaxLabelPrecision);

settings.dataPoint.parse();

return settings;
}

Expand Down Expand Up @@ -438,11 +439,11 @@ module powerbi.extensibility.visual {
? options.dataViews[0]
: null;
this.layout.viewportIn.height = this.layout.viewportIn.height;

const data: DotPlotData = DotPlot.converter(
dataView,
this.layout.viewportIn.height,
this.colorPalette,
this.radius,
this.visualHost,
this.layout
);
Expand All @@ -459,7 +460,7 @@ module powerbi.extensibility.visual {
width: Math.max(
this.layout.viewportIn.width,
this.data.dataGroups.length
* (this.radius * DotPlot.RadiusFactor + DotPlot.ExtraDiameterOfDataGroups)
* (this.data.settings.dataPoint.radius * DotPlot.RadiusFactor + DotPlot.ExtraDiameterOfDataGroups)
+ this.data.maxLabelWidth)
};

Expand Down Expand Up @@ -570,7 +571,7 @@ module powerbi.extensibility.visual {

circleSelection.attr({
cy: (dataPoint: DotPlotDataPoint) => dataPoint.y,
r: this.radius,
r: this.data.settings.dataPoint.radius,
fill: this.settings.dataPoint.fill
});

Expand Down Expand Up @@ -624,7 +625,7 @@ module powerbi.extensibility.visual {
},
y: (dataGroup: DotPlotDataGroup) => {
const y: number = (_.isEmpty(dataGroup.dataPoints)
? this.data.dotsTotalHeight + this.radius * DotPlot.RadiusFactor
? this.data.dotsTotalHeight + this.data.settings.dataPoint.radius * DotPlot.RadiusFactor
: _.last(dataGroup.dataPoints).y) + this.data.labelFontSize;

return y - dataGroup.size.height;
Expand All @@ -635,7 +636,7 @@ module powerbi.extensibility.visual {
&& dataGroup.dataPoints
&& this.layout.viewportIn.height
- this.data.maxXAxisHeight
+ this.radius * DotPlot.RadiusFactor > this.data.labelFontSize);
+ this.data.settings.dataPoint.radius * DotPlot.RadiusFactor > this.data.labelFontSize);
},
style: {
"fill": this.settings.labels.color,
Expand Down
5 changes: 3 additions & 2 deletions stringResources/en-US/resources.resjson
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Visual_Show": "Show",
"Visual_Title": "Title",
"Visual_LabelColor": "Label color",
"Visual_DataColors": "Data colors",
"Visual_Dots": "Dots",
"Visual_Fill": "Fill",
"Visual_DataLabels": "Data labels",
"Visual_Color": "Color",
Expand All @@ -20,5 +20,6 @@
"Visual_Description_Color": "Select color for data labels",
"Visual_Description_DisplayUnits": "Select the units (millions, billions, etc.)",
"Visual_Description_DecimalPlaces": "Select the number of decimal places to display",
"Visual_Value": "Value"
"Visual_Value": "Value",
"Visual_Radius": "Radius"
}
25 changes: 23 additions & 2 deletions test/visualTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ namespace powerbi.extensibility.visual.test {
});
});

describe("Data colors", () => {
it("default color", () => {
describe("Dots", () => {
it("specified color should be applied to all of dots", () => {
const color: string = "#112233";

dataView.metadata.objects = {
Expand All @@ -228,6 +228,27 @@ namespace powerbi.extensibility.visual.test {
assertColorsMatch(element.css("fill"), color);
});
});

it("specified radius should be applied to all of dots", () => {
const radius: number = 5;

dataView.metadata.objects = {
dataPoint: {
radius,
}
};

visualBuilder.updateFlushAllD3Transitions(dataView);

visualBuilder.dots
.toArray()
.map($)
.forEach((element: JQuery) => {
const parsedRadius: number = Number.parseInt(element.attr("r"));

expect(parsedRadius).toBe(radius);
});
});
});

describe("Data labels", () => {
Expand Down

0 comments on commit 9820a80

Please sign in to comment.