/** * Created by mm28969 on 1/30/17. */ import * as d3 from "d3"; import {convertValueToAttribute} from "../mmviz-common/index"; import {Layout} from "./layout"; import {LayoutScale} from "./scale"; export class MapPointLayout extends Layout { private _dataModel; private _areaDomain; colorScaleKey; areaScaleKey; constructor(dataModel) { super(); this.dataModel = dataModel; this.colorScaleKey = "colorPoint"; this.areaScaleKey = "area"; } set dataModel(dataModel) { this._dataModel = dataModel; if(this._dataModel.areaValueMap){ this._areaDomain = d3.extent(this._dataModel.dataArray, this._dataModel.areaValueMap); } } extend(layoutScale: LayoutScale) { if(this._areaDomain){ layoutScale.extendAreaScale(this.areaScaleKey, this._areaDomain); } } layoutView(layoutScale: LayoutScale){ let key, color, latLong, longitude, latitude, dLayout, viewModel: any = super.createViewModel(); for(let d of this._dataModel.dataArray){ key = this._dataModel.keyValueMap(d); latitude = this._dataModel.latitudeValueMap(d); longitude = this._dataModel.longitudeValueMap(d); latLong = this._dataModel.projection([longitude, latitude]); //if location on map if(latLong){ dLayout = { key: key, keyAttr: "key-" + convertValueToAttribute(key), x: latLong[0], y: latLong[1], keyValueMap: function(d){ return d.key; }, data: d }; color = layoutScale.mapValue(this.colorScaleKey, this._dataModel, d); dLayout.color = color; dLayout.category = color.key; dLayout.categoryAttr = "category-" + convertValueToAttribute(color.key); dLayout.radius = layoutScale.mapAreaRadiusValue(this.areaScaleKey, this._dataModel, d); if(this._dataModel.detailsMap){ dLayout.details = this._dataModel.detailsMap(d); } else { dLayout.details = { label: key, value: latitude + " " + longitude } } viewModel.dataArray.push(dLayout); } } return viewModel; } }