Which option is better: installing plotly.js or plotly.js-dist using npm?

When it comes to plotly.js and plotly.js-dist, what exactly sets these two packages apart from each other?

Notably, the installation instructions for plotly.js on npmjs.org specify running 'npm install plotly.js-dist' - why is this necessary?

While plotly.js appears to be a comprehensive project with multiple files, plotly.js-dist is a bundled version consisting of just one file. The reasoning behind this distribution method remains unclear.

Furthermore, it's worth noting that plotly.js-dist is not minified, while a minified file exists within plotly.js, potentially offering an easier way to import the library into projects.

Answer №1

After a thorough check and comparison, it's confirmed that these files are identical.

If you are working with npm + typescript (+Angular), my recommendation is to utilize the option of npm install plotly.js-dist.
If you're using npm (or not) + javascript, the suggestion is to go with option 3 and use plotly.min.js.

Whether the file is minified or not doesn't matter much as every module gets minified after bundling.
Therefore, it ultimately depends on your discretion to choose the file you need to inspect through the developer tool while debugging.

For quick start options, refer to this link.

  1. To install via npm: npm install plotly.js-dist.
  • A readily usable plotly.js distributed bundle.
  • Incorporates trace modules; more details can be found here
  1. Alternatively, utilize the plotly.js CDN hosted by Fastly.
  2. Download the latest release: plotly.js or plotly.min.js. Further information available here.

The choice between them might vary slightly in how you bundle/deploy your project,
and also consider using definition files such as @types/plotly.js
For additional insights, check out the "Bundle information" section in this readme.

Furthermore, if you're working with Angular, here's an additional option: angular-plotly.js.


This serves as my response to your second query regarding "plotly.js" and its complexities in setup for bundling.
My approach and goal have been:

  1. Implementing within angular2-seed alongside Angular 4.
  2. Fully defining each type/interface.

Step 1. Installation of packages.

Modify the command as per @Jesse's suggestion

npm install plotly.js-dist --save
npm install @types/plotly.js --save-dev
npm install @types/d3 --save-dev

Note: @types/d3 is a dependency of @types/plotly.js. If it's unnecessary, remove it from index.d.ts.

Step 2. Renewal of folder to accommodate the definition file.

Rename the folder "plotly.js" to "plotly.js-dist" within "node_modules/@types".

Update - 9/12/2023

This reflects my current environment;

  • Windows 11(x64)
  • Node v18.17.1
  • Angular 13.2.0

My suggested course of action is as follows,

npm i --save plotly.js-dist-min
npm i --save-dev @types/plotly.js-dist-min

This deviates slightly from the official guide.

import { Component, ElementRef, ViewChild, OnInit, AfterViewInit } from '@angular/core';
import * as Plotly from 'plotly.js-dist-min';

@Component({ ... })
export class AppComponent implements OnInit, AfterViewInit {  
  myData!: Partial<Plotly.PlotData>[];
  @ViewChild('chart') div?: ElementRef;

  ngOnInit(): void {
    this.myData = [
      {
        x: ['giraffes', 'orangutans', 'monkeys'],
        y: [20, 14, 23],
        type: 'bar',
      },
    ];
  }

