Skip to content

Commit

Permalink
Fix Safari issue, add unit tests (#19)
Browse files Browse the repository at this point in the history
* Fix Safari issue
  • Loading branch information
DimaNaumov authored and ignatvilesov committed Nov 16, 2017
1 parent cb15351 commit 5f5da2b
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.1
* Fix selection issue in Safari
* Add unit tests

## 2.3.0
* Remove d3 dependency
* Code refactoring
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "powerbi-visuals-globemap",
"description": "GlobeMap",
"version": "2.3.0",
"version": "2.3.1",
"author": {
"name": "Microsoft",
"email": "[email protected]"
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": "GlobeMap",
"guid": "GlobeMap1447669447625",
"visualClassName": "GlobeMap",
"version": "2.3.0",
"version": "2.3.1",
"description": "A 3D visual using WebGL for plotting locations, with category values displayed as bar heights and heat maps.\n\nShift+Click on bar to change center point. \nSlicing data points will animate to average location.\n\nAttributions:\nthree.js - https://github.com/mrdoob/three.js/\nwebgl-heatmap - https://github.com/pyalot/webgl-heatmap",
"supportUrl": "https://aka.ms/customvisualscommunity",
"gitHubUrl": "https://github.com/Microsoft/powerbi-visuals-globemap"
Expand Down
28 changes: 21 additions & 7 deletions src/globemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ module powerbi.extensibility.visual {
if (categorical.Location && categorical.Location.values) {
locations = categorical.Location.values;
const sourceType: IGlobeMapValueTypeDescriptor = <IGlobeMapValueTypeDescriptor> categorical.Location.source.type;
locationType = sourceType.category ? (<string>sourceType.category).toLowerCase() : "";
locationType = sourceType.category ? `${sourceType.category}`.toLowerCase() : "";
} else {
locations = [];
if (categorical.X && categorical.Y && categorical.X.values && categorical.Y.values) {
Expand Down Expand Up @@ -414,14 +414,15 @@ module powerbi.extensibility.visual {
let toolTipDataLongName: string;
let toolTipDataLatName: string;
let location: ILocation;

let locationValue: string;
if (typeof (locations[i]) === "string") {
place = (<string>locations[i]).toLowerCase();
place = `${locations[i]}`.toLowerCase();
placeKey = `${place} / ${locationType}`;
location = (!_.isEmpty(categorical.X) && !_.isEmpty(categorical.Y))
? { longitude: <number>categorical.X[0].values[i] || 0, latitude: <number>categorical.Y[0].values[i] || 0 }
: undefined;
toolTipDataLocationName = categorical.Location && categorical.Location.source.displayName;
locationValue = `${locations[i]}`;
} else {
place = `${categorical.X.values[i]} ${categorical.Y.values[i]}`;
placeKey = categorical.X.values[i] + " " + categorical.Y.values[i];
Expand All @@ -430,8 +431,12 @@ module powerbi.extensibility.visual {
: undefined;
toolTipDataLongName = categorical.X && categorical.X.source && categorical.X.source.displayName;
toolTipDataLatName = categorical.Y && categorical.Y.source && categorical.Y.source.displayName;
locationValue = "";
}

const longitudeValue: string = GlobeMap.getCategoricalValueByIndex(categorical.X, i);
const latitudeValue: string = GlobeMap.getCategoricalValueByIndex(categorical.Y, i);

let renderDatum: GlobeMapDataPoint = {
location: location,
placeKey: placeKey,
Expand All @@ -442,9 +447,9 @@ module powerbi.extensibility.visual {
seriesToolTipData: toolTipDataBySeries ? toolTipDataBySeries[i] : undefined,
heat: heat || 0,
toolTipData: {
location: { displayName: !_.isEmpty(toolTipDataLocationName) && toolTipDataLocationName, value: locations[i] },
longitude: {displayName: !_.isEmpty(toolTipDataLongName) && toolTipDataLongName, value: categorical.X && categorical.X.values && categorical.X.values[i].toString()},
latitude: {displayName: !_.isEmpty(toolTipDataLatName) && toolTipDataLatName, value: categorical.Y && categorical.Y.values && categorical.Y.values[i].toString()},
location: { displayName: !_.isEmpty(toolTipDataLocationName) && toolTipDataLocationName, value: locationValue },
longitude: {displayName: !_.isEmpty(toolTipDataLongName) && toolTipDataLongName, value: longitudeValue},
latitude: {displayName: !_.isEmpty(toolTipDataLatName) && toolTipDataLatName, value: latitudeValue},
height: { displayName: !_.isEmpty(categorical.Height) && categorical.Height[0].source.displayName, value: heightFormatter.format(heights[i]) },
heat: { displayName: !_.isEmpty(categorical.Heat) && categorical.Heat[0].source.displayName, value: heatFormatter.format(heats[i]) }
}
Expand Down Expand Up @@ -488,7 +493,7 @@ module powerbi.extensibility.visual {
.withCategory(dataPointsParams.dataView.categorical.categories[0], dataPointsParams.catIndex)
.createSelectionId();

const category: string = <string>converterHelper.getSeriesName(dataPointsParams.source);
const category: string = `${converterHelper.getSeriesName(dataPointsParams.source)}`;
const objects: {} = dataPointsParams.dataView.categorical.categories[0].objects;
const color: string =
objects && objects[dataPointsParams.catIndex] && objects[dataPointsParams.catIndex].dataPoint ?
Expand Down Expand Up @@ -1511,5 +1516,14 @@ module powerbi.extensibility.visual {

return controlsContainerSVG;
}

public static getCategoricalValueByIndex(category: DataViewCategoryColumn, index: number): string {
if (!category ||
!Array.isArray(category.values) ||
category.values.length <= index) {
return "";
}
return `${category.values[index]}`;
}
}
}
63 changes: 63 additions & 0 deletions test/visualData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module powerbi.extensibility.visual.test {
export class GlobeMapData extends TestDataViewBuilder {
public static ColumnSource: string = "Location";
public static ColumnValue: string = "Height";
public static ColumnLongitude: string = "Longitude";
public static ColumnLalitude: string = "Lalitude";

public valuesSourceDestination: string[] = [
'Riyadh, Saudi Arabia',
Expand All @@ -59,7 +61,50 @@ module powerbi.extensibility.visual.test {
'Ahmedabad, India',
'Mexico City, Mexico',
'Chennai, India'
];

public latitudeSourceDestination: number[] = [
24.7388,
24.911449,
-6.199707,
33.557617,
22.603919,
8.958422,
30.053986,
21.142542,
35.707666,
6.499765,
21.370158,
-33.925165,
31.170009,
-12.045775,
-29.845546,
51.513605,
23.036129,
19.377726,
13.05915
];

public longitudeSourceDestination: number[] = [
46.872447,
121.517012,
106.760508,
-7.649532,
113.951561,
38.725271,
31.244216,
72.815901,
51.32757,
3.273896,
39.212623,
18.568671,
121.204812,
-77.058747,
30.966266,
-0.168895,
72.510046,
-99.136068,
80.237908
];

public valuesValue: number[] = getRandomNumbers(this.valuesSourceDestination.length, 10, 500);
Expand All @@ -84,6 +129,24 @@ module powerbi.extensibility.visual.test {
type: ValueType.fromDescriptor({ numeric: true }),
},
values: this.valuesValue
},
{
source: {
displayName: GlobeMapData.ColumnLalitude,
roles: { [GlobeMapData.ColumnLalitude]: true },
isMeasure: true,
type: ValueType.fromDescriptor({ numeric: true }),
},
values: this.latitudeSourceDestination
},
{
source: {
displayName: GlobeMapData.ColumnLongitude,
roles: { [GlobeMapData.ColumnLongitude]: true },
isMeasure: true,
type: ValueType.fromDescriptor({ numeric: true }),
},
values: this.longitudeSourceDestination
}
], columnNames).build();
}
Expand Down
14 changes: 12 additions & 2 deletions test/visualTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module powerbi.extensibility.visual.test {
dataView: DataView;

beforeEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000;
visualBuilder = new GlobeMapBuilder(1024, 1024);

defaultDataViewBuilder = new GlobeMapDataViewBuilder();
Expand All @@ -63,9 +63,10 @@ module powerbi.extensibility.visual.test {
});

describe("DOM tests", () => {
it("canvas element created", () => {
it("canvas element created", (done) => {
visualBuilder.updateRenderTimeout(dataView, () => {
expect(visualBuilder.element.find("canvas")).toBeInDOM();
done();
});
});
});
Expand Down Expand Up @@ -114,6 +115,15 @@ module powerbi.extensibility.visual.test {
let groupedColumns: GlobeMapColumns<DataViewValueColumn>[] = GlobeMapColumns.getGroupedValueColumns(dataView);
expect(groupedColumns.length).toBe(1);
});
it("getCategoricalValueByIndex should return longitude value", function () {
let longitude: string = VisualClass.getCategoricalValueByIndex(dataView.categorical.values[1], 1);
expect(longitude).toEqual(`${dataView.categorical.values[1].values[1]}`);
});

it("getCategoricalValueByIndex should return latitude value", function () {
let latitude: string = VisualClass.getCategoricalValueByIndex(dataView.categorical.values[2], 1);
expect(latitude).toEqual(`${dataView.categorical.values[2].values[1]}`);
});
});
});

Expand Down

0 comments on commit 5f5da2b

Please sign in to comment.