Skip to content

Commit

Permalink
[chores] Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
totallynotvaishnav committed Aug 18, 2022
1 parent 39a8bd5 commit d28bfee
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/netjsongraph.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/js/netjsongraph.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,8 @@ class NetJSONGraphRender {
// eslint-disable-next-line no-underscore-dangle
self.leaflet._zoomAnimated = false;

if (!self.config.geoOptions.pointToLayer) {
self.config.geoOptions = {
...self.config.geoOptions,
self.config.geoOptions = self.utils.deepMergeObj(
{
pointToLayer: (feature, latlng) =>
L.circleMarker(latlng, self.config.geoOptions.style),
onEachFeature: (feature, layer) => {
Expand All @@ -348,8 +347,9 @@ class NetJSONGraphRender {
self.config.onClickElement.call(self, "Feature", properties);
});
},
};
}
},
self.config.geoOptions,
);

if (self.type === "geojson") {
self.leaflet.geoJSON = L.geoJSON(self.data, self.config.geoOptions).addTo(
Expand Down
9 changes: 5 additions & 4 deletions src/js/netjsongraph.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,14 @@ class NetJSONGraphUtil {
* @return {bool}
*/
isGeoJSON(param) {
if (
param.type &&
(param.type === "FeatureCollection" || param.type === "Feature")
) {
if (param.type && param.type === "FeatureCollection") {
return this.isObject(param) && this.isArray(param.features);
}

if (param.type && param.type === "Feature") {
return this.isObject(param) && this.isArray(param.geometry);
}

return false;
}

Expand Down
6 changes: 6 additions & 0 deletions test/netjsongraph.calc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,5 +475,11 @@ describe("Test netjsongraph function utils", () => {
};
expect(util.isGeoJSON(data)).toBeFalsy();
expect(util.isNetJSON(data)).toBeFalsy();
data = {
type: "Feature",
properties: {},
geometry: [],
};
expect(util.isGeoJSON(data)).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion test/netjsongraph.render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ describe("Test netjsongraph properties", () => {
});
});

describe("Test netjsongraph properties", () => {
describe("Test netjsongraph GeoJSON properties", () => {
const geoJSONData = {
type: "FeatureCollection",
features: [
Expand Down

0 comments on commit d28bfee

Please sign in to comment.