/** * Created by mm28969 on 1/21/17. */ import * as d3 from "d3"; import {convertValueToAttribute} from "../mmviz-common/index"; import {Layout} from "./layout"; import {LayoutScale} from "./scale"; export class MapLayout extends Layout { colorScaleKey; constructor() { super(); this.colorScaleKey = "color"; } layoutView(dataModel, layoutScale: LayoutScale){ let viewModel: any = {}, color, projection = dataModel.projection, path = d3.geoPath().projection(projection) ; viewModel = { path: path, json: dataModel.json }; const colorScaleContainer = layoutScale.getScaleContainer(this.colorScaleKey); if (!colorScaleContainer.hasDomain){ if (dataModel.getColorDomain){ colorScaleContainer.domain = dataModel.getColorDomain(); } else if (dataModel.colorValueMap) { colorScaleContainer.domain = d3.set(dataModel.json.features.map(dataModel.colorValueMap)).values(); } } for (let feature of viewModel.json.features){ color = layoutScale.mapValue(this.colorScaleKey, dataModel, feature); feature.color = color; feature.category = color.key; feature.categoryAttr = "category-" + convertValueToAttribute(color.key); feature.nameAttr = convertValueToAttribute(feature.properties.name); if(dataModel.detailsMap){ feature.details = dataModel.detailsMap(feature); } else { feature.details = { label: feature.properties.name, value: "" } } } return viewModel; } }