/** * Created by mm28969 on 1/21/17. */ import {Component} from "./component"; import {convertValueToAttribute} from "../mmviz-common/index"; export class MapComponentSvg extends Component { role; tabIndexStart; hasClickBehavior; hasFocusBehavior; hasMouseOverBehavior; hasMouseMoveBehavior; hasMouseOutBehavior; constructor(parentSelector: string, selector: string = ".map") { super(parentSelector, selector); this.role = []; this.hasClickBehavior = false; this.hasFocusBehavior = false; this.hasMouseOverBehavior = true; this.hasMouseMoveBehavior = true; this.hasMouseOutBehavior = true; } updateView(parent, viewModel): MapComponentSvg { let mapGroup = parent.select("g" + this.selector), features; if (mapGroup.empty()) { mapGroup = parent.append("g").attr("class", super.getClassName()); } // else { // // remove and redraw everything // mapGroup.selectAll("*").remove(); // } if (viewModel.json) { features = mapGroup .selectAll("path") .data(viewModel.json.features) .enter() .append("path") .attr("d", viewModel.path) .attr("fill", (d, i) => { return d.color.value; }) .attr("class", (d, i) => { return "feature " + d.nameAttr + " " + d.categoryAttr; }); if (this.role){ features.attr("role", this.role); } features = mapGroup .selectAll("path") .data(viewModel.json.features) .attr("d", viewModel.path); if (this.hasClickBehavior){ this.addBehavior(features, "click"); } if (this.hasFocusBehavior) { this.addBehavior(features, "focus"); features.attr("tabindex", 0); features.attr("focusable", true); } if (this.hasMouseOverBehavior){ this.addBehavior(features, "mouseover"); } if (this.hasMouseMoveBehavior) { this.addBehavior(features, "mousemove"); } if (this.hasMouseOutBehavior) { this.addBehavior(features, "mouseout"); } } return this; } }