From 9592e50c1bfb760ef69da2b4999ddc0582e135ee Mon Sep 17 00:00:00 2001 From: Roman Galochkin Date: Fri, 28 Feb 2020 13:49:39 +0300 Subject: [PATCH 1/4] Adds ticks --- src/components/charts/DistributionPlot/distPlotD3.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/charts/DistributionPlot/distPlotD3.js b/src/components/charts/DistributionPlot/distPlotD3.js index e781576d..7d21a632 100644 --- a/src/components/charts/DistributionPlot/distPlotD3.js +++ b/src/components/charts/DistributionPlot/distPlotD3.js @@ -337,11 +337,14 @@ export class CdfChartD3 { .domain([yMinDomain, yMaxDomain]) .range([this.calc.chartHeight, 0]); + const yTicks = Math.floor(this.calc.chartHeight / 20); + const yAxis = d3.axisLeft(yScale).ticks(yTicks); + // Adds 'g' for an y-axis. this.chart.append('g') .attr('class', 'lollipops-y-axis') .attr('transform', `translate(${this.calc.chartWidth}, 0)`) - .call(d3.axisLeft(yScale)); + .call(yAxis); function showTooltip(d) { d3.select('#lollipops-line-' + d.id) From 9a41be8c37eed1d625b7625aeb27febf9af40be8 Mon Sep 17 00:00:00 2001 From: Roman Galochkin Date: Mon, 2 Mar 2020 08:31:09 +0300 Subject: [PATCH 2/4] Fixes quarters --- src/components/charts/DistributionPlot/distPlotD3.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/charts/DistributionPlot/distPlotD3.js b/src/components/charts/DistributionPlot/distPlotD3.js index 7d21a632..d4edb40b 100644 --- a/src/components/charts/DistributionPlot/distPlotD3.js +++ b/src/components/charts/DistributionPlot/distPlotD3.js @@ -430,7 +430,10 @@ export class CdfChartD3 { case 'months': return d3.timeMonth.every(4); case 'quarters': - return d3.timeMonth.every(3); + // It is temporary solution, but it works + // if the difference between edge dates is not + // much more than 10 units. + return d3.timeMonth.every(12); case 'hours': return d3.timeHour.every(10); case 'days': From a2c5eaac89b76e80e027608455b95fb922ad74d8 Mon Sep 17 00:00:00 2001 From: Roman Galochkin Date: Mon, 2 Mar 2020 08:47:04 +0300 Subject: [PATCH 3/4] Fixes rectangles --- src/components/charts/DistributionPlot/distPlotD3.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/charts/DistributionPlot/distPlotD3.js b/src/components/charts/DistributionPlot/distPlotD3.js index d4edb40b..47f39133 100644 --- a/src/components/charts/DistributionPlot/distPlotD3.js +++ b/src/components/charts/DistributionPlot/distPlotD3.js @@ -169,7 +169,7 @@ export class CdfChartD3 { const areaColorRange = d3.scaleOrdinal().range(this.attrs.areaColors); const dataPoints = [this.getDataPoints('continuous')]; - const { xMin, xMax, xScale, yScale } = common; + const { xMin, xMax, xScale, yScale } = common; // X-axis. let xAxis = null; @@ -403,9 +403,9 @@ export class CdfChartD3 { .enter() .append('rect') .attr('width', 30) - .attr('height', this.calc.chartHeight) + .attr('height', d => this.calc.chartHeight - yScale(d.y) + 10) .attr('x', d => common.xScale(d.x) - 15) - .attr('y', 0) + .attr('y', d => yScale(d.y) - 10) .attr('opacity', 0) .attr('pointer-events', 'all') .on('mouseover', showTooltip) From 5ee9a6d227e7e8732b50ebf134ea1dcee3e989e5 Mon Sep 17 00:00:00 2001 From: Roman Galochkin Date: Mon, 2 Mar 2020 10:05:39 +0300 Subject: [PATCH 4/4] Adds jsDoc --- src/utility/GuesstimatorLibrary.js | 91 ++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 31 deletions(-) diff --git a/src/utility/GuesstimatorLibrary.js b/src/utility/GuesstimatorLibrary.js index bbe6a493..a102d5fd 100644 --- a/src/utility/GuesstimatorLibrary.js +++ b/src/utility/GuesstimatorLibrary.js @@ -34,15 +34,29 @@ const ratioSize = samples => { }; +/** + * @param values + * @param outputResolutionCount + * @param min + * @param max + * @returns {{discrete: {ys: *, xs: *}, continuous: {ys: [], xs: []}}} + */ const toPdf = (values, outputResolutionCount, min, max) => { let duplicateSamples = _(values).groupBy().pickBy(x => x.length > 1).keys().value(); let totalLength = _.size(values); - let frequencies = duplicateSamples.map(s => ({value: parseFloat(s), percentage: _(values).filter(x => x ==s).size()/totalLength})); + let frequencies = duplicateSamples.map(s => ({ + value: parseFloat(s), + percentage: _(values).filter(x => x == s).size() / totalLength + })); let continuousSamples = _.difference(values, frequencies.map(f => f.value)); - let discrete = {xs: frequencies.map(f => f.value), ys: frequencies.map(f => f.percentage)}; - let continuous = {ys: [], xs: []}; - if (continuousSamples.length > 20){ + let discrete = { + xs: frequencies.map(f => f.value), + ys: frequencies.map(f => f.percentage) + }; + let continuous = { ys: [], xs: [] }; + + if (continuousSamples.length > 20) { const samples = new Samples(continuousSamples); const ratioSize$ = ratioSize(samples); @@ -51,38 +65,53 @@ const toPdf = (values, outputResolutionCount, min, max) => { const pdf = samples.toPdf({ size: outputResolutionCount, width, min, max }); continuous = pdf; } - return {continuous, discrete}; + + return { continuous, discrete }; }; -let run = (text, sampleCount, outputResolutionCount, inputs=[], min=false, max=false) => { - let [_error, item] = Guesstimator.parse({ text: "=" + text }); - const { parsedInput } = item; - const { guesstimateType } = parsedInput; +/** + * @param text + * @param sampleCount + * @param outputResolutionCount + * @param inputs + * @param min + * @param max + * @returns {{discrete: {ys: *, xs: *}, continuous: {ys: *[], xs: *[]}}} + */ +const run = ( + text, + sampleCount, + outputResolutionCount, + inputs = [], + min = false, + max = false, +) => { + const [_error, item] = Guesstimator.parse({ text: "=" + text }); + const { parsedInput } = item; - const guesstimator = new Guesstimator({ parsedInput }); - const value = guesstimator.sample( - sampleCount, - inputs, - ); - const samplerType = guesstimator.samplerType(); + const guesstimator = new Guesstimator({ parsedInput }); + const value = guesstimator.sample( + sampleCount, + inputs, + ); - const values = _.filter(value.values, _.isFinite); + const values = _.filter(value.values, _.isFinite); - let update; - let blankResponse = { - continuous: {ys: [], xs: []}, - discrete: {ys: [], xs: []} - }; - if (values.length === 0) { - update = blankResponse; - } else if (values.length === 1) { - update = blankResponse; - } else { - update = toPdf(values, outputResolutionCount, min, max); - } - return update; -} + let update; + let blankResponse = { + continuous: { ys: [], xs: [] }, + discrete: { ys: [], xs: [] } + }; + if (values.length === 0) { + update = blankResponse; + } else if (values.length === 1) { + update = blankResponse; + } else { + update = toPdf(values, outputResolutionCount, min, max); + } + return update; +}; module.exports = { run, -}; \ No newline at end of file +};