Skip to content

Commit

Permalink
Merge pull request #104 from microsoft/dev/sdabbah/Modify-UseFormatti…
Browse files Browse the repository at this point in the history
…ngSettingsService

Modify formatting settings to use formatting model utils service & Add strings localization
  • Loading branch information
ShereinDabbah authored Sep 4, 2022
2 parents fa20f56 + 6937e3d commit 3c7df9c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 49 deletions.
16 changes: 9 additions & 7 deletions src/barChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructor
import { textMeasurementService } from "powerbi-visuals-utils-formattingutils";
import { createTooltipServiceWrapper, ITooltipServiceWrapper } from "powerbi-visuals-utils-tooltiputils";

import { FormattingSettingsService } from "powerbi-visuals-utils-formattingmodel";
import { BarChartSettingsModel } from "./barChartSettingsModel";
import { getLocalizedString } from "./localization/localizationHelper";
import { getCategoricalObjectValue, getValue } from "./objectEnumerationUtility";
Expand Down Expand Up @@ -165,11 +166,8 @@ export class BarChart implements IVisual {
private tooltipServiceWrapper: ITooltipServiceWrapper;
private locale: string;
private helpLinkElement: Selection<any>;
private element: HTMLElement;
private isLandingPageOn: boolean;
private LandingPageRemoved: boolean;
private LandingPage: Selection<any>;
private averageLine: Selection<SVGElement>;
private formattingSettingsService: FormattingSettingsService;

private barSelection: d3.Selection<d3.BaseType, any, d3.BaseType, any>;

Expand All @@ -196,7 +194,6 @@ export class BarChart implements IVisual {
*/
constructor(options: VisualConstructorOptions) {
this.host = options.host;
this.element = options.element;
this.selectionManager = options.host.createSelectionManager();
this.locale = options.host.locale;

Expand All @@ -206,6 +203,9 @@ export class BarChart implements IVisual {

this.tooltipServiceWrapper = createTooltipServiceWrapper(this.host.tooltipService, options.element);

const localizationManager = this.host.createLocalizationManager();
this.formattingSettingsService = new FormattingSettingsService(localizationManager);

this.svg = d3Select(options.element)
.append('svg')
.classed('barChart', true);
Expand Down Expand Up @@ -237,7 +237,9 @@ export class BarChart implements IVisual {
* the visual had queried.
*/
public update(options: VisualUpdateOptions) {
this.formattingSettings = BarChartSettingsModel.populateFrom(options.dataViews);
this.formattingSettings = this.formattingSettingsService.populateFormattingSettingsModel(BarChartSettingsModel, options.dataViews);


this.barDataPoints = createSelectorDataPoints(options, this.host);
this.formattingSettings.populateColorSelector(this.barDataPoints);

Expand Down Expand Up @@ -512,6 +514,6 @@ export class BarChart implements IVisual {
}

public getFormattingModel(): powerbi.visuals.FormattingModel {
return this.formattingSettings.buildFormattingModel();
return this.formattingSettingsService.buildFormattingModel(this.formattingSettings);
}
}
58 changes: 16 additions & 42 deletions src/barChartSettingsModel.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import powerbi from "powerbi-visuals-api";
import { dataViewWildcard } from "powerbi-visuals-utils-dataviewutils";
import { formattingSettings, formattingSettingsModel } from "powerbi-visuals-utils-formattingmodel";
import { formattingSettings } from "powerbi-visuals-utils-formattingmodel";
import { BarChartDataPoint } from "./barChart";

import FormattingSettingsCard = formattingSettings.Card;
import FormattingSettingsSlice = formattingSettings.Slice;
import FormattingSettingsModel = formattingSettings.Model;

class EnableAxisCardSettings implements FormattingSettingsCard {
class EnableAxisCardSettings extends FormattingSettingsCard {
show = new formattingSettings.ToggleSwitch({
name: "show",
displayName: undefined,
Expand All @@ -16,52 +17,26 @@ class EnableAxisCardSettings implements FormattingSettingsCard {

fill = new formattingSettings.ColorPicker({
name: "fill",
displayName: "Color",
displayNameKey: "Visual_Color",
value: { value: "#000000" }
});

font = new formattingSettings.FontControl({
displayName: "font",
name: "font",
fontFamily: {
name: "fontFamily",
value: "Segoe UI, wf_segoe-ui_normal, helvetica, arial, sans-serif",
type: powerbi.visuals.FormattingComponent.FontPicker
},
fontSize: {
name: "fontSize",
value: 5
},
bold: {
name: "fontBold",
value: false
},
underline: {
name: "fontUnderline",
value: false
},
italic: {
name: "fontItalic",
value: false
}
});

name: string = "enableAxis";
displayName: string = "Enable Axis";
displayNameKey: string = "Visual_EnableAxis";
slices: Array<FormattingSettingsSlice> = [this.show, this.fill];
}


class ColorSelectorCardSettings implements FormattingSettingsCard {
class ColorSelectorCardSettings extends FormattingSettingsCard {
name: string = "colorSelector";
displayName: string = "Data Colors";
displayNameKey: string = "Visual_DataColors";
slices: Array<FormattingSettingsSlice> = [];
}

class GeneralViewCardSettings implements FormattingSettingsCard {
class GeneralViewCardSettings extends FormattingSettingsCard {
opacity = new formattingSettings.NumUpDown({
name: "opacity",
displayName: "Bars Opacity",
displayNameKey: "Visual_BarsOpacity",
value: 100,
options: {
minValue: {
Expand All @@ -77,17 +52,17 @@ class GeneralViewCardSettings implements FormattingSettingsCard {

showHelpLink = new formattingSettings.ToggleSwitch({
name: "showHelpLink",
displayName: "Show Help Button",
displayNameKey: "Visual_Show_HelpButton",
value: false
});

name: string = "generalView";
displayName: string = "General View";
displayNameKey: string = "Visual_GeneralView";
helpLinkColor: string = "#80B0E0"
slices: Array<FormattingSettingsSlice> = [this.opacity, this.showHelpLink];
}

class AverageLineCardSettings implements FormattingSettingsCard {
class AverageLineCardSettings extends FormattingSettingsCard {
show = new formattingSettings.ToggleSwitch({
name: "show",
displayName: undefined,
Expand All @@ -97,18 +72,18 @@ class AverageLineCardSettings implements FormattingSettingsCard {

fill = new formattingSettings.ColorPicker({
name: "fill",
displayName: "Color",
displayNameKey: "Visual_Color",
value: { value: "#888888" },
});

showDataLabel = new formattingSettings.ToggleSwitch({
name: "showDataLabel",
displayName: "Data Label",
displayNameKey: "Visual_DataLabel",
value: false
});

name: string = "averageLine";
displayName: string = "Average Line";
displayNameKey: string = "Visual_AverageLine";
analyticsPane: boolean = true;
slices = [this.show, this.fill, this.showDataLabel];
}
Expand All @@ -121,14 +96,13 @@ class AverageLineCardSettings implements FormattingSettingsCard {
* @property {{generalView.opacity:number}} Bars Opacity - Controls opacity of plotted bars, values range between 10 (almost transparent) to 100 (fully opaque, default)
* @property {{generalView.showHelpLink:boolean}} Show Help Button - When TRUE, the plot displays a button which launch a link to documentation.
*/
export class BarChartSettingsModel extends formattingSettingsModel.FormattingSettingsModel {
export class BarChartSettingsModel extends FormattingSettingsModel {
enableAxis = new EnableAxisCardSettings();
colorSelector = new ColorSelectorCardSettings();
generalView = new GeneralViewCardSettings();
averageLine = new AverageLineCardSettings();
cards = [this.enableAxis, this.colorSelector, this.generalView, this.averageLine];


/**
* populate colorSelector object categories formatting properties
* @param dataPoints
Expand Down
10 changes: 10 additions & 0 deletions stringResources/en-US/resources.resjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Visual_EnableAxis" : "Enable Axis",
"Visual_Color": "Color",
"Visual_DataColors": "Data Colors",
"Visual_BarsOpacity": "Bars Opacity",
"Visual_Show_HelpButton": "Show Help Button",
"Visual_GeneralView": "General View",
"Visual_DataLabel": "Data Label",
"Visual_AverageLine": "Average Line"
}
11 changes: 11 additions & 0 deletions stringResources/he-IL/resources.resjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Visual_EnableAxis" : "הצג ציר",
"Visual_Color": "צבע",
"Visual_DataColors": "צבעי נתונים",
"Visual_BarsOpacity": "כֵּהוּת סורגים",
"Visual_Show_HelpButton": "הצג כפתור עזרה",
"Visual_GeneralView": "תצוגה כללית",
"Visual_DataLabel": "תווית נתונים",
"Visual_AverageLine": "קו ממוצע"

}

0 comments on commit 3c7df9c

Please sign in to comment.