Skip to content

Commit

Permalink
Merge pull request #39 from jku-vds-lab/jakob/y-range-settings
Browse files Browse the repository at this point in the history
added settings for y-axis ranges
  • Loading branch information
VAISHALI-DHANOA authored Feb 23, 2022
2 parents f7f4959 + b562b32 commit 0e7621f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
17 changes: 17 additions & 0 deletions capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 7 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/marginSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
6 changes: 3 additions & 3 deletions src/parseAndTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down Expand Up @@ -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<number>(yColumnObjects, Settings.yRangeSettings, YRangeSettingsNames.min, 0),//TODO: default Math.min(...yDataPoints)?
max: getValue<number>(yColumnObjects, Settings.yRangeSettings, YRangeSettingsNames.max, Math.max(...yDataPoints)),
},
dataPoints: dataPoints
};
Expand Down
24 changes: 17 additions & 7 deletions src/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T1, T2 = T1> = d3.Selection<any, T1, any, T2>;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -468,7 +469,7 @@ export class Visual implements IVisual {
for (const tooltip of tooltipData) {
tooltipText += "<b> " + tooltip.title + "</b> : " + tooltip.yValue + " <br> ";
}

//TODO: check if there is a performance difference
// for (let plotModel of plotModels) {
// for (let point of plotModel.dataPoints) {
// if (point.xValue == data.xValue) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -577,10 +580,6 @@ export class Visual implements IVisual {
function setObjectEnumerationColumnSettings(yCount: number, metadataColumns: powerbi.DataViewMetadataColumn[], settingsCount: number = 1) {
objectEnumeration = new Array<VisualObjectInstance>(yCount * settingsCount);

// if (objectName == Settings.axisSettings || objectName == Settings.plotSettings) {
// objectEnumeration = new Array<VisualObjectInstance>(2 * yCount);
// }

for (let column of metadataColumns) {
if (column.roles.y_axis) {
const columnObjects = column.objects;
Expand Down Expand Up @@ -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<number>(columnObjects, Settings.yRangeSettings, YRangeSettingsNames.min, 0),//TODO: change to yRange.min?
max: getValue<number>(columnObjects, Settings.yRangeSettings, YRangeSettingsNames.max, yRange.max)
};

break;
case Settings.overlayPlotSettings:
displayNames = {
overlayType: column.displayName + " Slab Overlay Type"
Expand Down

0 comments on commit 0e7621f

Please sign in to comment.