Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@d3fc/d3fc-sample

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@d3fc/d3fc-sample - npm Package Compare versions

Comparing version 4.0.9 to 4.0.10

build/d3fc-sample.min.js

427

build/d3fc-sample.js

@@ -8,301 +8,244 @@ (function (global, factory) {

function bucket () {
var bucketSize = 10;
var bucketSize = 10;
var bucket = function bucket(data) {
return bucketSize <= 1 ? data.map(function (d) {
return [d];
}) : d3Array.range(0, Math.ceil(data.length / bucketSize)).map(function (i) {
return data.slice(i * bucketSize, (i + 1) * bucketSize);
});
};
var bucket = function bucket(data) {
return bucketSize <= 1 ? data.map(function (d) {
return [d];
}) : d3Array.range(0, Math.ceil(data.length / bucketSize)).map(function (i) {
return data.slice(i * bucketSize, (i + 1) * bucketSize);
});
};
bucket.bucketSize = function (x) {
if (!arguments.length) {
return bucketSize;
}
bucket.bucketSize = function (x) {
if (!arguments.length) {
return bucketSize;
}
bucketSize = x;
return bucket;
};
bucketSize = x;
return bucket;
};
return bucket;
return bucket;
}
var createReboundMethod = (function (target, source, name) {
var method = source[name];
if (typeof method !== 'function') {
throw new Error('Attempt to rebind ' + name + ' which isn\'t a function on the source object');
}
return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var createReboundMethod = ((target, source, name) => {
const method = source[name];
var value = method.apply(source, args);
return value === source ? target : value;
};
if (typeof method !== 'function') {
throw new Error(`Attempt to rebind ${name} which isn't a function on the source object`);
}
return (...args) => {
var value = method.apply(source, args);
return value === source ? target : value;
};
});
var rebind = (function (target, source) {
for (var _len = arguments.length, names = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
names[_key - 2] = arguments[_key];
}
var rebind = ((target, source, ...names) => {
for (const name of names) {
target[name] = createReboundMethod(target, source, name);
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = names[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var name = _step.value;
target[name] = createReboundMethod(target, source, name);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return target;
return target;
});
function largestTriangleOneBucket () {
var dataBucketer = bucket();
var dataBucketer = bucket();
var x = function x(d) {
return d;
};
var y = function y(d) {
return d;
};
var x = function x(d) {
return d;
};
var largestTriangleOneBucket = function largestTriangleOneBucket(data) {
var y = function y(d) {
return d;
};
if (dataBucketer.bucketSize() >= data.length) {
return data;
}
var largestTriangleOneBucket = function largestTriangleOneBucket(data) {
if (dataBucketer.bucketSize() >= data.length) {
return data;
}
var pointAreas = calculateAreaOfPoints(data);
var pointAreaBuckets = dataBucketer(pointAreas);
var pointAreas = calculateAreaOfPoints(data);
var pointAreaBuckets = dataBucketer(pointAreas);
var buckets = dataBucketer(data.slice(1, data.length - 1));
var subsampledData = buckets.map(function (thisBucket, i) {
var pointAreaBucket = pointAreaBuckets[i];
var maxArea = d3Array.max(pointAreaBucket);
var currentMaxIndex = pointAreaBucket.indexOf(maxArea);
return thisBucket[currentMaxIndex];
}); // First and last data points are their own buckets.
var buckets = dataBucketer(data.slice(1, data.length - 1));
return [].concat([data[0]], subsampledData, [data[data.length - 1]]);
};
var subsampledData = buckets.map(function (thisBucket, i) {
function calculateAreaOfPoints(data) {
var xyData = data.map(function (point) {
return [x(point), y(point)];
});
var pointAreas = d3Array.range(1, xyData.length - 1).map(function (i) {
var lastPoint = xyData[i - 1];
var thisPoint = xyData[i];
var nextPoint = xyData[i + 1];
return 0.5 * Math.abs((lastPoint[0] - nextPoint[0]) * (thisPoint[1] - lastPoint[1]) - (lastPoint[0] - thisPoint[0]) * (nextPoint[1] - lastPoint[1]));
});
return pointAreas;
}
var pointAreaBucket = pointAreaBuckets[i];
var maxArea = d3Array.max(pointAreaBucket);
var currentMaxIndex = pointAreaBucket.indexOf(maxArea);
rebind(largestTriangleOneBucket, dataBucketer, 'bucketSize');
return thisBucket[currentMaxIndex];
});
largestTriangleOneBucket.x = function (d) {
if (!arguments.length) {
return x;
}
// First and last data points are their own buckets.
return [].concat([data[0]], subsampledData, [data[data.length - 1]]);
};
x = d;
return largestTriangleOneBucket;
};
function calculateAreaOfPoints(data) {
var xyData = data.map(function (point) {
return [x(point), y(point)];
});
var pointAreas = d3Array.range(1, xyData.length - 1).map(function (i) {
var lastPoint = xyData[i - 1];
var thisPoint = xyData[i];
var nextPoint = xyData[i + 1];
return 0.5 * Math.abs((lastPoint[0] - nextPoint[0]) * (thisPoint[1] - lastPoint[1]) - (lastPoint[0] - thisPoint[0]) * (nextPoint[1] - lastPoint[1]));
});
return pointAreas;
largestTriangleOneBucket.y = function (d) {
if (!arguments.length) {
return y;
}
rebind(largestTriangleOneBucket, dataBucketer, 'bucketSize');
y = d;
return largestTriangleOneBucket;
};
largestTriangleOneBucket.x = function (d) {
if (!arguments.length) {
return x;
}
x = d;
return largestTriangleOneBucket;
};
largestTriangleOneBucket.y = function (d) {
if (!arguments.length) {
return y;
}
y = d;
return largestTriangleOneBucket;
};
return largestTriangleOneBucket;
return largestTriangleOneBucket;
}
function largestTriangleThreeBucket () {
var x = function x(d) {
return d;
};
var x = function x(d) {
return d;
};
var y = function y(d) {
return d;
};
var dataBucketer = bucket();
var y = function y(d) {
return d;
};
var largestTriangleThreeBucket = function largestTriangleThreeBucket(data) {
var dataBucketer = bucket();
if (dataBucketer.bucketSize() >= data.length) {
return data;
}
var largestTriangleThreeBucket = function largestTriangleThreeBucket(data) {
if (dataBucketer.bucketSize() >= data.length) {
return data;
}
var buckets = dataBucketer(data.slice(1, data.length - 1));
var firstBucket = data[0];
var lastBucket = data[data.length - 1];
var buckets = dataBucketer(data.slice(1, data.length - 1));
var firstBucket = data[0];
var lastBucket = data[data.length - 1]; // Keep track of the last selected bucket info and all buckets
// (for the next bucket average)
// Keep track of the last selected bucket info and all buckets
// (for the next bucket average)
var allBuckets = [].concat([firstBucket], buckets, [lastBucket]);
var allBuckets = [].concat([firstBucket], buckets, [lastBucket]);
var lastSelectedX = x(firstBucket);
var lastSelectedY = y(firstBucket);
var subsampledData = buckets.map(function (thisBucket, i) {
var nextAvgX = d3Array.mean(allBuckets[i + 1], x);
var nextAvgY = d3Array.mean(allBuckets[i + 1], y);
var xyData = thisBucket.map(function (item) {
return [x(item), y(item)];
});
var areas = xyData.map(function (item) {
return 0.5 * Math.abs((lastSelectedX - nextAvgX) * (item[1] - lastSelectedY) - (lastSelectedX - item[0]) * (nextAvgY - lastSelectedY));
});
var highestIndex = areas.indexOf(d3Array.max(areas));
var highestXY = xyData[highestIndex];
lastSelectedX = highestXY[0];
lastSelectedY = highestXY[1];
return thisBucket[highestIndex];
}); // First and last data points are their own buckets.
var lastSelectedX = x(firstBucket);
var lastSelectedY = y(firstBucket);
return [].concat([data[0]], subsampledData, [data[data.length - 1]]);
};
var subsampledData = buckets.map(function (thisBucket, i) {
rebind(largestTriangleThreeBucket, dataBucketer, 'bucketSize');
var nextAvgX = d3Array.mean(allBuckets[i + 1], x);
var nextAvgY = d3Array.mean(allBuckets[i + 1], y);
largestTriangleThreeBucket.x = function (d) {
if (!arguments.length) {
return x;
}
var xyData = thisBucket.map(function (item) {
return [x(item), y(item)];
});
x = d;
return largestTriangleThreeBucket;
};
var areas = xyData.map(function (item) {
return 0.5 * Math.abs((lastSelectedX - nextAvgX) * (item[1] - lastSelectedY) - (lastSelectedX - item[0]) * (nextAvgY - lastSelectedY));
});
largestTriangleThreeBucket.y = function (d) {
if (!arguments.length) {
return y;
}
var highestIndex = areas.indexOf(d3Array.max(areas));
var highestXY = xyData[highestIndex];
y = d;
return largestTriangleThreeBucket;
};
lastSelectedX = highestXY[0];
lastSelectedY = highestXY[1];
return largestTriangleThreeBucket;
}
return thisBucket[highestIndex];
});
function modeMedian () {
var dataBucketer = bucket();
// First and last data points are their own buckets.
return [].concat([data[0]], subsampledData, [data[data.length - 1]]);
};
var value = function value(d) {
return d;
};
rebind(largestTriangleThreeBucket, dataBucketer, 'bucketSize');
var modeMedian = function modeMedian(data) {
if (dataBucketer.bucketSize() > data.length) {
return data;
}
largestTriangleThreeBucket.x = function (d) {
if (!arguments.length) {
return x;
}
var minMax = d3Array.extent(data, value);
var buckets = dataBucketer(data.slice(1, data.length - 1));
var subsampledData = buckets.map(function (thisBucket, i) {
var frequencies = {};
var mostFrequent;
var mostFrequentIndex;
var singleMostFrequent = true;
var values = thisBucket.map(value);
var globalMinMax = values.filter(function (value) {
return value === minMax[0] || value === minMax[1];
}).map(function (value) {
return values.indexOf(value);
})[0];
x = d;
if (globalMinMax !== undefined) {
return thisBucket[globalMinMax];
}
return largestTriangleThreeBucket;
};
largestTriangleThreeBucket.y = function (d) {
if (!arguments.length) {
return y;
values.forEach(function (item, i) {
if (frequencies[item] === undefined) {
frequencies[item] = 0;
}
y = d;
frequencies[item]++;
return largestTriangleThreeBucket;
};
return largestTriangleThreeBucket;
}
function modeMedian () {
var dataBucketer = bucket();
var value = function value(d) {
return d;
};
var modeMedian = function modeMedian(data) {
if (dataBucketer.bucketSize() > data.length) {
return data;
if (frequencies[item] > frequencies[mostFrequent] || mostFrequent === undefined) {
mostFrequent = item;
mostFrequentIndex = i;
singleMostFrequent = true;
} else if (frequencies[item] === frequencies[mostFrequent]) {
singleMostFrequent = false;
}
});
var minMax = d3Array.extent(data, value);
var buckets = dataBucketer(data.slice(1, data.length - 1));
if (singleMostFrequent) {
return thisBucket[mostFrequentIndex];
} else {
return thisBucket[Math.floor(thisBucket.length / 2)];
}
}); // First and last data points are their own buckets.
var subsampledData = buckets.map(function (thisBucket, i) {
return [].concat([data[0]], subsampledData, [data[data.length - 1]]);
};
var frequencies = {};
var mostFrequent;
var mostFrequentIndex;
var singleMostFrequent = true;
rebind(modeMedian, dataBucketer, 'bucketSize');
var values = thisBucket.map(value);
modeMedian.value = function (x) {
if (!arguments.length) {
return value;
}
var globalMinMax = values.filter(function (value) {
return value === minMax[0] || value === minMax[1];
}).map(function (value) {
return values.indexOf(value);
})[0];
value = x;
return modeMedian;
};
if (globalMinMax !== undefined) {
return thisBucket[globalMinMax];
}
values.forEach(function (item, i) {
if (frequencies[item] === undefined) {
frequencies[item] = 0;
}
frequencies[item]++;
if (frequencies[item] > frequencies[mostFrequent] || mostFrequent === undefined) {
mostFrequent = item;
mostFrequentIndex = i;
singleMostFrequent = true;
} else if (frequencies[item] === frequencies[mostFrequent]) {
singleMostFrequent = false;
}
});
if (singleMostFrequent) {
return thisBucket[mostFrequentIndex];
} else {
return thisBucket[Math.floor(thisBucket.length / 2)];
}
});
// First and last data points are their own buckets.
return [].concat([data[0]], subsampledData, [data[data.length - 1]]);
};
rebind(modeMedian, dataBucketer, 'bucketSize');
modeMedian.value = function (x) {
if (!arguments.length) {
return value;
}
value = x;
return modeMedian;
};
return modeMedian;
return modeMedian;
}

@@ -309,0 +252,0 @@

@@ -6,2 +6,10 @@ # Change Log

## [4.0.10](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-sample@4.0.9...@d3fc/d3fc-sample@4.0.10) (2019-09-04)
**Note:** Version bump only for package @d3fc/d3fc-sample
<a name="4.0.9"></a>

@@ -8,0 +16,0 @@ ## [4.0.9](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-sample@4.0.8...@d3fc/d3fc-sample@4.0.9) (2019-08-12)

{
"name": "@d3fc/d3fc-sample",
"version": "4.0.9",
"version": "4.0.10",
"description": "A data subsampler that chooses representative data points using a largest triangle or mode-median approach.",

@@ -34,3 +34,3 @@ "license": "MIT",

"dependencies": {
"@d3fc/d3fc-rebind": "^5.0.8",
"@d3fc/d3fc-rebind": "^5.0.9",
"d3-array": "^1.0.0"

@@ -40,3 +40,4 @@ },

"access": "public"
}
},
"gitHead": "d216bebca76b9bde7456f1c06e768bc67814dd2e"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc