/** * Created by mm28969 on 5/19/17. */ import {Theme} from "../mmviz-common/index"; import {ScaleTypeEnum, ScaleContainerTypeEnum, waterfallLayoutCreator} from "../mmviz-layout/index"; import {BarComponentSvg} from "../mmviz-component-svg/index"; import {DetailsBehavior} from "../mmviz-behavior/index"; import {ChartBuilderSvg} from "./builder"; export class WaterfallChartBuilderSvg extends ChartBuilderSvg { component: BarComponentSvg; padding: number; colorScaleKey: string; constructor(selector: string) { super(selector); this.component = new BarComponentSvg(selector); this.detailsBehavior = new DetailsBehavior(selector, this.component.selector); this.padding = 0.01; this.colorScaleKey = "color"; } createView(){ super.createView(); this.chartView.addContentTypeClass("waterfall-content"); return this; } updateView(){ let viewModel: any, layouter: Function, layoutExtender = waterfallLayoutCreator(this.colorScaleKey), axisViewModel: any, theme = Theme.getInstance(), colorRangeMapper = function(d){ let color = theme.colors.colorSequentialMid; switch (d) { case "previous-positive": color = theme.colors.colorPaletteSemanticPositive[1]; break; case "previous-negative": color = theme.colors.colorPaletteSemanticNegative[1]; break; case "net-positive": color = theme.colors.colorPaletteSemanticPositive[2]; break; case "net-negative": color = theme.colors.colorPaletteSemanticNegative[2]; break; case "next-positive": color = theme.colors.colorPaletteSemanticPositive[3]; break; case "next-negative": color = theme.colors.colorPaletteSemanticNegative[3]; break; case "variance_$-positive": color = theme.colors.colorPaletteSemanticPositive[0]; break; case "variance_$-negative": color = theme.colors.colorPaletteSemanticNegative[0]; break; default: color = theme.colors.colorSequentialMid; break; } return color; }; super.updateView(); this.layoutScale .xScaleSetup(ScaleTypeEnum.BAND) .yScaleSetup(ScaleTypeEnum.LINEAR) .createMapCustomOrdinalScaleContainer(this.colorScaleKey, this.dataModel, colorRangeMapper); this.layoutScale.xScale.padding(this.padding); layouter = layoutExtender(this.dataModel, this.layoutScale); this.displayAxies(); viewModel = layouter(); this.component.updateView(this.chartView.stage, viewModel); super.updateComponents(); return this; } resizeView(){ return this.updateView(); } }