Skip to content

Doesn't let you pass in the canvasModule option and also a suggestion for the implementation process #7

@Amndeep7

Description

@Amndeep7

d3-node lets you pass in the canvasModule as part of the options in order to use node-canvas as the png creation tool. d3node-barchart doesn't let you do so, so you have to manually add it in afterwards:

...
const d3nBar = require(blah);
const canvasModule = require(blah);
const bar = d3nBar(blah);
bar.options.canvasModule = canvasModule;
bar.createCanvas(blah);
...

Furthermore, would probably be easier on the user side if, when you passed in the module to the D3Node object, that you could also pass in the size of the canvas such that the user doesn't need to call the boilerplate createCanvas method since presumably they want a canvas to be created - which presumably is your assumption as well since you throw an error when they call that function without having passed in the canvasModule parameter. This part of the issue might be better served to be in the d3-node repo, but I'm sticking it here cause of the following example of how I roughly envision the code to look if my change is implemented.

User side example:

...
const d3nBar = require(blah);
const canvasModule = require(blah);
const bar = d3nBar(blah, {canvasModule, "canvasWidth": x, "canvasHeight": y}); // dunno the ramifications if you have the canvas size be different from the svg size
...

Library side example:

...
function bar({
  blah,
  canvasOptions
}) {
  ...
  const d3n = new D3Node({
    blah,
    "canvasModule": canvasOptions ? canvasOptions.canvasModule : null,
  });
  if (canvasOptions) {
    d3n.createCanvas(canvasOptions.canvasWidth, canvasOptions.canvasHeight);
  }
  ...
}
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions