Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monorepo #3810

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file removed img/axis-v4.png
Binary file not shown.
Binary file removed img/pack-v3.png
Binary file not shown.
Binary file removed img/pack-v4.png
Binary file not shown.
Binary file removed img/stratify.png
Binary file not shown.
14 changes: 14 additions & 0 deletions packages/d3-array/.eslintrc.json
@@ -0,0 +1,14 @@
{
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"env": {
"es6": true
},
"rules": {
"no-cond-assign": 0,
"no-constant-condition": 0
}
}
18 changes: 18 additions & 0 deletions packages/d3-array/.github/eslint.json
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "eslint-compact",
"pattern": [
{
"regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5,
"code": 6
}
]
}
]
}
30 changes: 30 additions & 0 deletions packages/d3-array/.github/workflows/node.js.yml
@@ -0,0 +1,30 @@
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn --frozen-lockfile
- run: |
echo ::add-matcher::.github/eslint.json
yarn run eslint src test --format=compact
- run: yarn test
5 changes: 5 additions & 0 deletions packages/d3-array/.gitignore
@@ -0,0 +1,5 @@
*.sublime-workspace
.DS_Store
dist/
node_modules
npm-debug.log
File renamed without changes.
12 changes: 12 additions & 0 deletions packages/d3-array/README.md
@@ -0,0 +1,12 @@
# d3-array

<a href="https://d3js.org"><img src="https://github.com/d3/d3/raw/main/docs/public/logo.svg" width="256" height="256"></a>

Array manipulation, ordering, searching, summarizing, etc.

## Resources