  ngAfterViewInit(): void {
    const element = this.div?.nativeElement;
    Plotly.newPlot(element, this.myData);
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to make the first Image Element within the div automatically clickable?

Is there a way to set the first image in a div as the default clicked element? I have a div with multiple images and I want the first one to be clicked by default. This is part of a React functional component that serves as a view. <div className=&quo ...

Switch the functionality of a Google Chrome extension back and forth numerous times

My Google Chrome extension works by attaching event listeners to all elements on a page and inserting CSS (lol.js and style.css) when clicked. However, I am facing an issue where I cannot remove the JS and CSS upon clicking the icon again. Right now, I am ...

What is the best way to execute tests in different environments with Protractor?

Is it possible to execute specifications in various environments? Maybe by adjusting the protractor-config file? Could we do something along the lines of specs: ['../tests/*.js', server1], ['../more_tests/*.js', server2] within the ...

In JavaScript, the mousedown event consistently receives the "e" parameter as the event object

I am facing an issue while trying to handle a middle mouse button click event using JQuery on a DataTable from the website https://datatables.net/. Below is the code I have implemented. var tbl = document.getElementById("entries"); $(tbl).on('mousedo ...

Error: The function "parse" is not defined

After installing the Font Awesome dependencies for my app and attempting to run npm start to test it, I encountered a troublesome error that has proven to be quite challenging to solve. $ npm start > <a href="/cdn-cgi/l/email-protection" class="__cf ...

Leverage closures within Underscore.js templates for enhanced functionality

Is there any benefit to utilizing a closure in an underscore template for purposes such as keeping track of counters? Here's a simple example: <% (function( models ){ var length = models.length-1, section = ""; _.each( models, functi ...

Exploring how process.argv in NodeJS can be utilized within JavaScript code compiled by

I'm having trouble compiling a basic TypeScript file using webpack (with 'awesome-typescript-loader') that needs to access command line arguments. It seems like the compiled JavaScript is causing a problem by overriding the Node 'proce ...

following the history.back() function call, the subsequent codes are executed

<?php $ok_register = 0; if($ok_register != 1) { ?> <javascript type="text/javascript"> alert("1"); history.back(); </javascript> <?php } ?> <javascript type="text/javas ...

Could anyone clarify the concept of how a function is able to be equivalent to zero?

function checkForSpecialCharacters(text) { var specialChars = [";", "!", ".", "?", ",", "-"]; for(var i = 0; i < specialChars.length; i++) { if(text.indexOf(specialChars[i]) !== -1) { return true; } } ...

Insert a page break after content for desktop browsers

Is it possible to control the display of sections on different screen sizes? I have a page that looks good on 15" laptops, but larger resolutions cause the next section to appear on the first screen. Is there a way to show the next section only on th ...

Using API calls to update component state in React-Redux

I am currently working on setting up a React application where clicking on a map marker in one component triggers the re-rendering of another component on the page. This new component should display data retrieved from a database and update the URL accordi ...

Uncertainty about the integration of a JavaScript file into a PHP file

Having two PHP files where one is executed through a URL and makes AJAX calls to the second PHP file can present challenges. Sometimes, the AJAX results return HTML content with JavaScript events that do not work as expected. To solve this issue, I have in ...

The Access-Control-Allow-Origin error is preventing the Angularjs post request from going through

I am encountering an issue with my index.html file that is sending a post request to localhost:3000/SetUser. The error I keep receiving states XMLHttpRequest cannot load https://localhost:3000/SetUser. No 'Access-Control-Allow-Origin' header is p ...

Switch out the content within a div upon selection

I'm currently working on a palette board project and facing some challenges when switching to a different theme. The initial page is set to have a Warm color palette, but I intend to alter this once the user clicks on the All theme option. Users wil ...

gRaphael - the struggle of animating a line chart

Encountering an issue with the gRaphael javascript line chart library. Creating a line chart from a CSV file with five columns (# of minutes, time, waiting time, in treatment, closed, in location). Previously drew full chart without animation successfull ...

Unable to activate Knockout data-bind using jQuery

I'm developing a plugin using jQuery and knockout.js. Currently, I have a scenario where I need to manipulate radio buttons with knockout data-bindings. However, I've encountered an issue when trying to uncheck a radio button by clicking another ...

Customizing the appearance of charts in AngularJS using the Chart.js

I just started experimenting with AngularJS and recently created a horizontal bar chart using Chart.js and HTML. My next step is to make the chart dynamically appear on the page with the help of AngularJS. Can someone please provide some guidance on how I ...

Do back-end routes get activated when the route path in the URL matches, or when a fetch request is initiated from the front-end?

Exploring the contrast between utilizing a fetch API versus directly visiting the URL corresponding to the route path. Consider a backend route structured as follows: let ALL_RESTAURANTS = [ { id: "0b65fe74-03a9-4b37-ab09-1c8d23189273", name: ...

Steps for implementing AJAX to display a success function and update database results in real-time

I'm struggling with allowing my AJAX call to send data to my PHP file and update the page without a reload. I need the success message to display after approving a user, but their name doesn't move on the page until I refresh. The goal is to app ...

Issues encountered while trying to integrate chessboard.js into a Vue application

I am facing an issue while trying to incorporate chessboard.js into my jetstream-vue application. Following the creation of the project, I executed the command npm install @chrisoakman/chessboardjs which successfully downloaded the package into my node_mod ...