Skip to content

Commit 822aebf

Browse files
committed
inline styles; tabular nums
1 parent ca57bbd commit 822aebf

File tree

137 files changed

+152
-186
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+152
-186
lines changed

bundle.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
import "./src/style.css";
21
export {version} from "./package.json";
32
export * from "./src/index.js";

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
},
2323
"files": [
2424
"dist/**/*.js",
25-
"src/**/*.js",
26-
"src/**/*.css"
25+
"src/**/*.js"
2726
],
2827
"scripts": {
2928
"test": "mkdir -p test/output && mocha -r module-alias/register 'test/**/*-test.js' test/plot.js && eslint src test",
@@ -38,12 +37,10 @@
3837
"devDependencies": {
3938
"@rollup/plugin-json": "^4.1.0",
4039
"@rollup/plugin-node-resolve": "^13.0.4",
41-
"clean-css": "^5.1.1",
4240
"eslint": "^7.12.1",
4341
"htl": "^0.3.0",
4442
"js-beautify": "^1.13.0",
4543
"jsdom": "^17.0.0",
46-
"jsesc": "^3.0.2",
4744
"mocha": "^9.1.0",
4845
"module-alias": "^2.2.2",
4946
"rollup": "^2.32.1",

rollup.config.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import fs from "fs";
2-
import path from "path";
32
import {terser} from "rollup-plugin-terser";
43
import json from "@rollup/plugin-json";
54
import node from "@rollup/plugin-node-resolve";
6-
import jsesc from "jsesc";
7-
import CleanCSS from "clean-css";
85
import * as meta from "./package.json";
96

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

23-
// A lil’ Rollup plugin to allow importing of style.css.
24-
const cssPath = path.resolve("./src/style.css");
25-
const css = {
26-
load(id) {
27-
if (id !== cssPath) return;
28-
return fs.readFileSync(id, "utf8");
29-
},
30-
transform(input, id) {
31-
if (id !== cssPath) return;
32-
return {
33-
moduleSideEffects: true,
34-
code: `if (typeof document !== 'undefined') {
35-
const style = document.createElement('style');
36-
style.textContent = '${jsesc(new CleanCSS().minify(input).styles)}';
37-
document.head.appendChild(style);
38-
}
39-
`
40-
};
41-
}
42-
};
43-
4420
const config = {
4521
input: "bundle.js",
4622
external: ["d3"],
@@ -49,7 +25,6 @@ const config = {
4925
banner: `// ${meta.name} v${meta.version} Copyright ${copyrights.join(", ")}`
5026
},
5127
plugins: [
52-
css,
5328
json(),
5429
node()
5530
]

src/plot.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,31 @@ export function plot(options = {}) {
6868

6969
const {width, height} = dimensions;
7070

71+
// A unique identifier for this plot, for inline styles.
72+
const uid = `plot-${Math.random().toString(16).slice(2)}`;
73+
7174
const svg = create("svg")
72-
.attr("class", "plot")
75+
.attr("class", uid)
7376
.attr("fill", "currentColor")
77+
.attr("font-family", "system-ui, sans-serif")
78+
.attr("font-size", 10)
79+
.attr("font-variant", "tabular-nums")
7480
.attr("text-anchor", "middle")
7581
.attr("width", width)
7682
.attr("height", height)
7783
.attr("viewBox", `0 0 ${width} ${height}`)
84+
.call(svg => svg.append("style").text(`
85+
.${uid} {
86+
display: block;
87+
background: white;
88+
height: auto;
89+
height: intrinsic;
90+
max-width: 100%;
91+
}
92+
.${uid} text {
93+
white-space: pre;
94+
}
95+
`))
7896
.each(function() {
7997
if (typeof style === "string") this.style = style;
8098
else Object.assign(this.style, style);

src/style.css

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/output/aaplBollinger.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplCandlestick.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplChangeVolume.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplClose.svg

Lines changed: 1 addition & 1 deletion
Loading

test/output/aaplCloseUntyped.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)