1.1.1 • Published 3 years ago

@xmlking/ngx-knob v1.1.1

Weekly downloads
89
License
-
Repository
-
Last release
3 years ago

ngx-knob

npm

Angular directive for Knob component using d3.js v4 without jQuery dependencies

screenshot

Features

  • very easy to implement
  • without jQuery dependencies
  • powered by d3.js v4
  • configurable minimum, maximum values and step
  • animated
  • great ability to configure
  • configurable scale
  • touch, click and drag events implemented

Dependencies

  • Angular 10+
  • D3.js V4
  • @types/d3-selection@^1.1.0
  • lodash-es@4.17.10

Browser Support

  • Chrome, Firefox, Safari, Opera, IE9+

Get started

Installation

You can also use bower to install the component:

Note: from v1.0.2, we are publishing to GitHub Packages https://github.com/xmlking/ngx-knob/packages/213430

See Configuring npm for use with GitHub Packages

npm install @xmlking/ngx-knob --save

add following resolutions to package.json

  "resolutions": {
    "d3-selection": "1.3.0"
  }

Usage

IMPORTING ANGULAR MODULE:
import { KnobModule } from "@xmlking/ngx-knob";

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [KnobModule]
  bootstrap: [AppComponent]
})
HTML USE
<ngx-knob [value]="value" [options]="knOptions"></ngx-knob>
CONFIGURING OPTIONS IN ANGULAR COMPONENT
import { Component, OnInit } from '@angular/core';
import { KnobOptions } from "@xmlking/ngx-knob";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{
  knOptions = {
    readOnly: true,
    size: 140,
    unit: '%',
    textColor: '#000000',
    fontSize: '32',
    fontWeigth: '700',
    fontFamily: 'Roboto',
    valueformat: 'percent',
    value: 0,
    max: 100,
    trackWidth: 19,
    barWidth: 20,
    trackColor: '#D8D8D8',
    barColor: '#FF6F17',
    subText: {
      enabled: true,
      fontFamily: 'Verdana',
      font: '14',
      fontWeight: 'bold',
      text: 'Overall',
      color: '#000000',
      offset: 7
    },
  }
  value = 45; 
}

Options


You can pass these options to the initialize function to set a custom look and feel for the plugin.
PropertyTypeDefaultDescription
animateobject{ enabled: true, duration: 1000, ease: 'bounce' }Duration in milliseconds, Ease: linear, bounce, sin, cubic, quad, exp, circle
sizeinteger200Size of knob in px. It will always be a square
startAngleinteger0Start angle in degrees
endAngleinteger360End angle in degrees
unitstring''Unit values
displayInputbooleantrueDisplay input value (true or false)
inputFormatterfunctionfunction(value){ return value; }Formats the input value before appending the unit and displaying it to the DOM
readOnlybooleanfalseDisabled change value (true or false)
trackWidthinteger50Width track bar in px
barWidthinteger50Width bar value in px
trackColorstring'rgba(0,0,0,0)'Color track bar
barColorstring'rgba(255,0,0,.5)'Color bar value
prevBarColorstring'rgba(0,0,0,0)'Color bar previous value
textColorstring'#222'Text color
barCapinteger0Defines how the ending of the bar line looks like in radius
trackCapinteger0Defines how the ending of the track line looks like in radius
fontSizestring'auto'Font size in px. auto: automatic change
subTextobject{ enabled: false, text: '', fontFamily: 'Arial', fontWeight: 'normal', color: 'gray', font: 'auto', offset: 0 }Subtext options
bgColorstring''Background color
bgFullstringfalsePaints the background of the whole circle ignoring startAngle and endAngle
scaleobject{ enabled: false, type: 'lines', color: 'gray', width: 4, quantity: 20, height: 10, spaceWidth: 15 }Scale options, type: lines or dots
stepinteger1Step change, min 0.1
displayPreviousbooleanfalseDisplay previous value (true or false)
mininteger0Min value (start value), only integer
maxinteger100Max value (end value), only integer
dynamicOptionsbooleanfalseDynamic change options (true or false)

Developer

Setup

# how to create lib project.
ng new ngx-knob
ng generate library knob --prefix=ngx
ng generate component knob --project=knob --inline-style --inline-template --export --flat --dry-run

Build

# bump version in `projects/knob/package.json`
ng build knob --configuration production

Run

ng serve

Publish

we are publishing to GitHub Packages https://github.com/xmlking/ngx-knob/packages/213430

cp README.md dist/knob
cd dist/knob
npm publish --access public
1.1.1

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago