Git Product home page Git Product logo

graphic-editor's Introduction

ng-graphic-editor

A library tool based on angular11 to implement a drag-and-drop component implementation interface, which can inject components and settings externally, and provide the function of binding data sources Demo overview

install

    npm i ng-graphic-editor

import

    import: [
        ...,
        GraphicEditorModule.forRoot()
    ],
    providers: [
        // inject components Widget[]
        { provide: WIDGET_LIST, useValue: widgets },
        // Inject component configuration WidgetSetting[]
        { provide: WIDGET_SETTING_LIST, useValue: widgetSettings }
        // Inject save to get page service, realize IGraphicEditorService,Does not provide use default storage indexdb
        { provide: EDITOR_SERVICE, useFactory: () => new AppService() },
    ]
  @import '~ng-graphic-editor/src/iconfont/iconfont.scss'; 

html use

    // editor
    <div>
        <ng-graphic-editor></ng-graphic-editor>
    </div>
    // show page directly Page
    <div>
        <ng-graphic-view [page]="page"></ng-graphic-view>
    </div>

how to create widget and use data

    export class ChartComponent
    extends BaseWidgetContent
    implements OnInit, AfterViewInit
    {
        ...
        // Component default display configuration
        widgetData: ChartWidgetData = {
            setting: {
            background: { fill: true, color: '#efefef' },
            radius: 4,
            border: {
                fill: true,
                color: '#efefef',
                style: 'solid',
                width: 1,
            },
            },
        };
        ...

        constructor(
            private widgetSrv: WidgetService
        ) {
            super();
        }

        ngOnInit(): void {}
        ngAfterViewInit(): void {
            this.widgetSrv.onDataChange().subscribe(() => {
                // can use this.data here
                const data = this.data;
                ...
            });
        }
        ...

how to create widget setting

    export class ChartSettingComponent implements OnInit {
        // ref instance of the component,See specific desirable properties WidgetComponent
        constructor(public ref: ComponentRef<WidgetComponent>) {}
        ...
        // Mark page changes, and call it when each attribute is modified or changed, otherwise the page may not get the changes and cannot save the modified attributes
        emitChange(): void {
            this.ref.instance.page._modified = true;
        }
    }

some type

    export interface IGraphicEditorService {
        addPage(): Observable<Page>;
        updatePage(pages: Page[]): Observable<any>;
        deletePage(page: Page): Observable<any>;
        getPageById(id: number): Observable<Page>;
        getAllPages(): Observable<Page[]>;
    }
    export type Page = {
        id: number;
        name?: string;
        style: PageStyle;
        widgets?: { type: string; style: WidgetStyle; widgetData?: WidgetData }[];
        dataSetting?: DataSetting[];
    };

    export type PageStyle = {
        width: number;
        height: number;
        backgroundColor: string;
        adaptive?: boolean;
    };
    export type Widget = {
        /** Component category */
        category: WidgetCategory | string;
        /** show name */
        name: string;
        /** Part Type */
        type: string;
        /** widget initial width */
        width?: number;
        /** Part initial height */
        height?: number;
        /** Toolbar display icon */
        icon?: string;
        /** Component class */
        component: any;
        /** set up */
        settings?: WidgetSetting[];
    };

    // @example    
    // {
    //   category: WidgetCategory.Advanced, // Basic,Advanced or custom string
    //   name: 'chart',
    //   icon: 'icon-chart',
    //   type: 'chart',
    //   width: 100,
    //   height: 100,
    //   component: ChartComponent,
    //   settings: [ // A set of settings, which can be combined with multiple settings
    //      { 
    //          type: 'chart', 
    //          name: 'chart', 
    //          component: ChartSettingComponent 
    //      },
    //     'appearance', // apperance-Appearance settings,text-text, image-picture
    //   ],
    // },
    export type WidgetSetting =
         {
            type: string;
            name?: string;
            component: any;
            }
        | string;

    // @example    
    // {
    //    type: 'image',
    //    name: 'picture',
    //    component: ImgSettingComponent,
    // },
    export type WidgetData<T = any> = {
        id?: number;
        // Subsequent use as component naming, not used yet
        name?: string;
        // General settings
        setting: T;
        // Event settings
        events?: EventListener[];
        // Data source settings
        dataSetting?: DataSetting[];
    };

graphic-editor's People

Contributors

sdrh avatar yuhuali avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.