npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-charts-extension

v2.2.0

Published

This library is used to extend the popular [@swimlanes/ngx-charts](https://github.com/swimlane/ngx-charts) with a variety of custom charts using typed classes for easy interaction. Using this library, you should easily be able to build custom charts using

Downloads

16

Readme

NGXChartsExtension

This library is used to extend the popular @swimlanes/ngx-charts with a variety of custom charts using typed classes for easy interaction. Using this library, you should easily be able to build custom charts using all the pre-built components from @swimlanes.

Install

To add ngx-charts-extension to your project, install through npm:

npm i ngx-charts-extension

Usage

Simply extend the BaseChartComponentExtension class in your component. This will create the basics for your custom chart component. Add all the desired charts and features as you desire. We decided to use strongly (when applicable) typed classes to make interacting with the plots even easier.

Here is the example code of a Area-Bubble-Combo Chart (StackBlitz):

import { Component, Input, OnInit, TemplateRef, ElementRef } from '@angular/core'

import { ColorHelper } from '@swimlane/ngx-charts';
import { area, line, curveLinear } from 'd3-shape';

import { BaseChartComponentExtension } from '../../Classes/BaseChartComponentExtension'
import { LineSeries, BubbleSeries, ColorScheme, LegendOptions } from '../../Classes/Classes'
import { concat } from 'rxjs';


@Component({
    selector: 'area-bubble-combo',
    template: `<ngx-charts-chart 
                  [view]="[width + ChartLegendOptions.spacing, height]" 
                  [showLegend]="ShowLegend" 
                  [legendOptions]="ChartLegendOptions"
                  (legendLabelClick)="TestFunction($event)">
    <svg:g [attr.transform]="transform" class="area-chart chart">
        <svg:g ngx-charts-x-axis
               *ngIf="XAxis.DisplayAxis"
               [xScale]="XAxis.Scale"
               [dims]="Dimensions"
               [showGridLines]="true"
               [showLabel]="XAxis.ShowLabel"
               [labelText]="XAxis.LabelText"
               [tickFormatting]="XAxis.Format"
               (dimensionsChanged)="TestFunction($event)">
        </svg:g>

        <svg:g ngx-charts-y-axis
               *ngIf="YAxis1.DisplayAxis"
               [yScale]="YAxis1.Scale"
               [dims]="Dimensions"
               [showGridLines]="true"
               [showLabel]="YAxis1.ShowLabel"
               [labelText]="YAxis1.LabelText"
               [yOrient]="YAxis1.Orientation"
               [tickFormatting]="YAxis1.Format"
               (dimensionsChanged)="TestFunction($event)">
        </svg:g>
        <svg:g ngx-charts-y-axis
               *ngIf="YAxis2.DisplayAxis"
               [yScale]="YAxis2.Scale"
               [dims]="Dimensions"
               [showGridLines]="true"
               [showLabel]="YAxis2.ShowLabel"
               [labelText]="YAxis2.LabelText"
               [yOrient]="YAxis2.Orientation"
               [tickFormatting]="YAxis2.Format"
               (dimensionsChanged)="TestFunction($event)">
        </svg:g>
        <svg:g class="line-chart chart">
            <svg:g [attr.clip-path]="null">
                <svg:g *ngFor="let series of AreaChartSeries">
                    <svg:g ngx-charts-area-series
                           [xScale]="XAxis.Scale"
                           [yScale]="YAxis2.Scale"
                           [colors]="AreaChartColors"
                           [data]="series"
                           [activeEntries]="activeEntries"
                           [scaleType]="XAxisScaleType"
                           [gradient]="false"
                           [curve]="CurveType"
                           [animations]="animations" 
                           (select)="TestFunction($event)"/>
                </svg:g>
            </svg:g>


            <svg:g>
                <svg:g ngx-charts-tooltip-area
                       [dims]="Dimensions"
                       [xSet]="XSet"
                       [xScale]="XAxis.Scale"
                       [yScale]="YAxis1.Scale"
                       [results]="AreaChartSeries"
                       [colors]="AreaChartColors"
                       [tooltipDisabled]="false"
                       [tooltipTemplate]="AreaChartTooltip" />
            </svg:g>

        </svg:g>
        <svg:g [attr.clip-path]="null">
            <svg:g *ngFor="let series of BubbleChartSeries">
                <svg:g ngx-charts-bubble-series
                       [xScale]="XAxis.Scale"
                       [yScale]="YAxis1.Scale"
                       [rScale]="RScale"
                       [xScaleType]="'time'"
                       [yScaleType]="'linear'"
                       [xAxisLabel]="null"
                       [yAxisLabel]="null"
                       [colors]="BubbleChartColors"
                       [data]="series"
                       [activeEntries]="activeEntries"
                       [tooltipDisabled]="false"
                       [tooltipTemplate]="BubbleChartTooltip"
                       (select)="TestFunction($event)"
                        />

            </svg:g>
        </svg:g>


    </svg:g>
</ngx-charts-chart>
`
})
export class AreaBubbleCombo extends BaseChartComponentExtension implements OnInit
{
    // #region Data
    @Input() AreaChartSeries: LineSeries[];
    @Input() BubbleChartSeries: BubbleSeries[];
    // #endregion

    // #region Color Properties
    // #region Input Properties
    @Input() AreaChartScheme: ColorScheme;
    @Input() BubbleChartScheme: ColorScheme;
    // #endregion
    AreaChartColors: ColorHelper;
    BubbleChartColors: ColorHelper;
    // #endregion

    // #region Area Chart Properties
    // #region Input Properties
    @Input() CurveType: any = curveLinear;
    // #endregion

    // #endregion

    // #region Bubble Chart Properties
    // #region Input Properties
    @Input() BubbleRadiusMin: number = 1;
    @Input() BubbleRadiusMax: number = 1;
    // #endregion
    RDomain: any;
    RScale: any;
    // #endregion

    // #region Tooltip Properties
    @Input() BubbleChartTooltip: TemplateRef<ElementRef>;
    @Input() AreaChartTooltip: TemplateRef<ElementRef>;
    // #endregion

    @Input() activeEntries: any[] = [];	//Not sure what this does.

    transform: any;

    SeriesDomain: any;
    CombinedSeries: any;

    ngOnInit()
    {
        this.view = [this.ChartWidth, this.ChartHeight];
        this.update();
    }

    update(): void
    {
        super.update();
        
        let XDomain = this.GetXDomain([...this.AreaChartSeries, ...this.BubbleChartSeries]);
        this.XAxis.Scale = this.GetXScale(XDomain, this.Dimensions.width);
        let YBubbleDomain = this.GetYDomain(this.BubbleChartSeries, this.YAxis1);
        let YLineDomain = this.GetYDomain(this.AreaChartSeries, this.YAxis2);
        this.RDomain = this.GetRDomain(this.BubbleChartSeries);
        this.YAxis1.Scale = this.GetYScale(YBubbleDomain, this.Dimensions.height);
        this.YAxis2.Scale = this.GetYScale(YLineDomain, this.Dimensions.height);
        this.RScale = this.GetRScale(this.RDomain, [this.BubbleRadiusMin, this.BubbleRadiusMax]);
        this.AreaChartColors = new ColorHelper(this.AreaChartScheme, this.SchemeType, YLineDomain);
        this.BubbleChartColors = new ColorHelper(this.BubbleChartScheme, this.SchemeType, YBubbleDomain);
        this.UpdateLegendOptions([...this.AreaChartSeries, ...this.BubbleChartSeries], [this.AreaChartColors, this.BubbleChartColors]);
        this.transform = `translate(${this.Dimensions.xOffset}, ${this.Margins[0]})`;	//xOffset is the third value of margins.
    }
}

References

ngx-charts-extension GitHub @swimlanes/ngx-charts d3