diff --git a/pbiviz.json b/pbiviz.json index 8b41d7f..c7bd230 100644 --- a/pbiviz.json +++ b/pbiviz.json @@ -1 +1,25 @@ -{"visual":{"name":"syinpoSlicer","displayName":"SyinpoSlicer","guid":"syinpoSlicer1E14A7D0BD9E4C9B99612FBE9E84697A","visualClassName":"Visual","version":"1.0.0","description":"","supportUrl":"","gitHubUrl":""},"apiVersion":"2.6.0","author":{"name":"","email":""},"assets":{"icon":"assets/icon.png"},"externalJS":null,"style":"style/visual.less","capabilities":"capabilities.json","dependencies":null,"stringResources":[]} +{ + "visual": { + "name": "syinpoSlicer", + "displayName": "SyinpoSlicer", + "guid": "syinpoSlicer1E14A7D0BD9E4C9B99612FBE9E84697A", + "visualClassName": "Visual", + "version": "1.0.0", + "description": "", + "supportUrl": "", + "gitHubUrl": "" + }, + "apiVersion": "2.6.0", + "author": { + "name": "", + "email": "" + }, + "assets": { + "icon": "assets/icon.png" + }, + "externalJS": null, + "style": "style/visual.less", + "capabilities": "capabilities.json", + "dependencies": null, + "stringResources": [] +} \ No newline at end of file diff --git a/src/managers/filterManager.ts b/src/managers/filterManager.ts new file mode 100644 index 0000000..c76fa2b --- /dev/null +++ b/src/managers/filterManager.ts @@ -0,0 +1,23 @@ +"Use strict"; +import powerbi from "powerbi-visuals-api"; +import DataView = powerbi.DataView; +import * as visualInterfaces from "../visual/visualInterfaces"; +import * as d3 from "d3"; +import { IFilterManager } from "../visual/visualInterfaces"; +export default class FilterManager implements IFilterManager{ + applyFilter(): void { + throw new Error("Method not implemented."); + } + setJsonFilter(field: number | Text, select: number | Text): void; + setJsonFilter(field: number, start: number, end: number): void; + setJsonFilter(field: any, start: any, end?: any) { + throw new Error("Method not implemented."); + } + setJsonFitler(filter: Date, select: Date): void { + throw new Error("Method not implemented."); + } + applyJsonFilter(filter: powerbi.IFilter | powerbi.IFilter[], objectName: string, propertyName: string, action: powerbi.FilterAction): void { + + } + +} \ No newline at end of file diff --git a/src/managers/index.ts b/src/managers/index.ts new file mode 100644 index 0000000..207b51a --- /dev/null +++ b/src/managers/index.ts @@ -0,0 +1,4 @@ +export {default as filterManager} from "./filterManager"; +export {default as layoutManager} from "./layoutManager"; +export {default as selectorManager} from "./selectorManager"; +export {default as managerFactory} from "./managerFactory"; \ No newline at end of file diff --git a/src/managers/layoutManager.ts b/src/managers/layoutManager.ts index d59d5ab..8642c39 100644 --- a/src/managers/layoutManager.ts +++ b/src/managers/layoutManager.ts @@ -2,13 +2,15 @@ import powerbi from "powerbi-visuals-api"; import DataView = powerbi.DataView; import * as visualInterfaces from "../visual/visualInterfaces"; -import * as viewManager from "./viewManager"; -export class layoutManager implements layoutManager{ - layout:HTMLElement; - constructor(layout:HTMLElement){ +import * as d3 from "d3"; +import { ILayoutManager } from "../visual/visualInterfaces"; +type Selection = d3.Selection; +export default class LayoutManager implements ILayoutManager{ + layout:Selection; + constructor(layout:Selection){ this.layout=layout; } - updateLayout(dataView:DataView):visualInterfaces.viewManager{ - return new viewManager.dropDownViewManager(); + update(dataView:DataView):void{ + } -} \ No newline at end of file +} diff --git a/src/managers/managerFactory.ts b/src/managers/managerFactory.ts new file mode 100644 index 0000000..d5e1098 --- /dev/null +++ b/src/managers/managerFactory.ts @@ -0,0 +1,16 @@ +"Use strict"; +import * as visualInterfaces from "../visual/visualInterfaces"; +import * as d3 from "d3"; +import powerbi from "powerbi-visuals-api"; +type Selection = d3.Selection; +export default class ManagerFactory{ + public static CreateLayoutManager(classLayoutManager:visualInterfaces.ILayoutManagerConstructor,container:Selection):visualInterfaces.ILayoutManager{ + return new classLayoutManager(container); + } + public static CreateSelectorManager(classSelectorManager:visualInterfaces.ISelectorManagerConstructor,container:Selection):visualInterfaces.ISelectorManager{ + return new classSelectorManager(container); + } + public static CreateFilterManager(classSelectorManager:visualInterfaces.IFilterManagerConstructor,host:powerbi.extensibility.IVisualHost):visualInterfaces.IFilterManager{ + return new classSelectorManager(host); + } +} diff --git a/src/managers/selectorManager.ts b/src/managers/selectorManager.ts new file mode 100644 index 0000000..63a375b --- /dev/null +++ b/src/managers/selectorManager.ts @@ -0,0 +1,79 @@ +"Use strict"; +import powerbi from "powerbi-visuals-api"; +import {ISelectorManager} from "../visual/visualInterfaces"; +import * as d3 from "d3"; +type Selection = d3.Selection; + +export default class SelectorManager implements ISelectorManager{ + public selectorContainer : Selection; + private selector; + + constructor(selectorContainer:Selection){ + this.selectorContainer=selectorContainer; + } + public switchSelector(c:new ()=>T){ + if(typeof(this.selector)!=typeof(c)){ + console.debug(typeof(this.selector)); + console.debug(typeof(c)); + } + let newSelector=new c(); + this.selector?.dispose(); + this.selector=newSelector; + } + updateView(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn){ + if(!this.selector){ + this.selector=new DropDownSelector(this); + } + this.selector.update(categories, defaultSelect, defaultStart, defaultEnd); + }; +} + +interface ISelector{ + update(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn); +} + +abstract class Selector implements ISelector{ + constructor(manager: ISelectorManager){ + console.debug("Abstract selector:","constructor start"); + this.manager=manager; + this.createView(); + } + protected view:Selection; + protected abstract createView(); + public dispose(){ + this.view?.remove(); + } + protected readonly manager:ISelectorManager; + public abstract update(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn); +} +class DropDownSelector extends Selector{ + protected createView() { + console.debug('dropDownViewManager','createView start'); + this.view=this.manager.selectorContainer.append("select").classed("dropDown-selector",true).classed("selector",true); + console.debug('dropDownViewManager','createView end'); + } + public update(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn) { + console.debug('dropDownViewManager','update start'); + this.view.selectAll("option").remove(); + this.view.selectAll("option").data(categories.values).enter().append("option").text(function(d){return d.toString();}); + console.debug('dropDownViewManager','update end'); + } +} +class ListSelector extends Selector{ + protected createView() { + throw new Error("Method not implemented."); + } + public update(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn) { + console.debug('ListSelector','updateView'); + let dropDownSelector=this.manager.selectorContainer.append("select").classed("listSelector"); + } +} +class CalendarSelector extends Selector{ + protected createView() { + throw new Error("Method not implemented."); + } + public update(categories: powerbi.DataViewCategoryColumn, defaultSelect: powerbi.DataViewValueColumn, defaultStart: powerbi.DataViewValueColumn, defaultEnd: powerbi.DataViewValueColumn) { + console.debug('calendarViewManager','updateView'); + let dropDownSelector=this.manager.selectorContainer.append("select").classed("listSelector"); + } +} \ No newline at end of file diff --git a/src/managers/viewManager.ts b/src/managers/viewManager.ts deleted file mode 100644 index 8e58c4f..0000000 --- a/src/managers/viewManager.ts +++ /dev/null @@ -1,20 +0,0 @@ -"Use strict"; -import {viewManager} from "../visual/visualInterfaces"; -export class dropDownViewManager implements viewManager{ - view: HTMLElement; - updateView(categories: Text, defaultSelect: Text) { - console.debug('dropDownViewManager','updateView') - } -} -export class listViewManager implements viewManager{ - view: HTMLElement; - updateView(categories: Text, defaultSelect: Text) { - console.debug('dropDownViewManager','updateView') - } -} -export class calendalViewManager implements viewManager{ - view: HTMLElement; - updateView(categories: Text, defaultSelect: Text) { - console.debug('dropDownViewManager','updateView') - } -} \ No newline at end of file diff --git a/src/visual/visual.ts b/src/visual/visual.ts index 8fe4a85..d94369a 100644 --- a/src/visual/visual.ts +++ b/src/visual/visual.ts @@ -26,7 +26,7 @@ "use strict"; import "core-js/stable"; -import "./../style/visual.less"; +import "../../style/visual.less"; import powerbi from "powerbi-visuals-api"; import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions; import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions; @@ -38,23 +38,30 @@ import VisualObjectInstanceEnumerationObject = powerbi.VisualObjectInstanceEnume import IVisualEventService = powerbi.extensibility.IVisualEventService; import * as visualInterfaces from "./visualInterfaces"; import { VisualSettings } from "../settings/visualSettings"; -import * as viewManager from "../managers/viewManager"; -import { layoutManager } from "../managers/layoutManager"; +import {filterManager,managerFactory,selectorManager,layoutManager} from "../managers"; import * as d3 from "d3"; +import { getObject } from "powerbi-visuals-utils-dataviewutils/lib/dataViewObjects"; +import { getMeasureIndexOfRole } from "powerbi-visuals-utils-dataviewutils/lib/dataRoleHelper"; +import { selector } from "d3"; + export class Visual implements IVisual { private events: IVisualEventService; - private target: HTMLElement; private settings: VisualSettings; - private layoutManager: layoutManager; - private viewManager: visualInterfaces.viewManager; + private layoutManager: visualInterfaces.ILayoutManager; + private selectorManager: visualInterfaces.ISelectorManager; private view:SVGElement; - + private filterManager:visualInterfaces.IFilterManager; constructor(options: VisualConstructorOptions) { console.log('Visual constructor', options); this.events = options.host.eventService; if (document) { - this.layoutManager=new layoutManager(options.element); + let container=d3.select(options.element).append("div").classed("container",true); + let headerContainer=container.append("div").classed("header-container",true); + let selectorContainer=container.append("div").classed("selector-container",true); + this.layoutManager=managerFactory.CreateLayoutManager(layoutManager,container); + this.selectorManager=managerFactory.CreateSelectorManager(selectorManager,selectorContainer); + this.filterManager=managerFactory.CreateFilterManager(filterManager,options.host); } console.debug('end constructor'); } @@ -64,7 +71,24 @@ export class Visual implements IVisual { this.events.renderingStarted(options); this.settings = Visual.parseSettings(options && options.dataViews && options.dataViews[0]); - let viewManager:visualInterfaces.viewManager=this.layoutManager.updateLayout(options.dataViews[0]); + let dataView=options.dataViews[0]; + let field=dataView.categorical.categories[0]; + let values=dataView.categorical.values; + let defaultSelect:powerbi.DataViewValueColumn; + let defaultStart:powerbi.DataViewValueColumn; + let defaultEnd:powerbi.DataViewValueColumn; + values.map((messure)=>{ + var role=messure.source.roles; + if(role['defaultSelect']){ + defaultSelect=messure; + }else if(role['defaultStart']){ + defaultStart=messure; + }else if(role['defaultEnd']){ + defaultEnd=messure; + }; + }); + this.layoutManager.update(dataView); + this.selectorManager.updateView(field,defaultSelect,defaultStart,defaultEnd); this.events.renderingFinished(options); } diff --git a/src/visual/visualInterfaces.ts b/src/visual/visualInterfaces.ts index ce48232..59a50f3 100644 --- a/src/visual/visualInterfaces.ts +++ b/src/visual/visualInterfaces.ts @@ -2,13 +2,37 @@ import powerbi from "powerbi-visuals-api"; import DataView = powerbi.DataView; import {VisualSettings} from "../settings/visualSettings"; -export interface layoutManager{ - layout:HTMLElement; - constructor(layout:HTMLElement):void; - updateLayout(dataView:DataView):viewManager; +import * as d3 from "d3"; +type Selection = d3.Selection; +/* +Main interfaces +*/ + +//ISelectorManager +export interface ILayoutManager{ + layout:Selection; + update(dataView:DataView):void; } -export interface viewManager{ - view:HTMLElement; - updateView(categories:any,defaultSelect:any,defaultStart:any,defaultEnd:any); +export interface ILayoutManagerConstructor{ + new(layout:Selection):ILayoutManager; +}; + +//ISelectorManager +export interface ISelectorManager{ + selectorContainer:Selection; + updateView(categories:powerbi.DataViewCategoryColumn,defaultSelect:powerbi.DataViewValueColumn,defaultStart:powerbi.DataViewValueColumn,defaultEnd:powerbi.DataViewValueColumn); +} +export interface ISelectorManagerConstructor{ + new(selectorContainer:Selection):ISelectorManager; +} + +//IFilterManager +export interface IFilterManager{ + applyFilter():void; + setJsonFilter(field:Text|number,select: Text|number):void; + setJsonFilter(field:number,start:number,end:number):void; + setJsonFitler(filter:Date,select:Date):void; +} +export interface IFilterManagerConstructor{ + new(host:powerbi.extensibility.IVisualHost); } -//interface \ No newline at end of file diff --git a/webpack.statistics.dev.html b/webpack.statistics.dev.html index bd694c5..f5fb753 100644 --- a/webpack.statistics.dev.html +++ b/webpack.statistics.dev.html @@ -3,7 +3,7 @@ - Webpack Bundle Analyzer [24 Apr 2020 at 23:03] + Webpack Bundle Analyzer [25 Apr 2020 at 21:45]