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

port to ES6 module system #220

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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"type": "git",
"url": "https://github.com/andredumas/techan.js.git"
},
"license" : "MIT",
"license": "MIT",
"dependencies": {
"d3": "~4.2.6"
},
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/adx.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const adx = function() {
var date = function(d) { return d.date; },
adx = function(d) { return d.adx; },
plusDi = function(d) { return d.plusDi; },
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/aroon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const aroon = function () {

var date = function(d) { return d.date; },
up = function(d) { return d.up; },
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/atrtrailingstop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const atrtrailingstop = function() {
var date = function(d) { return d.date; },
up = function(d) { return d.up; },
down = function(d) { return d.down; };
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/bollinger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const bollinger = function() {
var date = function(d) { return d.date; },
middle = function(d) { return d.middleBand; },
upper = function(d) { return d.upperBand; },
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/crosshair.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const crosshair = function() {
/**
* Supports getter and setter. Watch out if used in d3 and the second parameter is an index!!
* This approach needs further thought.
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/ichimoku.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const ichimoku = function() {
var date = function(d) { return d.date; },
tenkanSen = function(d) { return d.tenkanSen; }, // Conversion line
kijunSen = function(d) { return d.kijunSen; }, // Base Line
Expand Down
61 changes: 39 additions & 22 deletions src/accessor/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
'use strict';


import { atrtrailingstop } from './atrtrailingstop';
import { crosshair } from './crosshair';
import { ichimoku } from './ichimoku';
import { macd } from './macd';
import { ohlc } from './ohlc';
import { rsi } from './rsi';
import { trendline } from './trendline';
import { value } from './value';
import { volume } from './volume';
import { tick } from './tick';
import { trade } from './trade';
import { adx } from './adx';
import { aroon } from './aroon';
import { stochastic } from './stochastic';
import { supstance } from './supstance';
import { williams } from './williams';
import { bollinger } from './bollinger';


// Provide IDs for all accessors. Default to date, but at least provide an option
module.exports = function() {
return {
atrtrailingstop: require('./atrtrailingstop'),
crosshair: require('./crosshair'),
ichimoku: require('./ichimoku'),
macd: require('./macd'),
ohlc: require('./ohlc'),
rsi: require('./rsi'),
trendline: require('./trendline'),
value: require('./value'),
volume: require('./volume'),
tick: require('./tick'),
trade: require('./trade'),
adx: require('./adx'),
aroon: require('./aroon'),
stochastic: require('./stochastic'),
supstance: require('./supstance'),
williams: require('./williams'),
bollinger: require('./bollinger')
};
};
export const accessors = ()=>({
atrtrailingstop: atrtrailingstop,
crosshair: crosshair,
ichimoku: ichimoku,
macd: macd,
ohlc: ohlc,
rsi: rsi,
trendline: trendline,
value: value,
volume: volume,
tick: tick,
trade: trade,
adx: adx,
aroon: aroon,
stochastic: stochastic,
supstance: supstance,
williams: williams,
bollinger: bollinger
});
4 changes: 1 addition & 3 deletions src/accessor/macd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const macd = function() {
var date = function(d) { return d.date; },
macd = function(d) { return d.macd; },
zero = function(d) { return d.zero; },
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/ohlc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const ohlc = function() {
var date = function(d) { return d.date; },
open = function(d) { return d.open; },
high = function(d) { return d.high; },
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/rsi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const rsi = function() {
var date = function(d) { return d.date; },
rsi = function(d) { return d.rsi; },
overbought = function(d) { return d.overbought; },
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/stochastic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const stochastic = function() {
var date = function(d) { return d.date; },
stochasticK = function(d) { return d.stochasticK; },
stochasticD = function(d) { return d.stochasticD; },
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/supstance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const supstance = function() {
var start = function(d) { return d.start; },
end = function(d) { return d.end; },
/**
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/tick.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const tick = function() {
var date = function(d) { return d.date; },
high = function(d) { return d.high; },
low = function(d) { return d.low; },
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/trade.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const trade = function() {
var date = function(d) { return d.date; },
type = function(d) { return d.type; },
price = function(d) { return d.price; };
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/trendline.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const trendline = function() {
var startDate = function(d, _) {
if(arguments.length < 2) return d.start.date;
d.start.date = _;
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/value.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const value = function() {
var date = function(d) { return d.date; },
/**
* Supports getter and setter
Expand Down
4 changes: 1 addition & 3 deletions src/accessor/volume.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const volume = function() {
var date = function(d) { return d.date; },
volume = function(d) { return d.volume; };

Expand Down
4 changes: 1 addition & 3 deletions src/accessor/williams.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const williams = function() {
var date = function(d) { return d.date; },
williams = function(d) { return d.williams; };

Expand Down
4 changes: 1 addition & 3 deletions src/indicator/adx.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(d3_max, indicatorMixin, accessor_ohlc, indicator_ema) { // Injected dependencies
export const adx = function(d3_max, indicatorMixin, accessor_ohlc, indicator_ema) { // Injected dependencies
return function() { // Closure function
var p = {}; // Container for private, direct access mixed in variables

Expand Down
4 changes: 1 addition & 3 deletions src/indicator/aroon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc) { // Injected dependencies
export const aroon = function(indicatorMixin, accessor_ohlc) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
overbought = 70,
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/atr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc, indicator_sma) { // Injected dependencies
export const atr_init = function(indicatorMixin, accessor_ohlc, indicator_sma) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
initialAtr = indicator_sma(),
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/atrtrailingstop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc, indicator_atr) { // Injected dependencies
export const atrtrailingstop = function(indicatorMixin, accessor_ohlc, indicator_atr) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
multiplier = 3,
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/bollinger.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc, indicator_sma) { // Injected dependencies
export const bollinger = function(indicatorMixin, accessor_ohlc, indicator_sma) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
sdMultiplication = 2,
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/ema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc, alpha_init) { // Injected dependencies
export const ema_init = function(indicatorMixin, accessor_ohlc, alpha_init) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
previous,
Expand Down
7 changes: 3 additions & 4 deletions src/indicator/heikinashi.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc, min, max) { // Injected dependencies
return function() { // Closure function
export const heikinashi = function(indicatorMixin, accessor_ohlc, min, max) { // Injected dependencies
//Injected dependencies
return function() { // Closure function
var p = {}; // Container for private, direct access mixed in variables

function indicator(data) {
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/ichimoku.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc) { // Injected dependencies
export const ichimoku = function(indicatorMixin, accessor_ohlc) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
tenkanSen = 9,
Expand Down
59 changes: 38 additions & 21 deletions src/indicator/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
'use strict';

module.exports = function(d3) {
var indicatorMixin = require('./indicatormixin')(),
accessor = require('../accessor')(),
ema_init = require('./ema'),
import { indicatormixin } from './indicatormixin';
import { accessors } from '../accessor';
import { ema_init } from './ema';
import { sma_init } from './sma';
import { atr_init } from './atr';
import { util } from '../util';
import { sroc_init } from './sroc';
import { vwap } from './vwap';


import { atrtrailingstop } from './atrtrailingstop';
import { heikinashi } from './heikinashi';
import { ichimoku } from './ichimoku';
import { macd } from './macd';
import { rsi } from './rsi';
import { adx } from './adx';
import { aroon } from './aroon';
import { stochastic } from './stochastic';
import { williams } from './williams';
import { bollinger } from './bollinger';

export const indicators = function(d3) {
var indicatorMixin = indicatormixin(),
accessor = accessors(),
ema = ema_init(indicatorMixin, accessor.ohlc, ema_alpha_init),
sma = require('./sma')(indicatorMixin, accessor.ohlc),
atr = require('./atr')(indicatorMixin, accessor.ohlc, sma),
circularbuffer = require('../util')().circularbuffer,
sroc_init = require('./sroc'),
vwap = require('./vwap')(indicatorMixin, accessor.ohlc);
sma = sma_init(indicatorMixin, accessor.ohlc),
atr = atr_init(indicatorMixin, accessor.ohlc, sma),
circularbuffer = util().circularbuffer;

return {
atr: atr,
atrtrailingstop: require('./atrtrailingstop')(indicatorMixin, accessor.ohlc, atr),
atrtrailingstop: atrtrailingstop(indicatorMixin, accessor.ohlc, atr),
ema: ema,
heikinashi: require('./heikinashi')(indicatorMixin, accessor.ohlc, d3.min, d3.max),
ichimoku: require('./ichimoku')(indicatorMixin, accessor.ohlc),
macd: require('./macd')(indicatorMixin, accessor.ohlc, ema),
rsi: require('./rsi')(indicatorMixin, accessor.ohlc, ema),
heikinashi: heikinashi(indicatorMixin, accessor.ohlc, d3.min, d3.max),
ichimoku: ichimoku(indicatorMixin, accessor.ohlc),
macd: macd(indicatorMixin, accessor.ohlc, ema),
rsi: rsi(indicatorMixin, accessor.ohlc, ema),
sma: sma,
wilderma: ema_init(indicatorMixin, accessor.ohlc, wilder_alpha_init),
aroon: require('./aroon')(indicatorMixin, accessor.ohlc),
aroon: aroon(indicatorMixin, accessor.ohlc),
roc: sroc_init(circularbuffer, indicatorMixin, accessor.ohlc, ema, 1),
sroc: sroc_init(circularbuffer, indicatorMixin, accessor.ohlc, ema, 13),
stochastic: require('./stochastic')(indicatorMixin, accessor.ohlc, ema),
williams: require('./williams')(indicatorMixin, accessor.ohlc, ema),
adx: require('./adx')(d3.max, indicatorMixin, accessor.ohlc, ema),
bollinger: require('./bollinger')(indicatorMixin, accessor.ohlc, sma),
vwap: vwap
stochastic: stochastic(indicatorMixin, accessor.ohlc, ema),
williams: williams(indicatorMixin, accessor.ohlc, ema),
adx: adx(d3.max, indicatorMixin, accessor.ohlc, ema),
bollinger: bollinger(indicatorMixin, accessor.ohlc, sma),
vwap: vwap(indicatorMixin, accessor.ohlc)
};
};

Expand Down
4 changes: 1 addition & 3 deletions src/indicator/indicatormixin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function() {
export const indicatormixin = function() {
return function(source, priv) {
var indicatorMixin = {};

Expand Down
4 changes: 1 addition & 3 deletions src/indicator/macd.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc, indicator_ema) { // Injected dependencies
export const macd = function(indicatorMixin, accessor_ohlc, indicator_ema) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
fast = 12,
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/rsi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc, indicator_ema) { // Injected dependencies
export const rsi = function(indicatorMixin, accessor_ohlc, indicator_ema) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
overbought = 70,
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/sma.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc) { // Injected dependencies
export const sma_init = function(indicatorMixin, accessor_ohlc) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
samples,
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/sroc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(techan_util_circularbuffer, indicatorMixin, accessor_ohlc, indicator_smoothing, smoothed_period) { // Injected dependencies
export const sroc_init = function(techan_util_circularbuffer, indicatorMixin, accessor_ohlc, indicator_smoothing, smoothed_period) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
smoothing = indicator_smoothing().period(smoothed_period),
Expand Down
4 changes: 1 addition & 3 deletions src/indicator/stochastic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = function(indicatorMixin, accessor_ohlc) { // Injected dependencies
export const stochastic = function(indicatorMixin, accessor_ohlc) { // Injected dependencies
return function() { // Closure function
var p = {}, // Container for private, direct access mixed in variables
periodD = 3,
Expand Down
Loading