New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

d3-pca

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

d3-pca

Principal component analysis plugin for D3.js

1.0.0
latest
Source
npm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

d3-pca

Principal component analysis plugin for D3.js (v4)

Demo

https://likr.github.io/d3-pca

Example

import * as d3 from 'd3'
import {Renderer, PCA} from '../src'

d3.csv('data.csv')
  .row((d) => {
    const obj = {
      name: d.name,
      values: {}
    }
    for (const key in d) {
      if (key !== 'name') {
        obj.values[key] = +d[key]
      }
    }
    return obj
  })
  .get((errors, data) => {
    const p = 0.98
    const pca = new PCA(data)
    const lambda = pca.lambda()
    const sumLambda = lambda.reduce((a, x) => a + x)
    const renderer = new Renderer().size([400, 400])

    let i
    let acc = 0
    for (i = 0; i < lambda.length; ++i) {
      acc += lambda[i]
      if (acc > sumLambda * p) {
        break
      }
    }
    const n = i + 1
    for (let i = 0; i < n; ++i) {
      for (let j = i + 1; j < n; ++j) {
        d3.select('body')
          .append('svg')
          .datum(pca.get(i, j))
          .call(renderer.render())
      }
    }
  })

Running example

Run following commands and open http://localhost:8080/.

$ git clone https://github.com/likr/d3-pca
$ cd d3-pca
$ npm i
$ npm start

FAQs

Package last updated on 20 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts