Skip to content

Commit

Permalink
Fixed breaking issue if string value used instead of number in Values…
Browse files Browse the repository at this point in the history
… field bucket (#16)
  • Loading branch information
mvgaliev authored and ignatvilesov committed Jan 12, 2018
1 parent 5425cd5 commit aca90fd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.4.1
* Fixed breaking issue if string value used instead of number in Values field bucket

## 1.4.0
* Stream Graph: Community suggestions
* Data Labels option can now displays measure *field name* measure *value*.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-visuals-streamgraph",
"version": "1.4.0",
"version": "1.4.1",
"description": "A stacked area chart with smooth interpolation. Often used to display values over time.",
"repository": {
"type": "git",
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": "Stream Graph",
"guid": "StreamGraph1446659696222",
"visualClassName": "StreamGraph",
"version": "1.4.0",
"version": "1.4.1",
"description": "A stacked area chart with smooth interpolation. Often used to display values over time.",
"supportUrl": "https://aka.ms/customvisualscommunity",
"gitHubUrl": "https://github.com/Microsoft/powerbi-visuals-streamgraph"
Expand Down
12 changes: 8 additions & 4 deletions src/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ module powerbi.extensibility.visual {
};
}

public static isNumber(value: PrimitiveValue) {
return !isNaN(value as number) && isFinite(value as number) && value !== null;
}

public static converter(
dataView: DataView,
colorPalette: IColorPalette,
Expand Down Expand Up @@ -296,9 +300,9 @@ module powerbi.extensibility.visual {
}
let streamDataPoint: StreamDataPoint = {
x: dataPointValueIndex,
y: isNaN(y)
? StreamGraph.DefaultValue
: y,
y: StreamGraph.isNumber(y)
? y
: StreamGraph.DefaultValue,
text: label,
labelFontSize: fontSizeInPx
};
Expand Down Expand Up @@ -987,7 +991,7 @@ module powerbi.extensibility.visual {
.x((dataPoint: StreamDataPoint) => xScale(dataPoint.x))
.y0((dataPoint: StreamDataPoint) => yScale(dataPoint.y0))
.y1((dataPoint: StreamDataPoint) => yScale(dataPoint.y0 + dataPoint.y))
.defined((dataPoint: StreamDataPoint) => !isNaN(dataPoint.y0) && !isNaN(dataPoint.y));
.defined((dataPoint: StreamDataPoint) => StreamGraph.isNumber(dataPoint.y0) && StreamGraph.isNumber(dataPoint.y));

const selection: UpdateSelection<StreamGraphSeries> = this.dataPointsContainer
.selectAll(StreamGraph.LayerSelector.selectorName)
Expand Down
14 changes: 14 additions & 0 deletions test/visualTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,20 @@ module powerbi.extensibility.visual.test {
visualBuilder.visualHost);
});

describe("isNumber" , () => {
it("should define number values", () => {
const valueNumber = 100,
valueNull = null,
valueUndefined = undefined,
valueNan = NaN;

expect(VisualClass.isNumber(valueNumber)).toBeTruthy();
expect(VisualClass.isNumber(valueNull)).toBeFalsy();
expect(VisualClass.isNumber(valueUndefined)).toBeFalsy();
expect(VisualClass.isNumber(valueNan)).toBeFalsy();
});
});

describe("streamData", () => {
let streamData: StreamData;

Expand Down

0 comments on commit aca90fd

Please sign in to comment.