Skip to content

Commit

Permalink
added localization strings (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgaliev authored and ignatvilesov committed Apr 13, 2018
1 parent 59c6815 commit c1a4eb9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"powerbi-visuals-utils-formattingutils": "^3.0.0",
"powerbi-visuals-utils-interactivityutils": "3.2.0",
"powerbi-visuals-utils-svgutils": "^1.1.0",
"powerbi-visuals-utils-testutils": "1.2.0",
"powerbi-visuals-utils-testutils": "1.2.1",
"powerbi-visuals-utils-tooltiputils": "^1.0.0",
"powerbi-visuals-utils-typeutils": "^1.1.0",
"tslint": "^5.1.0",
Expand Down
35 changes: 20 additions & 15 deletions src/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ module powerbi.extensibility.visual {

export class Histogram implements IVisual {
private static ClassName: string = "histogram";
private static FrequencyText: string = "Frequency";
private static DensityText: string = "Density";

private static Axes: ClassAndSelector = createClassAndSelector("axes");
private static Axis: ClassAndSelector = createClassAndSelector("axis");
Expand Down Expand Up @@ -170,7 +168,6 @@ module powerbi.extensibility.visual {

private static MinColumnHeight: number = 1;

private static TooltipDisplayName: string = "Range";
private static SeparatorNumbers: string = ", ";

private static MaxWidthOfTheLatestLabel: number = 40;
Expand Down Expand Up @@ -225,6 +222,7 @@ module powerbi.extensibility.visual {
private viewportIn: IViewport;

private visualHost: IVisualHost;
private localizationManager: ILocalizationManager;
private interactivityService: IInteractivityService;
private behavior: IInteractiveBehavior;

Expand Down Expand Up @@ -253,6 +251,7 @@ module powerbi.extensibility.visual {

public init(options: VisualConstructorOptions): void {
this.visualHost = options.host;
this.localizationManager = this.visualHost.createLocalizationManager();

this.interactivityService = createInteractivityService(this.visualHost);
this.behavior = HistogramBehavior.create();
Expand Down Expand Up @@ -298,7 +297,8 @@ module powerbi.extensibility.visual {

public static converter(
dataView: DataView,
visualHost: IVisualHost): HistogramDataView {
visualHost: IVisualHost,
localizationManager: ILocalizationManager): HistogramDataView {

if (!dataView
|| !dataView.categorical
Expand Down Expand Up @@ -437,7 +437,8 @@ module powerbi.extensibility.visual {
bins,
settings,
yLabelFormatter,
xLabelFormatter);
xLabelFormatter,
localizationManager);

return {
dataPoints,
Expand Down Expand Up @@ -574,7 +575,8 @@ module powerbi.extensibility.visual {
bins: LayoutBin<number>[],
settings: HistogramSettings,
yValueFormatter: IValueFormatter,
xValueFormatter: IValueFormatter): HistogramDataPoint[] {
xValueFormatter: IValueFormatter,
localizationManager: ILocalizationManager): HistogramDataPoint[] {

let fontSizeInPx: string = PixelConverter.fromPoint(settings.labels.fontSize);

Expand All @@ -587,7 +589,8 @@ module powerbi.extensibility.visual {
settings,
index === 0,
yValueFormatter,
xValueFormatter);
xValueFormatter,
localizationManager);

bin.subDataPoints = Histogram.getSubDataPoints(values, bin, index);

Expand All @@ -607,14 +610,15 @@ module powerbi.extensibility.visual {
settings: HistogramSettings,
includeLeftBorder: boolean,
yValueFormatter: IValueFormatter,
xValueFormatter: IValueFormatter): VisualTooltipDataItem[] {
xValueFormatter: IValueFormatter,
localizationManager: ILocalizationManager): VisualTooltipDataItem[] {

return [
{
displayName: Histogram.getLegendText(settings),
displayName: Histogram.getLegendText(settings, localizationManager),
value: yValueFormatter.format(value)
}, {
displayName: Histogram.TooltipDisplayName,
displayName: localizationManager.getDisplayName("Visual_TooltipDisplayName"),
value: Histogram.rangeToString(range, includeLeftBorder, xValueFormatter)
}
];
Expand Down Expand Up @@ -754,7 +758,8 @@ module powerbi.extensibility.visual {

this.dataView = Histogram.converter(
dataView,
this.visualHost);
this.visualHost,
this.localizationManager);

borderValues = this.dataView.borderValues;
xAxisSettings = this.dataView.settings.xAxis;
Expand Down Expand Up @@ -1324,7 +1329,7 @@ module powerbi.extensibility.visual {
}

private getDataLegends(settings: HistogramSettings): Legend[] {
let bottomLegendText: string = Histogram.getLegendText(settings);
let bottomLegendText: string = Histogram.getLegendText(settings, this.localizationManager);

bottomLegendText = Histogram.getLegend(
bottomLegendText,
Expand Down Expand Up @@ -1358,10 +1363,10 @@ module powerbi.extensibility.visual {
];
}

private static getLegendText(settings: HistogramSettings): string {
private static getLegendText(settings: HistogramSettings, localizationManager: ILocalizationManager): string {
return settings.general.frequency
? Histogram.FrequencyText
: Histogram.DensityText;
? localizationManager.getDisplayName("Visual_Frequency")
: localizationManager.getDisplayName("Visual_Density");
}

private bindSelectionHandler(columnsSelection: UpdateSelection<HistogramDataPoint>): void {
Expand Down
5 changes: 4 additions & 1 deletion stringResources/en-US/resources.resjson
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"Visual_TextSize": "Text Size",
"Visual_Values": "Values",
"Visual_Frequency": "Frequency",
"Visual_Fill": "Fill"
"Visual_Fill": "Fill",
"Visual_Frequency": "Frequency",
"Visual_Density": "Density",
"Visual_TooltipDisplayName": "Range"
}

0 comments on commit c1a4eb9

Please sign in to comment.