Skip to content

Commit 65b71f8

Browse files
committed
Move the math helper.
1 parent 04cd63f commit 65b71f8

File tree

3 files changed

+47
-47
lines changed

3 files changed

+47
-47
lines changed

extension-src/dataTool/prepareBoxplotData.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* under the License.
1818
*/
1919

20-
import quantile from './quantile';
2120
import * as numberUtil from '../../src/util/number';
2221

2322
/**
@@ -58,9 +57,9 @@ export default function (rawData, opt) {
5857
axisData.push(i + '');
5958
var ascList = numberUtil.asc(rawData[i].slice());
6059

61-
var Q1 = quantile(ascList, 0.25);
62-
var Q2 = quantile(ascList, 0.5);
63-
var Q3 = quantile(ascList, 0.75);
60+
var Q1 = numberUtil.quantile(ascList, 0.25);
61+
var Q2 = numberUtil.quantile(ascList, 0.5);
62+
var Q3 = numberUtil.quantile(ascList, 0.75);
6463
var min = ascList[0];
6564
var max = ascList[ascList.length - 1];
6665

extension-src/dataTool/quantile.js

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

src/util/number.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,50 @@ export function nice(val, round) {
409409
return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
410410
}
411411

412+
/**
413+
* BSD 3-Clause
414+
*
415+
* Copyright (c) 2010-2015, Michael Bostock
416+
* All rights reserved.
417+
*
418+
* Redistribution and use in source and binary forms, with or without
419+
* modification, are permitted provided that the following conditions are met:
420+
*
421+
* * Redistributions of source code must retain the above copyright notice, this
422+
* list of conditions and the following disclaimer.
423+
*
424+
* * Redistributions in binary form must reproduce the above copyright notice,
425+
* this list of conditions and the following disclaimer in the documentation
426+
* and/or other materials provided with the distribution.
427+
*
428+
* * The name Michael Bostock may not be used to endorse or promote products
429+
* derived from this software without specific prior written permission.
430+
*
431+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
432+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
433+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
434+
* DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
435+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
436+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
437+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
438+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
439+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
440+
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
441+
*/
442+
443+
/**
444+
* @see <https://github.com/mbostock/d3/blob/master/src/arrays/quantile.js>
445+
* @see <http://en.wikipedia.org/wiki/Quantile>
446+
* @param {Array.<number>} ascArr
447+
*/
448+
export function quantile(ascArr, p) {
449+
var H = (ascArr.length - 1) * p + 1;
450+
var h = Math.floor(H);
451+
var v = +ascArr[h - 1];
452+
var e = H - h;
453+
return e ? v + e * (ascArr[h] - v) : v;
454+
}
455+
412456
/**
413457
* Order intervals asc, and split them when overlap.
414458
* expect(numberUtil.reformIntervals([

0 commit comments

Comments
 (0)