Add ReadMe.md, fix textSize

This commit is contained in:
沐见南 2020-02-07 22:12:42 +08:00
parent e7528900d1
commit 5a92e30690
9 changed files with 29 additions and 19 deletions

4
ReadMe.md Normal file
View File

@ -0,0 +1,4 @@
# Assign default period to date-pickers
You can assign default period by messures, just use DAX!
# Known issues
* Can't edit date in PowerBiApp(only on some Android devices)

View File

@ -52,7 +52,7 @@
] ]
} }
}, },
"fontSize":{ "textSize":{
"displayNameKey": "DatePickers_FontSize_DisplayName", "displayNameKey": "DatePickers_FontSize_DisplayName",
"displayName": "Font size", "displayName": "Font size",
"descriptionKey": "DatePickers_FontSize_Description", "descriptionKey": "DatePickers_FontSize_Description",
@ -178,7 +178,8 @@
"displayNameKey": "Period_RelativeToday_DisplayName", "displayNameKey": "Period_RelativeToday_DisplayName",
"displayName": "Contain today", "displayName": "Contain today",
"descriptionKey": "Period_RelativeToday_Description", "descriptionKey": "Period_RelativeToday_Description",
"description": "Effictive when and only when Custom(use measures) not selected" "description": "Effictive when and only when Custom(use measures) not selected",
"filterState": true
}, },
"firstDayOfWeek": { "firstDayOfWeek": {
"descriptionKey": "Period_FirstDayOfWeek_DisplayName", "descriptionKey": "Period_FirstDayOfWeek_DisplayName",
@ -222,7 +223,8 @@
"displayNameKey": "Saturday" "displayNameKey": "Saturday"
} }
] ]
} },
"filterState": true
} }
} }
}, },

View File

@ -18,7 +18,8 @@
"powerbi-models": "^1.3.1", "powerbi-models": "^1.3.1",
"powerbi-visuals-api": "~2.6.1", "powerbi-visuals-api": "~2.6.1",
"powerbi-visuals-utils-dataviewutils": "2.2.1", "powerbi-visuals-utils-dataviewutils": "2.2.1",
"powerbi-visuals-utils-interactivityutils": "^5.6.0" "powerbi-visuals-utils-interactivityutils": "^5.6.0",
"powerbi-visuals-utils-typeutils": "^2.2.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.8.4", "@babel/core": "^7.8.4",

View File

@ -6,13 +6,13 @@
"visualClassName": "Visual", "visualClassName": "Visual",
"version": "1.0.0", "version": "1.0.0",
"description": "A period slicer, which can be initialized by messures.", "description": "A period slicer, which can be initialized by messures.",
"supportUrl": "https://github.com/mujiannan/PeriodSlicer-Syinpo", "supportUrl": "https://github.com/mujiannan/PeriodSlicer-Syinpo/issues",
"gitHubUrl": "https://github.com/mujiannan/PeriodSlicer-Syinpo" "gitHubUrl": "https://github.com/mujiannan/PeriodSlicer-Syinpo"
}, },
"apiVersion": "2.6.0", "apiVersion": "2.6.0",
"author": { "author": {
"name": "MuJianNan", "name": "shennan",
"email": "littlesand@outlook.com" "email": "shennan@syinpo.com"
}, },
"assets": { "assets": {
"icon": "assets/icon.png" "icon": "assets/icon.png"

View File

@ -2,11 +2,11 @@
import { OrientationType } from "./datePeriod"; import { OrientationType } from "./datePeriod";
export class DatePickerSetting { export class DatePickerSetting {
public orientationType: OrientationType = OrientationType.Horizontal; public orientationType: OrientationType = OrientationType.Horizontal;
public fontSize: number = 12; public textSize: number = 9;
public fontColor: string = "black"; public fontColor: string = "black";
public backgroundColor: string = "white"; public backgroundColor: string = "white";
public backgroundTransparency: number = 0; public backgroundTransparency: number = 0;
public borderWidth: number = 1; public borderWidth: number = 1;
public borderColor: string = "gray"; public borderColor: string = "lightgray";
public outlineColor: string = "blue"; public outlineColor: string = "blue";
} }

View File

@ -45,6 +45,7 @@ import { stratify, rgb } from "d3";
import * as models from 'powerbi-models'; import * as models from 'powerbi-models';
import { IAdvancedFilter } from "powerbi-models"; import { IAdvancedFilter } from "powerbi-models";
import IVisualEventService=powerbi.extensibility.IVisualEventService; import IVisualEventService=powerbi.extensibility.IVisualEventService;
import {pixelConverter} from "powerbi-visuals-utils-typeutils";
//custom //custom
import { IPeriod, Period, DefaultPeriodType,OrientationType } from "./settings/datePeriod/datePeriod"; import { IPeriod, Period, DefaultPeriodType,OrientationType } from "./settings/datePeriod/datePeriod";
import { RelativePeriodHelper } from "./settings/datePeriod/relativePeriodHelper"; import { RelativePeriodHelper } from "./settings/datePeriod/relativePeriodHelper";
@ -96,19 +97,24 @@ export class Visual implements IVisual {
} }
public update(options: VisualUpdateOptions) { public update(options: VisualUpdateOptions) {
//pbi //pbi
this.events.renderingStarted(options); this.events.renderingStarted(options);
this.settings = Visual.parseSettings(options && options.dataViews && options.dataViews[0]); this.settings = Visual.parseSettings(options && options.dataViews && options.dataViews[0]);
let dataView = options.dataViews[0];
this.category = dataView.categorical.categories[0];
//style
let width: number = options.viewport.width; let width: number = options.viewport.width;
if(this.settings.datePickers.backgroundTransparency<0||this.settings.datePickers.backgroundTransparency>1){ if(this.settings.datePickers.backgroundTransparency<0||this.settings.datePickers.backgroundTransparency>1){
this.settings.datePickers.backgroundTransparency=0; this.settings.datePickers.backgroundTransparency=0;
} }
let backgroundColor=d3.rgb(this.settings.datePickers.backgroundColor).rgb(); let backgroundColor=d3.rgb(this.settings.datePickers.backgroundColor).rgb();
let backgroundColorWithTransparency=rgb(backgroundColor.r,backgroundColor.g,backgroundColor.b,1-this.settings.datePickers.backgroundTransparency).toString(); let backgroundColorWithTransparency=rgb(backgroundColor.r,backgroundColor.g,backgroundColor.b,1-this.settings.datePickers.backgroundTransparency).toString();
let fontSize:number=pixelConverter.fromPointToPixel(this.settings.datePickers.textSize);
let datePickerWidth:number=(this.settings.datePickers.orientationType==OrientationType.Horizontal)?width/2-10-4*this.settings.datePickers.borderWidth:width-10-2*this.settings.datePickers.borderWidth;
//Set style for these date-pickers one-by-one, but not group by class //Set style for these date-pickers one-by-one, but not group by class
let datePickerWidth:number=(this.settings.datePickers.orientationType==OrientationType.Horizontal)?width/2-8-4*this.settings.datePickers.borderWidth:width-8-2*this.settings.datePickers.borderWidth;
this.periodSelectorManager.dateSelector_Start this.periodSelectorManager.dateSelector_Start
.style("width", datePickerWidth + "px") .style("width", datePickerWidth + "px")
.style("font-size",this.settings.datePickers.fontSize+"px") .style("font-size",fontSize+"px")
.style("color",this.settings.datePickers.fontColor) .style("color",this.settings.datePickers.fontColor)
.style("background-color",backgroundColorWithTransparency) .style("background-color",backgroundColorWithTransparency)
.style("border-width",this.settings.datePickers.borderWidth+"px") .style("border-width",this.settings.datePickers.borderWidth+"px")
@ -117,15 +123,12 @@ export class Visual implements IVisual {
.style("display", (this.settings.datePickers.orientationType==OrientationType.Horizontal)?"inline":"block"); .style("display", (this.settings.datePickers.orientationType==OrientationType.Horizontal)?"inline":"block");
this.periodSelectorManager.dateSelector_End this.periodSelectorManager.dateSelector_End
.style("width", datePickerWidth+"px") .style("width", datePickerWidth+"px")
.style("font-size",this.settings.datePickers.fontSize+"px") .style("font-size",fontSize+"px")
.style("color",this.settings.datePickers.fontColor) .style("color",this.settings.datePickers.fontColor)
.style("background-color",backgroundColorWithTransparency) .style("background-color",backgroundColorWithTransparency)
.style("border-width",this.settings.datePickers.borderWidth+"px") .style("border-width",this.settings.datePickers.borderWidth+"px")
.style("border-color",this.settings.datePickers.borderColor) .style("border-color",this.settings.datePickers.borderColor)
.style("display", (this.settings.datePickers.orientationType==OrientationType.Horizontal)?"inline":"block"); .style("display", (this.settings.datePickers.orientationType==OrientationType.Horizontal)?"inline":"block");
let dataView = options.dataViews[0];
//set date series
this.category = dataView.categorical.categories[0];
//set new default period //set new default period
let newDefaultPeriod: IPeriod = new Period(); let newDefaultPeriod: IPeriod = new Period();
if (this.settings.period.defaultPeriodType == DefaultPeriodType.Custom) { if (this.settings.period.defaultPeriodType == DefaultPeriodType.Custom) {

View File

@ -30,8 +30,8 @@
"Vertical":"垂直", "Vertical":"垂直",
"Obj_DatePickers_DisplayName":"日期选择器外观", "Obj_DatePickers_DisplayName":"日期选择器外观",
"Obj_DatePickers_Description":"设置两个日期选择器的外观", "Obj_DatePickers_Description":"设置两个日期选择器的外观",
"DatePickers_FontSize_DisplayName":"字体", "DatePickers_FontSize_DisplayName":"文本大小",
"DatePickers_FontSize_Description":"设置字体大小单位px无大小限制但请注意保持合适", "DatePickers_FontSize_Description":"设置文本字体大小",
"DatePickers_FontColor_DisplayName":"字体颜色", "DatePickers_FontColor_DisplayName":"字体颜色",
"DatePickers_FontColor_Description":"设置字体颜色", "DatePickers_FontColor_Description":"设置字体颜色",
"DatePickers_BackgroundColor_DisplayName":"背景色", "DatePickers_BackgroundColor_DisplayName":"背景色",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long