Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bundle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import "./src/style.css";
export {version} from "./package.json";
export * from "./src/index.js";
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
},
"files": [
"dist/**/*.js",
"src/**/*.js",
"src/**/*.css"
"src/**/*.js"
],
"scripts": {
"test": "mkdir -p test/output && mocha -r module-alias/register 'test/**/*-test.js' test/plot.js && eslint src test",
Expand All @@ -38,12 +37,10 @@
"devDependencies": {
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"clean-css": "^5.1.1",
"eslint": "^7.12.1",
"htl": "^0.3.0",
"js-beautify": "^1.13.0",
"jsdom": "^17.0.0",
"jsesc": "^3.0.2",
"mocha": "^9.1.0",
"module-alias": "^2.2.2",
"rollup": "^2.32.1",
Expand Down
25 changes: 0 additions & 25 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import fs from "fs";
import path from "path";
import {terser} from "rollup-plugin-terser";
import json from "@rollup/plugin-json";
import node from "@rollup/plugin-node-resolve";
import jsesc from "jsesc";
import CleanCSS from "clean-css";
import * as meta from "./package.json";

const filename = meta.name.split("/").pop();
Expand All @@ -20,27 +17,6 @@ const copyrights = fs.readFileSync("./LICENSE", "utf-8")
.filter(line => /^copyright\s+/i.test(line))
.map(line => line.replace(/^copyright\s+/i, ""));

// A lil’ Rollup plugin to allow importing of style.css.
const cssPath = path.resolve("./src/style.css");
const css = {
load(id) {
if (id !== cssPath) return;
return fs.readFileSync(id, "utf8");
},
transform(input, id) {
if (id !== cssPath) return;
return {
moduleSideEffects: true,
code: `if (typeof document !== 'undefined') {
const style = document.createElement('style');
style.textContent = '${jsesc(new CleanCSS().minify(input).styles)}';
document.head.appendChild(style);
}
`
};
}
};

const config = {
input: "bundle.js",
external: ["d3"],
Expand All @@ -49,7 +25,6 @@ const config = {
banner: `// ${meta.name} v${meta.version} Copyright ${copyrights.join(", ")}`
},
plugins: [
css,
json(),
node()
]
Expand Down
20 changes: 19 additions & 1 deletion src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,31 @@ export function plot(options = {}) {

const {width, height} = dimensions;

// A unique identifier for this plot, for inline styles.
const uid = `plot-${Math.random().toString(16).slice(2)}`;

const svg = create("svg")
.attr("class", "plot")
.attr("class", uid)
.attr("fill", "currentColor")
.attr("font-family", "system-ui, sans-serif")
.attr("font-size", 10)
.attr("font-variant", "tabular-nums")
.attr("text-anchor", "middle")
.attr("width", width)
.attr("height", height)
.attr("viewBox", `0 0 ${width} ${height}`)
.call(svg => svg.append("style").text(`
.${uid} {
display: block;
background: white;
height: auto;
height: intrinsic;
max-width: 100%;
}
.${uid} text {
white-space: pre;
}
`))
.each(function() {
if (typeof style === "string") this.style = style;
else Object.assign(this.style, style);
Expand Down
12 changes: 0 additions & 12 deletions src/style.css

This file was deleted.

2 changes: 1 addition & 1 deletion test/output/aaplBollinger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplCandlestick.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplChangeVolume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplClose.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplCloseUntyped.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplMonthly.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplVolume.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/aaplVolumeRect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/anscombeQuartet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesHeightWeight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesHeightWeightBin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesHeightWeightBinStroke.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesHeightWeightSex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesHeightWeightSport.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesNationality.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesSexWeight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesSportSex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesSportWeight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesWeight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/athletesWeightCumulative.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/availability.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/ballotStatusRace.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/beckerBarley.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/output/caltrain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading