Last active
April 17, 2023 20:13
-
-
Save TweededBadger/d5069823501761936d6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('SvgMapApp').directive('svgMap', ['$compile', function ($compile) { | |
return { | |
restrict: 'A', | |
templateUrl: 'img/Blank_US_Map.svg', | |
link: function (scope, element, attrs) { | |
var regions = element[0].querySelectorAll('.state'); | |
angular.forEach(regions, function (path, key) { | |
var regionElement = angular.element(path); | |
regionElement.attr("region", ""); | |
regionElement.attr("dummy-data", "dummyData"); | |
regionElement.attr("hover-region", "hoverRegion"); //<--- Add this | |
$compile(regionElement)(scope); | |
}) | |
} | |
} | |
}]); | |
angular.module('SvgMapApp').directive('region', ['$compile', function ($compile) { | |
return { | |
restrict: 'A', | |
scope: { | |
dummyData: "=", | |
hoverRegion: "=" //<--- Add this | |
}, | |
link: function (scope, element, attrs) { | |
scope.elementId = element.attr("id"); | |
scope.regionClick = function () { | |
alert(scope.dummyData[scope.elementId].value); | |
}; | |
scope.regionMouseOver = function () { //< | |
scope.hoverRegion = scope.elementId; //<--- Add this | |
element[0].parentNode.appendChild(element[0]); //< | |
}; //< | |
element.attr("ng-click", "regionClick()"); | |
element.attr("ng-attr-fill", "{{dummyData[elementId].value | map_colour}}"); | |
element.attr("ng-mouseover", "regionMouseOver()"); //<--- Add this | |
element.attr("ng-class", "{active:hoverRegion==elementId}"); //<--- Add this | |
element.removeAttr("region"); | |
$compile(element)(scope); | |
} | |
} | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--... --> | |
<div class="regionlist"> | |
<div ng-repeat="(key,region) in dummyData" ng-class="{active:hoverRegion==key}"> <!-- Change this --> | |
<div>{{key}}</div> | |
<div>{{region.value | number}}</div> | |
</div> | |
</div> | |
<!--...--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*...*/ | |
.regionlist > div.active { | |
font-weight: bold; | |
background-color: lightblue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment