Skip to content

Instantly share code, notes, and snippets.

@mpalmr
Created August 6, 2016 20:37
Show Gist options
  • Save mpalmr/946d2f5773e4d6346aa7524a1f75c7c7 to your computer and use it in GitHub Desktop.
Save mpalmr/946d2f5773e4d6346aa7524a1f75c7c7 to your computer and use it in GitHub Desktop.
import * as d3 from "d3";
export default class Chart {
private elements: Array<Element>;
constructor(target: string|Element|NodeList) {
this.elements = Chart.parseTarget(target);
}
private static parseTarget(target: string|Element|NodeList): Array<Element> {
if (typeof target === "string") return Array.from(document.querySelectorAll(target));
if (typeof target === "NodeList") return Array.from(target);
if (target instanceof Element) return [target];
throw new TypeError();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment