Fixes the vector
This commit is contained in:
parent
8f2cb18edc
commit
36cc3ec61a
|
@ -18,16 +18,7 @@ let timeDist =
|
||||||
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
|
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
|
||||||
~probabilityType=Pdf,
|
~probabilityType=Pdf,
|
||||||
~domain=Complete,
|
~domain=Complete,
|
||||||
~unit=
|
~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
|
||||||
TimeDistribution({
|
|
||||||
zero: MomentRe.momentNow(),
|
|
||||||
step: `years,
|
|
||||||
length:
|
|
||||||
MomentRe.Moment.add(
|
|
||||||
~duration=MomentRe.duration(5., `years),
|
|
||||||
MomentRe.momentNow(),
|
|
||||||
),
|
|
||||||
}),
|
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
|> GenericDistribution.renderIfNeeded(~sampleCount=3000);
|
|> GenericDistribution.renderIfNeeded(~sampleCount=3000);
|
||||||
|
|
|
@ -181,17 +181,19 @@ export class CdfChartD3 {
|
||||||
// Axis generator.
|
// Axis generator.
|
||||||
if (!!this.attrs.timeScale) {
|
if (!!this.attrs.timeScale) {
|
||||||
const zero = _.get(this.attrs.timeScale, 'zero', moment());
|
const zero = _.get(this.attrs.timeScale, 'zero', moment());
|
||||||
const step = _.get(this.attrs.timeScale, 'step', 'years');
|
const unit = _.get(this.attrs.timeScale, 'unit', 'years');
|
||||||
const length = _.get(this.attrs.timeScale, 'length', moment());
|
const diff = Math.abs(xMax - xMin);
|
||||||
|
const left = zero.clone().add(xMin, unit);
|
||||||
|
const right = left.clone().add(diff, unit);
|
||||||
|
|
||||||
const xScaleTime = d3.scaleTime()
|
const xScaleTime = d3.scaleTime()
|
||||||
.domain([zero.toDate(), length.toDate()])
|
.domain([left.toDate(), right.toDate()])
|
||||||
.nice()
|
.nice()
|
||||||
.range([0, calc.chartWidth]);
|
.range([0, calc.chartWidth]);
|
||||||
|
|
||||||
this.xAxis = d3.axisBottom()
|
this.xAxis = d3.axisBottom()
|
||||||
.scale(xScaleTime)
|
.scale(xScaleTime)
|
||||||
.ticks(this.getTimeTicksByStr(step))
|
.ticks(this.getTimeTicksByStr(unit))
|
||||||
.tickFormat(this.formatDates);
|
.tickFormat(this.formatDates);
|
||||||
} else {
|
} else {
|
||||||
this.xAxis = d3.axisBottom(this.xScale)
|
this.xAxis = d3.axisBottom(this.xScale)
|
||||||
|
@ -339,11 +341,11 @@ export class CdfChartD3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} step
|
* @param {string} unit
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
getTimeTicksByStr(step) {
|
getTimeTicksByStr(unit) {
|
||||||
switch (step) {
|
switch (unit) {
|
||||||
case "months":
|
case "months":
|
||||||
return d3.timeMonth.every(1);
|
return d3.timeMonth.every(1);
|
||||||
case "quarters":
|
case "quarters":
|
||||||
|
|
|
@ -51,13 +51,9 @@ type genericDistribution = {
|
||||||
module DistributionUnit = {
|
module DistributionUnit = {
|
||||||
let toJson = (distributionUnit: distributionUnit) =>
|
let toJson = (distributionUnit: distributionUnit) =>
|
||||||
switch (distributionUnit) {
|
switch (distributionUnit) {
|
||||||
| TimeDistribution({zero, step, length}) =>
|
| TimeDistribution({zero, unit}) =>
|
||||||
Js.Null.fromOption(
|
Js.Null.fromOption(
|
||||||
Some({
|
Some({"zero": zero, "unit": unit |> TimeTypes.TimeUnit.toString}),
|
||||||
"zero": zero,
|
|
||||||
"step": step |> TimeTypes.TimeUnit.toString,
|
|
||||||
"length": length,
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
| _ => Js.Null.fromOption(None)
|
| _ => Js.Null.fromOption(None)
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,8 +12,7 @@ type timeUnit = [
|
||||||
|
|
||||||
type timeVector = {
|
type timeVector = {
|
||||||
zero: MomentRe.Moment.t,
|
zero: MomentRe.Moment.t,
|
||||||
length: MomentRe.Moment.t,
|
unit: timeUnit,
|
||||||
step: timeUnit,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type timePoint = {
|
type timePoint = {
|
||||||
|
@ -43,12 +42,12 @@ module TimePoint = {
|
||||||
timePoint.timeVector.zero
|
timePoint.timeVector.zero
|
||||||
|> MomentRe.Moment.add(
|
|> MomentRe.Moment.add(
|
||||||
~duration=
|
~duration=
|
||||||
MomentRe.duration(timePoint.value, timePoint.timeVector.step),
|
MomentRe.duration(timePoint.value, timePoint.timeVector.unit),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let fromMoment = (timeVector: timeVector, moment: MomentRe.Moment.t) =>
|
let fromMoment = (timeVector: timeVector, moment: MomentRe.Moment.t) =>
|
||||||
MomentRe.diff(timeVector.zero, moment, timeVector.step);
|
MomentRe.diff(timeVector.zero, moment, timeVector.unit);
|
||||||
};
|
};
|
||||||
|
|
||||||
module RelativeTimePoint = {
|
module RelativeTimePoint = {
|
||||||
|
@ -61,7 +60,7 @@ module RelativeTimePoint = {
|
||||||
| Time(r) => r
|
| Time(r) => r
|
||||||
| XValue(r) =>
|
| XValue(r) =>
|
||||||
timeVector.zero
|
timeVector.zero
|
||||||
|> MomentRe.Moment.add(~duration=MomentRe.duration(r, timeVector.step))
|
|> MomentRe.Moment.add(~duration=MomentRe.duration(r, timeVector.unit))
|
||||||
};
|
};
|
||||||
|
|
||||||
let _timeToX = (time, timeStart, timeUnit) =>
|
let _timeToX = (time, timeStart, timeUnit) =>
|
||||||
|
@ -69,7 +68,7 @@ module RelativeTimePoint = {
|
||||||
|
|
||||||
let toXValue = (timeVector: timeVector, timeInVector: timeInVector) =>
|
let toXValue = (timeVector: timeVector, timeInVector: timeInVector) =>
|
||||||
switch (timeInVector) {
|
switch (timeInVector) {
|
||||||
| Time(r) => _timeToX(r, timeVector.zero, timeVector.step)
|
| Time(r) => _timeToX(r, timeVector.zero, timeVector.unit)
|
||||||
| XValue(r) => r
|
| XValue(r) => r
|
||||||
};
|
};
|
||||||
};
|
};
|
|
@ -154,12 +154,7 @@ module Model = {
|
||||||
),
|
),
|
||||||
~probabilityType=Cdf,
|
~probabilityType=Cdf,
|
||||||
~domain=RightLimited({xPoint: 100., excludingProbabilityMass: 0.3}),
|
~domain=RightLimited({xPoint: 100., excludingProbabilityMass: 0.3}),
|
||||||
~unit=
|
~unit=TimeDistribution({zero: currentDateTime, unit: `years}),
|
||||||
TimeDistribution({
|
|
||||||
zero: currentDateTime,
|
|
||||||
step: `years,
|
|
||||||
length: currentDateTime,
|
|
||||||
}),
|
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,12 +7,7 @@ module Model = {
|
||||||
~generationSource=GuesstimatorString(guesstimatorString),
|
~generationSource=GuesstimatorString(guesstimatorString),
|
||||||
~probabilityType=Cdf,
|
~probabilityType=Cdf,
|
||||||
~domain=RightLimited({xPoint: 200., excludingProbabilityMass: 0.3}),
|
~domain=RightLimited({xPoint: 200., excludingProbabilityMass: 0.3}),
|
||||||
~unit=
|
~unit=TimeDistribution({zero: currentDateTime, unit: `years}),
|
||||||
TimeDistribution({
|
|
||||||
zero: currentDateTime,
|
|
||||||
step: `years,
|
|
||||||
length: currentDateTime,
|
|
||||||
}),
|
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
Prop.Value.GenericDistribution(genericDistribution);
|
Prop.Value.GenericDistribution(genericDistribution);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user