Merge part changes from branch bootstrap, next to test HtmlInputElement

This commit is contained in:
沐见南 2020-05-01 10:43:06 +08:00
parent 56811702d2
commit c676bb727e
7 changed files with 41 additions and 24 deletions

View File

@ -14,6 +14,11 @@ export class FilterManager implements IFilterManager{
constructor(host:IVisualHost){ constructor(host:IVisualHost){
this.host=host; this.host=host;
} }
public clear():void{
console.debug("clear start:");
this.host.applyJsonFilter(null,"general","filter",powerbi.FilterAction.remove);
console.debug("clear end");
}
public update(field:powerbi.DataViewCategoryColumn):void{ public update(field:powerbi.DataViewCategoryColumn):void{
let queryName:string=field.source.queryName; let queryName:string=field.source.queryName;
let splitPosition:number=queryName.indexOf('.'); let splitPosition:number=queryName.indexOf('.');

View File

@ -3,13 +3,22 @@ import powerbi from "powerbi-visuals-api";
import DataView = powerbi.DataView; import DataView = powerbi.DataView;
import * as visualInterfaces from "../visual/visualInterfaces"; import * as visualInterfaces from "../visual/visualInterfaces";
import * as d3 from "d3"; import * as d3 from "d3";
import { ILayoutManager } from "../visual/visualInterfaces"; import { ILayoutManager,IFilterManager } from "../visual/visualInterfaces";
import { IFilter } from "powerbi-models";
type Selection<T extends d3.BaseType> = d3.Selection<T, any, any, any>; type Selection<T extends d3.BaseType> = d3.Selection<T, any, any, any>;
export class LayoutManager implements ILayoutManager{ export class LayoutManager implements ILayoutManager{
layout:Selection<HTMLElement>; layout:Selection<HTMLElement>;
// constructor(layout:Selection<HTMLElement>){ // constructor(layout:Selection<HTMLElement>){
// this.layout=layout; // this.layout=layout;
// } // }
header:Selection<HTMLDivElement>
constructor(layout:Selection<HTMLElement>,filterManager:IFilterManager){
this.layout=layout;
this.header=this.layout.append('div').attr('header',true);
this.header.append('button').attr('clear',true).text('clear').on('click',function(){
filterManager.clear();
});
}
update(dataView:DataView,width:number,height:number):void{ update(dataView:DataView,width:number,height:number):void{
//this.layout.style("width",width+"px").style("height",height+"px"); //this.layout.style("width",width+"px").style("height",height+"px");
} }

View File

@ -4,8 +4,8 @@ import * as d3 from "d3";
import powerbi from "powerbi-visuals-api"; import powerbi from "powerbi-visuals-api";
type Selection<T extends d3.BaseType> = d3.Selection<T, any, any, any>; type Selection<T extends d3.BaseType> = d3.Selection<T, any, any, any>;
export class ManagerFactory{ export class ManagerFactory{
public static CreateLayoutManager(classLayoutManager:visualInterfaces.ILayoutManagerConstructor,container:Selection<HTMLElement>):visualInterfaces.ILayoutManager{ public static CreateLayoutManager(classLayoutManager:visualInterfaces.ILayoutManagerConstructor,container:Selection<HTMLElement>,filterManager:visualInterfaces.IFilterManager):visualInterfaces.ILayoutManager{
return new classLayoutManager(container); return new classLayoutManager(container,filterManager);
} }
public static CreateSelectorManager(classSelectorManager:visualInterfaces.ISelectorManagerConstructor,container:Selection<HTMLElement>,filterManager:visualInterfaces.IFilterManager):visualInterfaces.ISelectorManager{ public static CreateSelectorManager(classSelectorManager:visualInterfaces.ISelectorManagerConstructor,container:Selection<HTMLElement>,filterManager:visualInterfaces.IFilterManager):visualInterfaces.ISelectorManager{
return new classSelectorManager(container,filterManager); return new classSelectorManager(container,filterManager);

View File

@ -26,11 +26,11 @@ export class SelectorManager implements ISelectorManager{
this.selector?.dispose(); this.selector?.dispose();
this.selector=newSelector; this.selector=newSelector;
} }
updateData(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn){ updateData(field: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn){
if(!this.selector){ if(!this.selector){
let fieldType=categories.source.type; let fieldType=field.source.type;
if(fieldType.text){ if(fieldType.text){
this.selector=new DropDownSelector(this); this.selector=new DropDownSelector(this);
}else if(fieldType.numeric){ }else if(fieldType.numeric){
@ -43,7 +43,7 @@ export class SelectorManager implements ISelectorManager{
} }
this.selector.update(categories, defaultSelect, defaultStart, defaultEnd); this.selector.update(field, defaultSelect, defaultStart, defaultEnd);
}; };
public filterStringField(selection:string[]){ public filterStringField(selection:string[]){
@ -51,7 +51,7 @@ export class SelectorManager implements ISelectorManager{
} }
interface ISelector{ interface ISelector{
update(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn); update(field: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn);
dispose():void; dispose():void;
} }
@ -64,7 +64,7 @@ abstract class Selector implements ISelector{
protected abstract createView():void; protected abstract createView():void;
public abstract dispose():void; public abstract dispose():void;
protected readonly manager:ISelectorManager; protected readonly manager:ISelectorManager;
public abstract update(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn):void; public abstract update(field: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn):void;
} }
class DropDownSelector extends Selector{ class DropDownSelector extends Selector{
private dropDown:Selection<HTMLSelectElement>; private dropDown:Selection<HTMLSelectElement>;
@ -76,9 +76,9 @@ class DropDownSelector extends Selector{
public dispose(){ public dispose(){
this.dropDown.remove(); this.dropDown.remove();
} }
public update(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn) { public update(field: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn) {
console.debug('dropDownViewManager','update start'); console.debug('dropDownViewManager','update start');
let options=this.dropDown.selectAll("option").data(categories.values,function(d){return d.toString();});//map data let options=this.dropDown.selectAll("option").data(field.values,function(d){return d.toString();});//map data
options.enter().append("option").text(function(d){return d.toString();}).attr('dropDown-option');//add options.enter().append("option").text(function(d){return d.toString();}).attr('dropDown-option');//add
options.exit().remove();//delete options.exit().remove();//delete
console.debug("dropDown:",this.dropDown); console.debug("dropDown:",this.dropDown);

View File

@ -63,20 +63,22 @@ export class Visual implements IVisual {
if (document) { if (document) {
this.selectionManager =options.host.createSelectionManager(); this.selectionManager =options.host.createSelectionManager();
let container=d3.select(options.element).append("div").classed("container",true); let container=d3.select(options.element).append("div").classed("container",true);
d3.select(options.element).on('contextmenu', () => { // d3.select(options.element).on('contextmenu', () => {
const mouseEvent: MouseEvent = <MouseEvent>d3.event; // const mouseEvent: MouseEvent = <MouseEvent>d3.event;
//const eventTarget: EventTarget = mouseEvent.target; // //const eventTarget: EventTarget = mouseEvent.target;
//let dataPoint = d3.select(eventTarget).datum(); // //let dataPoint = d3.select(eventTarget).datum();
this.selectionManager.showContextMenu({}, { // this.selectionManager.showContextMenu({}, {
x: mouseEvent.clientX, // x: mouseEvent.clientX,
y: mouseEvent.clientY // y: mouseEvent.clientY
}); // });
//mouseEvent.preventDefault(); // //mouseEvent.preventDefault();
}); // });
let headerContainer=container.append("div").classed("header-container",true); let headerContainer=container.append("div").classed("header-container",true);
let selectorContainer=container.append("div").classed("selector-container",true); let selectorContainer=container.append("div").classed("selector-container",true);
this.layoutManager=ManagerFactory.CreateLayoutManager(LayoutManager,container); //First, create the filterManager
this.filterManager=ManagerFactory.CreateFilterManager(FilterManager,options.host); this.filterManager=ManagerFactory.CreateFilterManager(FilterManager,options.host);
//Then, layoutManager and selectorManager
this.layoutManager=ManagerFactory.CreateLayoutManager(LayoutManager,container,this.filterManager);
this.selectorManager=ManagerFactory.CreateSelectorManager(SelectorManager,selectorContainer,this.filterManager); this.selectorManager=ManagerFactory.CreateSelectorManager(SelectorManager,selectorContainer,this.filterManager);
} }
console.debug('end constructor'); console.debug('end constructor');

View File

@ -16,7 +16,7 @@ export interface ILayoutManager{
update(dataView:DataView,width:number,height:number):void; update(dataView:DataView,width:number,height:number):void;
} }
export interface ILayoutManagerConstructor{ export interface ILayoutManagerConstructor{
new(container:Selection<HTMLElement>):ILayoutManager; new(container:Selection<HTMLElement>,filterManager:IFilterManager):ILayoutManager;
}; };
//ISelectorManager //ISelectorManager
@ -35,6 +35,7 @@ export interface ISelectorManagerConstructor{
export interface IFilterManager{ export interface IFilterManager{
update(field:powerbi.DataViewCategoryColumn):void; update(field:powerbi.DataViewCategoryColumn):void;
filterStringField(selection:string[]):void; filterStringField(selection:string[]):void;
clear():void;
} }
export interface IFilterManagerConstructor{ export interface IFilterManagerConstructor{
new(host:IVisualHost):IFilterManager; new(host:IVisualHost):IFilterManager;

File diff suppressed because one or more lines are too long