Cant solve bookmark, sync
This commit is contained in:
parent
ad38c05613
commit
17015f13e6
@ -1,5 +1,9 @@
|
|||||||
# A utility slicer for Power Bi
|
# A utility slicer for Power Bi
|
||||||
Assign default selection to this slicer by messures, just use DAX!
|
Assign default selection to this slicer by messures, just use DAX!
|
||||||
|
## Tutorial
|
||||||
|
1. Click the top right corner of this slicer
|
||||||
|
1. Click "Edit"
|
||||||
|
1. Save&publish the report
|
||||||
## Functionalities
|
## Functionalities
|
||||||
* Implemented
|
* Implemented
|
||||||
1. Dropdown-slicer for text field
|
1. Dropdown-slicer for text field
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"supportsSynchronizingFilterState": true,
|
"supportsSynchronizingFilterState": true,
|
||||||
|
"advancedEditModeSupport": 1,
|
||||||
"dataRoles": [
|
"dataRoles": [
|
||||||
{
|
{
|
||||||
"displayName": "Field",
|
"displayName": "Field",
|
||||||
@ -134,6 +135,22 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"outlineColor":{
|
||||||
|
"displayName": "Outline color",
|
||||||
|
"type": {
|
||||||
|
"fill": {
|
||||||
|
"solid": {
|
||||||
|
"color":true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"outlineWeight":{
|
||||||
|
"displayName": "Outline weight",
|
||||||
|
"type":{
|
||||||
|
"integer": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"showAllDataPoints": {
|
"showAllDataPoints": {
|
||||||
"displayName": "Show all",
|
"displayName": "Show all",
|
||||||
"type": {
|
"type": {
|
||||||
|
@ -11,16 +11,26 @@ import { select, json } from "d3";
|
|||||||
export class FilterManager implements IFilterManager{
|
export class FilterManager implements IFilterManager{
|
||||||
private target: models.IFilterColumnTarget={table:'',column:''};
|
private target: models.IFilterColumnTarget={table:'',column:''};
|
||||||
private host:IVisualHost;
|
private host:IVisualHost;
|
||||||
private _jsonFilter:powerbi.IFilter;
|
private _jsonFilter:models.IAdvancedFilter;
|
||||||
|
|
||||||
public get jsonFilter() : powerbi.IFilter {
|
public get jsonFilter() : models.IAdvancedFilter {
|
||||||
return this._jsonFilter;
|
return this._jsonFilter;
|
||||||
}
|
}
|
||||||
|
public get advancedEditModeMark():string{
|
||||||
|
return 'SyinpoSlicer_AdvancedEditMode_'+this.inAdvancedEditMode;
|
||||||
|
}
|
||||||
constructor(host:IVisualHost){
|
constructor(host:IVisualHost){
|
||||||
this.host=host;
|
this.host=host;
|
||||||
}
|
}
|
||||||
setFilter(jsonFilter: powerbi.IFilter,applyNow:boolean): void {
|
_inAdvancedEditMode: boolean=false;
|
||||||
|
public set inAdvancedEditMode(newValue:boolean){
|
||||||
|
this._inAdvancedEditMode=this._inAdvancedEditMode?true:newValue;
|
||||||
|
}
|
||||||
|
public get inAdvancedEditMode():boolean{
|
||||||
|
return this._inAdvancedEditMode;
|
||||||
|
}
|
||||||
|
setFilter(jsonFilter:models.IAdvancedFilter,applyNow:boolean): void {
|
||||||
|
jsonFilter.conditions[0].value=this.advancedEditModeMark
|
||||||
this._jsonFilter=jsonFilter;
|
this._jsonFilter=jsonFilter;
|
||||||
if(applyNow){
|
if(applyNow){
|
||||||
this.applyJsonFilter();
|
this.applyJsonFilter();
|
||||||
@ -30,6 +40,7 @@ export class FilterManager implements IFilterManager{
|
|||||||
public applyJsonFilter():void{
|
public applyJsonFilter():void{
|
||||||
console.debug('filter manager applyJsonFilter start');
|
console.debug('filter manager applyJsonFilter start');
|
||||||
this.host.applyJsonFilter(this._jsonFilter,'general','filter',powerbi.FilterAction.merge);
|
this.host.applyJsonFilter(this._jsonFilter,'general','filter',powerbi.FilterAction.merge);
|
||||||
|
console.debug(this.jsonFilter);
|
||||||
console.debug('filter manager applyJsonFilter end');
|
console.debug('filter manager applyJsonFilter end');
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -58,12 +69,25 @@ export class FilterManager implements IFilterManager{
|
|||||||
}
|
}
|
||||||
public setFilter_String(selection:string[],applyNow:boolean):void{
|
public setFilter_String(selection:string[],applyNow:boolean):void{
|
||||||
console.debug("setFilter_String start:",selection);
|
console.debug("setFilter_String start:",selection);
|
||||||
let jsonFilter:models.IBasicFilter={
|
let conditions:models.IAdvancedFilterCondition[]=[];
|
||||||
"$schema": "http://powerbi.com/product/schema#basic",
|
|
||||||
|
conditions.push({
|
||||||
|
"operator":"StartsWith",
|
||||||
|
"value":this.advancedEditModeMark
|
||||||
|
});
|
||||||
|
|
||||||
|
selection.forEach(function(item){
|
||||||
|
conditions.push({
|
||||||
|
"operator":"Is",
|
||||||
|
"value":item
|
||||||
|
});
|
||||||
|
});
|
||||||
|
let jsonFilter:models.IAdvancedFilter={
|
||||||
|
"$schema": "http://powerbi.com/product/schema#advanced",
|
||||||
"target": this.target,
|
"target": this.target,
|
||||||
"filterType": models.FilterType.Basic,
|
"filterType": models.FilterType.Advanced,
|
||||||
"operator":"In",
|
"conditions":conditions,
|
||||||
"values": selection
|
"logicalOperator":"Or"
|
||||||
}
|
}
|
||||||
console.debug("jsonFilter:",jsonFilter);
|
console.debug("jsonFilter:",jsonFilter);
|
||||||
this._jsonFilter=jsonFilter;
|
this._jsonFilter=jsonFilter;
|
||||||
|
@ -32,10 +32,8 @@ export class DropDownSelector extends Selector {
|
|||||||
.style('border-width', '2px')
|
.style('border-width', '2px')
|
||||||
.style('border-color', 'black');
|
.style('border-color', 'black');
|
||||||
this.dropDown.selectAll('option').style('background-color', itemsSetting.backgroundColor)
|
this.dropDown.selectAll('option').style('background-color', itemsSetting.backgroundColor)
|
||||||
.style('padding','0px 0px')
|
|
||||||
.style('color', itemsSetting.fontColor)
|
.style('color', itemsSetting.fontColor)
|
||||||
.style('font-size', itemsSetting.textSize + 'px')
|
.style('font-size', pixelConverter.fromPointToPixel(itemsSetting.textSize) + 'px')
|
||||||
.style('width', (width - 10) + 'px')
|
|
||||||
.style('border-style', settings.Enums.getOutlineStyle(itemsSetting.outline))
|
.style('border-style', settings.Enums.getOutlineStyle(itemsSetting.outline))
|
||||||
.style('border-width', '2px')
|
.style('border-width', '2px')
|
||||||
.style('border-color', 'black');
|
.style('border-color', 'black');
|
||||||
|
@ -6,4 +6,6 @@ export class SlicerHeaderSetting{
|
|||||||
public fontColor:string='';
|
public fontColor:string='';
|
||||||
public backgroundColor:string='';
|
public backgroundColor:string='';
|
||||||
public outline:enums.Outline=enums.Outline.None;
|
public outline:enums.Outline=enums.Outline.None;
|
||||||
|
public outlineWeight:number=2;
|
||||||
|
public outlineColor:string="gray";
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ import { getMeasureIndexOfRole } from "powerbi-visuals-utils-dataviewutils/lib/d
|
|||||||
import { selector, json } from "d3";
|
import { selector, json } from "d3";
|
||||||
import { debuglog } from "util";
|
import { debuglog } from "util";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
|
import * as models from 'powerbi-models';
|
||||||
export class Visual implements IVisual {
|
export class Visual implements IVisual {
|
||||||
/*
|
/*
|
||||||
SelectorManager: a custom manager, used to manage dropDownSelector, listSelector, calendarSelector, and so on
|
SelectorManager: a custom manager, used to manage dropDownSelector, listSelector, calendarSelector, and so on
|
||||||
@ -64,6 +64,7 @@ export class Visual implements IVisual {
|
|||||||
//private selectionManager:powerbi.extensibility.ISelectionManager;
|
//private selectionManager:powerbi.extensibility.ISelectionManager;
|
||||||
constructor(options: VisualConstructorOptions) {
|
constructor(options: VisualConstructorOptions) {
|
||||||
console.debug('Visual constructor start');
|
console.debug('Visual constructor start');
|
||||||
|
console.debug('options:',options);
|
||||||
this.events = options.host.eventService;
|
this.events = options.host.eventService;
|
||||||
if (document) {
|
if (document) {
|
||||||
//this.selectionManager =options.host.createSelectionManager();
|
//this.selectionManager =options.host.createSelectionManager();
|
||||||
@ -107,8 +108,10 @@ export class Visual implements IVisual {
|
|||||||
public update(options: VisualUpdateOptions) {
|
public update(options: VisualUpdateOptions) {
|
||||||
console.debug('visual update start');
|
console.debug('visual update start');
|
||||||
console.debug('id:',this.id);
|
console.debug('id:',this.id);
|
||||||
|
console.debug('options:',options);
|
||||||
//console.debug('operationKind',options.operationKind.toString());
|
//console.debug('operationKind',options.operationKind.toString());
|
||||||
this.events.renderingStarted(options);
|
this.events.renderingStarted(options);
|
||||||
|
this.filterManager.inAdvancedEditMode=options.editMode==powerbi.EditMode.Advanced
|
||||||
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];
|
let dataView=options.dataViews[0];
|
||||||
let field=dataView.categorical.categories[0];
|
let field=dataView.categorical.categories[0];
|
||||||
@ -159,11 +162,24 @@ export class Visual implements IVisual {
|
|||||||
console.debug('options.jsonFilters[0] is not null');
|
console.debug('options.jsonFilters[0] is not null');
|
||||||
if((!this.filterManager.jsonFilter)||
|
if((!this.filterManager.jsonFilter)||
|
||||||
(JSON.stringify(this.filterManager.jsonFilter)!=JSON.stringify(options.jsonFilters[0]))){
|
(JSON.stringify(this.filterManager.jsonFilter)!=JSON.stringify(options.jsonFilters[0]))){
|
||||||
//Sync slicers
|
console.debug('Two filter are different');
|
||||||
console.debug('Sync slicers init or restore a bookmark start');
|
let advancedFilter:models.IAdvancedFilter=options.jsonFilters[0] as models.IAdvancedFilter;
|
||||||
this.filterManager.setFilter(options.jsonFilters[0],false);
|
console.debug("Cast as advancedFilter:",advancedFilter);
|
||||||
this.selectorManager.select(options.jsonFilters[0]['values'])
|
if(advancedFilter.conditions[0].value=='SyinpoSlicer_AdvancedEditMode_true'){
|
||||||
console.debug('Sync slicers init or restore a bookmark end');
|
console.debug('previous filter is created in AdvancedEditMode');
|
||||||
|
}else{
|
||||||
|
//Sync slicers
|
||||||
|
console.debug('Sync slicers init or restore a bookmark start');
|
||||||
|
this.filterManager.setFilter(advancedFilter,false);
|
||||||
|
let oldSelection:string[]=[];
|
||||||
|
advancedFilter.conditions.map(function(condition,index){
|
||||||
|
oldSelection.push(condition.value as string);
|
||||||
|
});
|
||||||
|
this.selectorManager.select(oldSelection);
|
||||||
|
console.debug('Sync slicers init or restore a bookmark end');
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
console.debug('Two filter are equal');
|
||||||
}//end if
|
}//end if
|
||||||
}else{
|
}else{
|
||||||
console.debug('Neednt init a sync slicer or restore a bookmark');
|
console.debug('Neednt init a sync slicer or restore a bookmark');
|
||||||
|
@ -43,10 +43,11 @@ export interface ISelectorManagerConstructor{
|
|||||||
|
|
||||||
//IFilterManager
|
//IFilterManager
|
||||||
export interface IFilterManager{
|
export interface IFilterManager{
|
||||||
jsonFilter:powerbi.IFilter;
|
jsonFilter:models.IAdvancedFilter;
|
||||||
|
inAdvancedEditMode:boolean;
|
||||||
update(field:powerbi.DataViewCategoryColumn):void;
|
update(field:powerbi.DataViewCategoryColumn):void;
|
||||||
setFilter_String(selection:string[],applyNow:boolean):void;
|
setFilter_String(selection:string[],applyNow:boolean):void;
|
||||||
setFilter(jsonFilter:powerbi.IFilter,applyNow:boolean):void;
|
setFilter(jsonFilter:models.IAdvancedFilter,applyNow:boolean):void;
|
||||||
applyJsonFilter():void;
|
applyJsonFilter():void;
|
||||||
clear():void;
|
clear():void;
|
||||||
dispose():void;
|
dispose():void;
|
||||||
|
Loading…
Reference in New Issue
Block a user