- [Documentation](https://d3js.org/d3-array)
- [Examples](https://observablehq.com/collection/@d3/d3-array)
- [Releases](https://github.com/d3/d3-array/releases)
- [Getting help](https://d3js.org/community)
Binary file added packages/d3-array/img/histogram.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions packages/d3-array/package.json
@@ -0,0 +1,61 @@
{
"name": "d3-array",
"version": "3.2.4",
"description": "Array manipulation, ordering, searching, summarizing, etc.",
"homepage": "https://d3js.org/d3-array/",
"repository": {
"type": "git",
"url": "https://github.com/d3/d3-array.git"
},
"keywords": [
"d3",
"d3-module",
"histogram",
"bisect",
"shuffle",
"statistics",
"search",
"sort",
"array"
],
"license": "ISC",
"author": {
"name": "Mike Bostock",
"url": "http://bost.ocks.org/mike"
},
"type": "module",
"files": [
"dist/**/*.js",
"src/**/*.js"
],
"module": "src/index.js",
"main": "src/index.js",
"jsdelivr": "dist/d3-array.min.js",
"unpkg": "dist/d3-array.min.js",
"exports": {
"umd": "./dist/d3-array.min.js",
"default": "./src/index.js"
},
"sideEffects": false,
"dependencies": {
"internmap": "1 - 2"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "15",
"d3-dsv": "3",
"d3-random": "2 - 3",
"eslint": "8",
"jsdom": "21",
"mocha": "10",
"rollup": "3",
"rollup-plugin-terser": "7"
},
"scripts": {
"test": "mocha 'test/**/*-test.js' && eslint src test",
"prepublishOnly": "rm -rf dist && rollup -c",
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -"
},
"engines": {
"node": ">=12"
}
}
53 changes: 53 additions & 0 deletions packages/d3-array/rollup.config.js
@@ -0,0 +1,53 @@
import {nodeResolve} from "@rollup/plugin-node-resolve";
import {readFileSync} from "fs";
import {terser} from "rollup-plugin-terser";
import meta from "./package.json" assert {type: "json"};

// Extract copyrights from the LICENSE.
const copyright = readFileSync("./LICENSE", "utf-8")
.split(/\n/g)
.filter(line => /^copyright\s+/i.test(line))
.map(line => line.replace(/^copyright\s+/i, ""))
.join(", ");

const config = {
input: "src/index.js",
external: Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)),
output: {
file: `dist/${meta.name}.js`,
name: "d3",
format: "umd",
indent: false,
extend: true,
banner: `// ${meta.homepage} v${meta.version} Copyright ${copyright}`,
globals: Object.assign({}, ...Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
},
plugins: [
nodeResolve()
]
};

export default [
config,
{
...config,
output: {
...config.output,
file: `dist/${meta.name}.min.js`
},
plugins: [
...config.plugins,
terser({
output: {
preamble: config.output.banner
},
mangle: {
reserved: [
"InternMap",
"InternSet"
]
}
})
]
}
];
4 changes: 4 additions & 0 deletions packages/d3-array/src/array.js
@@ -0,0 +1,4 @@
var array = Array.prototype;

export var slice = array.slice;
export var map = array.map;
3 changes: 3 additions & 0 deletions packages/d3-array/src/ascending.js
@@ -0,0 +1,3 @@
export default function ascending(a, b) {
return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
125 changes: 125 additions & 0 deletions packages/d3-array/src/bin.js
@@ -0,0 +1,125 @@
import {slice} from "./array.js";
import bisect from "./bisect.js";
import constant from "./constant.js";
import extent from "./extent.js";
import identity from "./identity.js";
import nice from "./nice.js";
import ticks, {tickIncrement} from "./ticks.js";
import sturges from "./threshold/sturges.js";

export default function bin() {
var value = identity,
domain = extent,
threshold = sturges;

function histogram(data) {
if (!Array.isArray(data)) data = Array.from(data);

var i,
n = data.length,
x,
step,
values = new Array(n);

for (i = 0; i < n; ++i) {
values[i] = value(data[i], i, data);
}

var xz = domain(values),
x0 = xz[0],
x1 = xz[1],
tz = threshold(values, x0, x1);

// Convert number of thresholds into uniform thresholds, and nice the
// default domain accordingly.
if (!Array.isArray(tz)) {
const max = x1, tn = +tz;
if (domain === extent) [x0, x1] = nice(x0, x1, tn);
tz = ticks(x0, x1, tn);

// If the domain is aligned with the first tick (which it will by
// default), then we can use quantization rather than bisection to bin
// values, which is substantially faster.
if (tz[0] <= x0) step = tickIncrement(x0, x1, tn);

// If the last threshold is coincident with the domain’s upper bound, the
// last bin will be zero-width. If the default domain is used, and this
// last threshold is coincident with the maximum input value, we can
// extend the niced upper bound by one tick to ensure uniform bin widths;
// otherwise, we simply remove the last threshold. Note that we don’t
// coerce values or the domain to numbers, and thus must be careful to
// compare order (>=) rather than strict equality (===)!
if (tz[tz.length - 1] >= x1) {
if (max >= x1 && domain === extent) {
const step = tickIncrement(x0, x1, tn);
if (isFinite(step)) {
if (step > 0) {
x1 = (Math.floor(x1 / step) + 1) * step;
} else if (step < 0) {
x1 = (Math.ceil(x1 * -step) + 1) / -step;
}
}
} else {
tz.pop();
}
}
}

// Remove any thresholds outside the domain.
// Be careful not to mutate an array owned by the user!
var m = tz.length, a = 0, b = m;
while (tz[a] <= x0) ++a;
while (tz[b - 1] > x1) --b;
if (a || b < m) tz = tz.slice(a, b), m = b - a;

var bins = new Array(m + 1),
bin;

// Initialize bins.
for (i = 0; i <= m; ++i) {
bin = bins[i] = [];
bin.x0 = i > 0 ? tz[i - 1] : x0;
bin.x1 = i < m ? tz[i] : x1;
}

// Assign data to bins by value, ignoring any outside the domain.
if (isFinite(step)) {
if (step > 0) {
for (i = 0; i < n; ++i) {
if ((x = values[i]) != null && x0 <= x && x <= x1) {
bins[Math.min(m, Math.floor((x - x0) / step))].push(data[i]);
}
}
} else if (step < 0) {
for (i = 0; i < n; ++i) {
if ((x = values[i]) != null && x0 <= x && x <= x1) {
const j = Math.floor((x0 - x) * step);
bins[Math.min(m, j + (tz[j] <= x))].push(data[i]); // handle off-by-one due to rounding
}
}
}
} else {
for (i = 0; i < n; ++i) {
if ((x = values[i]) != null && x0 <= x && x <= x1) {
bins[bisect(tz, x, 0, m)].push(data[i]);
}
}
}

return bins;
}

histogram.value = function(_) {
return arguments.length ? (value = typeof _ === "function" ? _ : constant(_), histogram) : value;
};

histogram.domain = function(_) {
return arguments.length ? (domain = typeof _ === "function" ? _ : constant([_[0], _[1]]), histogram) : domain;
};

histogram.thresholds = function(_) {
return arguments.length ? (threshold = typeof _ === "function" ? _ : constant(Array.isArray(_) ? slice.call(_) : _), histogram) : threshold;
};

return histogram;
}
9 changes: 9 additions & 0 deletions packages/d3-array/src/bisect.js
@@ -0,0 +1,9 @@
import ascending from "./ascending.js";
import bisector from "./bisector.js";
import number from "./number.js";

const ascendingBisect = bisector(ascending);
export const bisectRight = ascendingBisect.right;
export const bisectLeft = ascendingBisect.left;
export const bisectCenter = bisector(number).center;
export default bisectRight;