diff --git a/capabilities.json b/capabilities.json index 42769ba..4f40b36 100644 --- a/capabilities.json +++ b/capabilities.json @@ -241,6 +241,23 @@ } } }, + "yRangeSettings": { + "displayName": "Y-Axis Range Settings", + "properties": { + "min": { + "displayName": "Minimum Value", + "type": { + "numeric":true + } + }, + "max": { + "displayName": "Maximum Value", + "type": { + "numeric":true + } + } + } + }, "axisSettings": { "displayName": "Axis Settings", "properties": { diff --git a/src/constants.ts b/src/constants.ts index 2826345..105d6ff 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,8 +5,14 @@ export enum Settings { colorSettings = "colorSettings", overlayPlotSettings = "overlayPlotSettings", plotTitleSettings = "plotTitleSettings", - tooltipTitleSettings = "tooltipTitleSettings" + tooltipTitleSettings = "tooltipTitleSettings", + yRangeSettings = "yRangeSettings" } +export enum YRangeSettingsNames{ + min = "min", + max = "max" +} + export enum PlotSettingsNames { plotType = "plotType", fill = "fill" diff --git a/src/marginSettings.ts b/src/marginSettings.ts index 2f59831..e9bd567 100644 --- a/src/marginSettings.ts +++ b/src/marginSettings.ts @@ -2,13 +2,13 @@ import { Margins } from './plotInterface'; export class MarginSettings { static readonly svgTopPadding = 0; - static readonly svgBottomPadding = 0 - static readonly plotTitleHeight = 20; + static readonly svgBottomPadding = 10 + static readonly plotTitleHeight = 18; static readonly dotMargin = 4; static readonly margins: Margins = { top: 10, right: 30, - bottom: 20, + bottom: 10, left: 50, } } \ No newline at end of file diff --git a/src/parseAndTransform.ts b/src/parseAndTransform.ts index 31e27ec..97d44f6 100644 --- a/src/parseAndTransform.ts +++ b/src/parseAndTransform.ts @@ -6,7 +6,7 @@ import ISandboxExtendedColorPalette = powerbi.extensibility.ISandboxExtendedColo import { getValue, getColumnnColorByIndex, getAxisTextFillColor, getPlotFillColor, getColorSettings } from './objectEnumerationUtility'; import { ViewModel, DataPoint, FormatSettings, PlotSettings, PlotModel, TooltipDataPoint, XAxisData, YAxisData, PlotType, SlabRectangle, SlabType, GeneralPlotSettings, Margins, AxisInformation, AxisInformationInterface, TooltipModel } from './plotInterface'; import { Color } from 'd3'; -import { AxisSettingsNames, PlotSettingsNames, Settings, ColorSettingsNames, OverlayPlotSettingsNames, PlotTitleSettingsNames, TooltipTitleSettingsNames } from './constants'; +import { AxisSettingsNames, PlotSettingsNames, Settings, ColorSettingsNames, OverlayPlotSettingsNames, PlotTitleSettingsNames, TooltipTitleSettingsNames, YRangeSettingsNames } from './constants'; import { MarginSettings } from './marginSettings' @@ -223,8 +223,8 @@ export function visualTransform(options: VisualUpdateOptions, host: IVisualHost) max: Math.max(...xDataPoints), }, yRange: { - min: Math.min(...yDataPoints), - max: Math.max(...yDataPoints), + min: getValue(yColumnObjects, Settings.yRangeSettings, YRangeSettingsNames.min, 0),//TODO: default Math.min(...yDataPoints)? + max: getValue(yColumnObjects, Settings.yRangeSettings, YRangeSettingsNames.max, Math.max(...yDataPoints)), }, dataPoints: dataPoints }; diff --git a/src/visual.ts b/src/visual.ts index 3009e51..8c36656 100644 --- a/src/visual.ts +++ b/src/visual.ts @@ -51,7 +51,7 @@ import { getAxisTextFillColor, getPlotFillColor, getValue, getColorSettings } fr import { createTooltipServiceWrapper, ITooltipServiceWrapper } from 'powerbi-visuals-utils-tooltiputils'; import { ViewModel, DataPoint, PlotModel, PlotType, SlabType, D3Plot, D3PlotXAxis, D3PlotYAxis, ColorSettings, SlabRectangle, AxisInformation, AxisInformationInterface, TooltipModel, TooltipDataPoint, TooltipData } from './plotInterface'; import { visualTransform } from './parseAndTransform'; -import { OverlayPlotSettingsNames, ColorSettingsNames, Constants, AxisSettingsNames, PlotSettingsNames, Settings, PlotTitleSettingsNames, TooltipTitleSettingsNames } from './constants'; +import { OverlayPlotSettingsNames, ColorSettingsNames, Constants, AxisSettingsNames, PlotSettingsNames, Settings, PlotTitleSettingsNames, TooltipTitleSettingsNames, YRangeSettingsNames } from './constants'; import { data } from 'jquery'; type Selection = d3.Selection; @@ -92,6 +92,7 @@ export class Visual implements IVisual { let plots: D3Plot[] = []; for (let plotModel of this.viewModel.plotModels) { const plotType = plotModel.plotSettings.plotSettings.plotType; + //TODO: don't draw datapoints that are out of y-range? if (plotType == PlotType.LinePlot) { const linePlot = this.drawLinePlot(options, plotModel); plots.push(linePlot); @@ -197,7 +198,7 @@ export class Visual implements IVisual { const generalPlotSettings = this.viewModel.generalPlotSettings; const yAxis = plot.append('g').classed('yAxis', true); - const yScale = scaleLinear().domain([0, plotModel.yRange.max]).range([generalPlotSettings.plotHeight, 0]); + const yScale = scaleLinear().domain([plotModel.yRange.min, plotModel.yRange.max]).range([generalPlotSettings.plotHeight, 0]); const yAxisValue = axisLeft(yScale).ticks(generalPlotSettings.plotHeight / 20); var yLabel = null; if (plotModel.formatSettings.axisSettings.yAxis.lables) { @@ -468,7 +469,7 @@ export class Visual implements IVisual { for (const tooltip of tooltipData) { tooltipText += " " + tooltip.title + " : " + tooltip.yValue + "
"; } - + //TODO: check if there is a performance difference // for (let plotModel of plotModels) { // for (let point of plotModel.dataPoints) { // if (point.xValue == data.xValue) { @@ -527,12 +528,14 @@ export class Visual implements IVisual { const objectName = options.objectName; const colorPalette = this.host.colorPalette; let objectEnumeration: VisualObjectInstance[] = []; + const plotmodles: PlotModel[] = this.viewModel.plotModels; try { let yCount: number = this.dataview.metadata.columns.filter(x => { return x.roles.y_axis }).length; let metadataColumns: DataViewMetadataColumn[] = this.dataview.metadata.columns; switch (objectName) { case Settings.plotSettings: case Settings.axisSettings: + case Settings.yRangeSettings: setObjectEnumerationColumnSettings(yCount, metadataColumns, 2); break; case Settings.overlayPlotSettings: @@ -577,10 +580,6 @@ export class Visual implements IVisual { function setObjectEnumerationColumnSettings(yCount: number, metadataColumns: powerbi.DataViewMetadataColumn[], settingsCount: number = 1) { objectEnumeration = new Array(yCount * settingsCount); - // if (objectName == Settings.axisSettings || objectName == Settings.plotSettings) { - // objectEnumeration = new Array(2 * yCount); - // } - for (let column of metadataColumns) { if (column.roles.y_axis) { const columnObjects = column.objects; @@ -614,7 +613,18 @@ export class Visual implements IVisual { yAxis: yInformation }; break; + case Settings.yRangeSettings: + const yRange = plotmodles.filter(x => { return x.plotId == yIndex })[0].yRange + displayNames = { + min: column.displayName + " Minimum Value", + yInformation: column.displayName + " Maximum Value", + }; + properties = { + min: getValue(columnObjects, Settings.yRangeSettings, YRangeSettingsNames.min, 0),//TODO: change to yRange.min? + max: getValue(columnObjects, Settings.yRangeSettings, YRangeSettingsNames.max, yRange.max) + }; + break; case Settings.overlayPlotSettings: displayNames = { overlayType: column.displayName + " Slab Overlay Type"