You've already forked wakapi-readme-stats
Bar graph added.
This commit is contained in:
21
node_modules/vega-functions/src/functions/data.js
generated
vendored
Normal file
21
node_modules/vega-functions/src/functions/data.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import {truthy} from 'vega-util';
|
||||
|
||||
export function data(name) {
|
||||
const data = this.context.data[name];
|
||||
return data ? data.values.value : [];
|
||||
}
|
||||
|
||||
export function indata(name, field, value) {
|
||||
const index = this.context.data[name]['index:' + field],
|
||||
entry = index ? index.value.get(value) : undefined;
|
||||
return entry ? entry.count : entry;
|
||||
}
|
||||
|
||||
export function setdata(name, tuples) {
|
||||
const df = this.context.dataflow,
|
||||
data = this.context.data[name],
|
||||
input = data.input;
|
||||
|
||||
df.pulse(input, df.changeset().remove(truthy).insert(tuples));
|
||||
return 1;
|
||||
}
|
||||
8
node_modules/vega-functions/src/functions/encode.js
generated
vendored
Normal file
8
node_modules/vega-functions/src/functions/encode.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export default function(item, name, retval) {
|
||||
if (item) {
|
||||
const df = this.context.dataflow,
|
||||
target = item.mark.source;
|
||||
df.pulse(target, df.changeset().encode(item, name));
|
||||
}
|
||||
return retval !== undefined ? retval : item;
|
||||
}
|
||||
36
node_modules/vega-functions/src/functions/format.js
generated
vendored
Normal file
36
node_modules/vega-functions/src/functions/format.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
const wrap = method => function(value, spec) {
|
||||
const locale = this.context.dataflow.locale();
|
||||
return locale[method](spec)(value);
|
||||
};
|
||||
|
||||
export const format = wrap('format');
|
||||
export const timeFormat = wrap('timeFormat');
|
||||
export const utcFormat = wrap('utcFormat');
|
||||
export const timeParse = wrap('timeParse');
|
||||
export const utcParse = wrap('utcParse');
|
||||
|
||||
var dateObj = new Date(2000, 0, 1);
|
||||
|
||||
function time(month, day, specifier) {
|
||||
if (!Number.isInteger(month) || !Number.isInteger(day)) return '';
|
||||
dateObj.setYear(2000);
|
||||
dateObj.setMonth(month);
|
||||
dateObj.setDate(day);
|
||||
return timeFormat.call(this, dateObj, specifier);
|
||||
}
|
||||
|
||||
export function monthFormat(month) {
|
||||
return time.call(this, month, 1, '%B');
|
||||
}
|
||||
|
||||
export function monthAbbrevFormat(month) {
|
||||
return time.call(this, month, 1, '%b');
|
||||
}
|
||||
|
||||
export function dayFormat(day) {
|
||||
return time.call(this, 0, 2 + day, '%A');
|
||||
}
|
||||
|
||||
export function dayAbbrevFormat(day) {
|
||||
return time.call(this, 0, 2 + day, '%a');
|
||||
}
|
||||
23
node_modules/vega-functions/src/functions/geo.js
generated
vendored
Normal file
23
node_modules/vega-functions/src/functions/geo.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import {getScale} from '../scales';
|
||||
import {
|
||||
geoArea as area,
|
||||
geoBounds as bounds,
|
||||
geoCentroid as centroid
|
||||
} from 'd3-geo';
|
||||
|
||||
function geoMethod(methodName, globalMethod) {
|
||||
return function(projection, geojson, group) {
|
||||
if (projection) {
|
||||
// projection defined, use it
|
||||
const p = getScale(projection, (group || this).context);
|
||||
return p && p.path[methodName](geojson);
|
||||
} else {
|
||||
// projection undefined, use global method
|
||||
return globalMethod(geojson);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const geoArea = geoMethod('area', area);
|
||||
export const geoBounds = geoMethod('bounds', bounds);
|
||||
export const geoCentroid = geoMethod('centroid', centroid);
|
||||
10
node_modules/vega-functions/src/functions/inscope.js
generated
vendored
Normal file
10
node_modules/vega-functions/src/functions/inscope.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export default function(item) {
|
||||
let group = this.context.group,
|
||||
value = false;
|
||||
|
||||
if (group) while (item) {
|
||||
if (item === group) { value = true; break; }
|
||||
item = item.mark.group;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
25
node_modules/vega-functions/src/functions/intersect.js
generated
vendored
Normal file
25
node_modules/vega-functions/src/functions/intersect.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import {Bounds, intersect} from 'vega-scenegraph';
|
||||
import {array} from 'vega-util';
|
||||
|
||||
export default function(b, opt, group) {
|
||||
if (!b) return [];
|
||||
|
||||
const [u, v] = b,
|
||||
box = new Bounds().set(u[0], u[1], v[0], v[1]),
|
||||
scene = group || this.context.dataflow.scenegraph().root;
|
||||
|
||||
return intersect(scene, box, filter(opt));
|
||||
}
|
||||
|
||||
function filter(opt) {
|
||||
let p = null;
|
||||
|
||||
if (opt) {
|
||||
const types = array(opt.marktype),
|
||||
names = array(opt.markname);
|
||||
p = _ => (!types.length || types.some(t => _.marktype === t))
|
||||
&& (!names.length || names.some(s => _.name === s));
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
20
node_modules/vega-functions/src/functions/log.js
generated
vendored
Normal file
20
node_modules/vega-functions/src/functions/log.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
function log(df, method, args) {
|
||||
try {
|
||||
df[method].apply(df, ['EXPRESSION'].concat([].slice.call(args)));
|
||||
} catch (err) {
|
||||
df.warn(err);
|
||||
}
|
||||
return args[args.length-1];
|
||||
}
|
||||
|
||||
export function warn() {
|
||||
return log(this.context.dataflow, 'warn', arguments);
|
||||
}
|
||||
|
||||
export function info() {
|
||||
return log(this.context.dataflow, 'info', arguments);
|
||||
}
|
||||
|
||||
export function debug() {
|
||||
return log(this.context.dataflow, 'debug', arguments);
|
||||
}
|
||||
27
node_modules/vega-functions/src/functions/luminance.js
generated
vendored
Normal file
27
node_modules/vega-functions/src/functions/luminance.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import {rgb} from 'd3-color';
|
||||
|
||||
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
|
||||
function channel_luminance_value(channelValue) {
|
||||
const val = channelValue / 255;
|
||||
if (val <= 0.03928) {
|
||||
return val / 12.92;
|
||||
}
|
||||
return Math.pow((val + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
export function luminance(color) {
|
||||
const c = rgb(color),
|
||||
r = channel_luminance_value(c.r),
|
||||
g = channel_luminance_value(c.g),
|
||||
b = channel_luminance_value(c.b);
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
|
||||
export function contrast(color1, color2) {
|
||||
const lum1 = luminance(color1),
|
||||
lum2 = luminance(color2),
|
||||
lumL = Math.max(lum1, lum2),
|
||||
lumD = Math.min(lum1, lum2);
|
||||
return (lumL + 0.05) / (lumD + 0.05);
|
||||
}
|
||||
7
node_modules/vega-functions/src/functions/merge.js
generated
vendored
Normal file
7
node_modules/vega-functions/src/functions/merge.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import {extend} from 'vega-util';
|
||||
|
||||
export default function() {
|
||||
var args = [].slice.call(arguments);
|
||||
args.unshift({});
|
||||
return extend.apply(null, args);
|
||||
}
|
||||
80
node_modules/vega-functions/src/functions/modify.js
generated
vendored
Normal file
80
node_modules/vega-functions/src/functions/modify.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import {isTuple} from 'vega-dataflow';
|
||||
import {isArray, isObject, truthy} from 'vega-util';
|
||||
|
||||
function equal(a, b) {
|
||||
return a === b || a !== a && b !== b ? true
|
||||
: isArray(a) ? (
|
||||
isArray(b) && a.length === b.length ? equalArray(a, b) : false
|
||||
)
|
||||
: isObject(a) && isObject(b) ? equalObject(a, b)
|
||||
: false;
|
||||
}
|
||||
|
||||
function equalArray(a, b) {
|
||||
for (let i=0, n=a.length; i<n; ++i) {
|
||||
if (!equal(a[i], b[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function equalObject(a, b) {
|
||||
for (let key in a) {
|
||||
if (!equal(a[key], b[key])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function removePredicate(props) {
|
||||
return _ => equalObject(props, _);
|
||||
}
|
||||
|
||||
export default function(name, insert, remove, toggle, modify, values) {
|
||||
let df = this.context.dataflow,
|
||||
data = this.context.data[name],
|
||||
input = data.input,
|
||||
changes = data.changes,
|
||||
stamp = df.stamp(),
|
||||
predicate, key;
|
||||
|
||||
if (df._trigger === false || !(input.value.length || insert || toggle)) {
|
||||
// nothing to do!
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!changes || changes.stamp < stamp) {
|
||||
data.changes = (changes = df.changeset());
|
||||
changes.stamp = stamp;
|
||||
df.runAfter(function() {
|
||||
data.modified = true;
|
||||
df.pulse(input, changes).run();
|
||||
}, true, 1);
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
predicate = remove === true ? truthy
|
||||
: (isArray(remove) || isTuple(remove)) ? remove
|
||||
: removePredicate(remove);
|
||||
changes.remove(predicate);
|
||||
}
|
||||
|
||||
if (insert) {
|
||||
changes.insert(insert);
|
||||
}
|
||||
|
||||
if (toggle) {
|
||||
predicate = removePredicate(toggle);
|
||||
if (input.value.some(predicate)) {
|
||||
changes.remove(predicate);
|
||||
} else {
|
||||
changes.insert(toggle);
|
||||
}
|
||||
}
|
||||
|
||||
if (modify) {
|
||||
for (key in values) {
|
||||
changes.modify(modify, key, values[key]);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
14
node_modules/vega-functions/src/functions/pinch.js
generated
vendored
Normal file
14
node_modules/vega-functions/src/functions/pinch.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
export function pinchDistance(event) {
|
||||
const t = event.touches,
|
||||
dx = t[0].clientX - t[1].clientX,
|
||||
dy = t[0].clientY - t[1].clientY;
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
export function pinchAngle(event) {
|
||||
const t = event.touches;
|
||||
return Math.atan2(
|
||||
t[0].clientY - t[1].clientY,
|
||||
t[0].clientX - t[1].clientX
|
||||
);
|
||||
}
|
||||
35
node_modules/vega-functions/src/functions/scale-gradient.js
generated
vendored
Normal file
35
node_modules/vega-functions/src/functions/scale-gradient.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import {getScale} from '../scales';
|
||||
import {scale as get, scaleFraction} from 'vega-scale';
|
||||
import {Gradient} from 'vega-scenegraph';
|
||||
import {identity, peek} from 'vega-util';
|
||||
|
||||
export default function(scale, p0, p1, count, group) {
|
||||
scale = getScale(scale, (group || this).context);
|
||||
|
||||
const gradient = Gradient(p0, p1);
|
||||
|
||||
let stops = scale.domain(),
|
||||
min = stops[0],
|
||||
max = peek(stops),
|
||||
fraction = identity;
|
||||
|
||||
if (!(max - min)) {
|
||||
// expand scale if domain has zero span, fix #1479
|
||||
scale = (scale.interpolator
|
||||
? get('sequential')().interpolator(scale.interpolator())
|
||||
: get('linear')().interpolate(scale.interpolate()).range(scale.range())
|
||||
).domain([min=0, max=1]);
|
||||
} else {
|
||||
fraction = scaleFraction(scale, min, max);
|
||||
}
|
||||
|
||||
if (scale.ticks) {
|
||||
stops = scale.ticks(+count || 15);
|
||||
if (min !== stops[0]) stops.unshift(min);
|
||||
if (max !== peek(stops)) stops.push(max);
|
||||
}
|
||||
|
||||
stops.forEach(_ => gradient.stop(fraction(_), scale(_)));
|
||||
|
||||
return gradient;
|
||||
}
|
||||
39
node_modules/vega-functions/src/functions/scale.js
generated
vendored
Normal file
39
node_modules/vega-functions/src/functions/scale.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import {getScale} from '../scales';
|
||||
import {bandSpace} from 'vega-scale';
|
||||
import {isArray} from 'vega-util';
|
||||
|
||||
export function bandspace(count, paddingInner, paddingOuter) {
|
||||
return bandSpace(count || 0, paddingInner || 0, paddingOuter || 0);
|
||||
}
|
||||
|
||||
export function bandwidth(name, group) {
|
||||
const s = getScale(name, (group || this).context);
|
||||
return s && s.bandwidth ? s.bandwidth() : 0;
|
||||
}
|
||||
|
||||
export function copy(name, group) {
|
||||
const s = getScale(name, (group || this).context);
|
||||
return s ? s.copy() : undefined;
|
||||
}
|
||||
|
||||
export function domain(name, group) {
|
||||
const s = getScale(name, (group || this).context);
|
||||
return s ? s.domain() : [];
|
||||
}
|
||||
|
||||
export function invert(name, range, group) {
|
||||
const s = getScale(name, (group || this).context);
|
||||
return !s ? undefined
|
||||
: isArray(range) ? (s.invertRange || s.invert)(range)
|
||||
: (s.invert || s.invertExtent)(range);
|
||||
}
|
||||
|
||||
export function range(name, group) {
|
||||
const s = getScale(name, (group || this).context);
|
||||
return s && s.range ? s.range() : [];
|
||||
}
|
||||
|
||||
export function scale(name, value, group) {
|
||||
const s = getScale(name, (group || this).context);
|
||||
return s ? s(value) : undefined;
|
||||
}
|
||||
18
node_modules/vega-functions/src/functions/shape.js
generated
vendored
Normal file
18
node_modules/vega-functions/src/functions/shape.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import {getScale} from '../scales';
|
||||
import {pathParse, pathRender} from 'vega-scenegraph';
|
||||
|
||||
export function geoShape(projection, geojson, group) {
|
||||
const p = getScale(projection, (group || this).context);
|
||||
return function(context) {
|
||||
return p ? p.path.context(context)(geojson) : '';
|
||||
};
|
||||
}
|
||||
|
||||
export function pathShape(path) {
|
||||
let p = null;
|
||||
return function(context) {
|
||||
return context
|
||||
? pathRender(context, (p = p || pathParse(path)))
|
||||
: path;
|
||||
};
|
||||
}
|
||||
20
node_modules/vega-functions/src/functions/tree.js
generated
vendored
Normal file
20
node_modules/vega-functions/src/functions/tree.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import {data} from './data';
|
||||
|
||||
const datum = d => d.data;
|
||||
|
||||
function treeNodes(name, context) {
|
||||
const tree = data.call(context, name);
|
||||
return tree.root && tree.root.lookup || {};
|
||||
}
|
||||
|
||||
export function treePath(name, source, target) {
|
||||
const nodes = treeNodes(name, this),
|
||||
s = nodes[source],
|
||||
t = nodes[target];
|
||||
return s && t ? s.path(t).map(datum) : undefined;
|
||||
}
|
||||
|
||||
export function treeAncestors(name, node) {
|
||||
const n = treeNodes(name, this)[node];
|
||||
return n ? n.ancestors().map(datum) : undefined;
|
||||
}
|
||||
21
node_modules/vega-functions/src/functions/window.js
generated
vendored
Normal file
21
node_modules/vega-functions/src/functions/window.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
const _window = () => (typeof window !== 'undefined' && window) || null;
|
||||
|
||||
export function screen() {
|
||||
const w = _window();
|
||||
return w ? w.screen : {};
|
||||
}
|
||||
|
||||
export function windowSize() {
|
||||
const w = _window();
|
||||
return w
|
||||
? [w.innerWidth, w.innerHeight]
|
||||
: [undefined, undefined];
|
||||
}
|
||||
|
||||
export function containerSize() {
|
||||
const view = this.context.dataflow,
|
||||
el = view.container && view.container();
|
||||
return el
|
||||
? [el.clientWidth, el.clientHeight]
|
||||
: [undefined, undefined];
|
||||
}
|
||||
Reference in New Issue
Block a user