diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f7909030..3ef224938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ - The "in order" option is inverted, so it is now "in free order" and unchecked by default (but still `in_order` in the URL query param and in the API) - The checkbox of said option no longer gets disabled in Extended mode -- Fixed parallel sentence alignment [#323](https://github.com/spraakbanken/korp-frontend/issues/323) + +### Fixed + +- Parallel sentence alignment [#323](https://github.com/spraakbanken/korp-frontend/issues/323) +- Trend diagram subquery with repetition [#288](https://github.com/spraakbanken/korp-frontend/issues/288) ### Removed diff --git a/app/scripts/components/trend_diagram.js b/app/scripts/components/trend_diagram.js index 9988beafd..e9ce6c235 100644 --- a/app/scripts/components/trend_diagram.js +++ b/app/scripts/components/trend_diagram.js @@ -109,8 +109,7 @@ export const trendDiagramComponent = { return } - const nTokens = $ctrl.data.cqp.split("]").length - 2 - const timecqp = trendUtil.getTimeCQP(time, zoom, nTokens, validZoomLevels.indexOf(zoom) < 3) + const timecqp = trendUtil.getTimeCQP(time, zoom, validZoomLevels.indexOf(zoom) < 3) const decodedCQP = decodeURIComponent(cqp) const opts = { ajaxParams: { diff --git a/app/scripts/trend_diagram/trend_util.js b/app/scripts/trend_diagram/trend_util.js index 540ad7ff0..b2b8bffd7 100644 --- a/app/scripts/trend_diagram/trend_util.js +++ b/app/scripts/trend_diagram/trend_util.js @@ -1,5 +1,5 @@ /** @format */ -export function getTimeCQP(time, zoom, n_tokens, coarseGranularity) { +export function getTimeCQP(time, zoom, coarseGranularity) { let timecqp const m = moment(time * 1000) @@ -13,26 +13,21 @@ export function getTimeCQP(time, zoom, n_tokens, coarseGranularity) { if (coarseGranularity) { // year, month, day - timecqp = `[(int(_.text_datefrom) >= ${datefrom} & int(_.text_dateto) <= ${dateto}) | - (int(_.text_datefrom) <= ${datefrom} & int(_.text_dateto) >= ${dateto}) - ]` + const dateInside = `(int(_.text_datefrom) >= ${datefrom} & int(_.text_dateto) <= ${dateto})` + const dateOutside = `(int(_.text_datefrom) <= ${datefrom} & int(_.text_dateto) >= ${dateto})` + timecqp = `[${dateInside} | ${dateOutside}]` } else { // hour, minute, second const timefrom = moment(m).startOf(zoom).format("HHmmss") const timeto = moment(m).endOf(zoom).format("HHmmss") - timecqp = `[(int(_.text_datefrom) = ${datefrom} & - int(_.text_timefrom) >= ${timefrom} & - int(_.text_dateto) <= ${dateto} & - int(_.text_timeto) <= ${timeto}) | - ((int(_.text_datefrom) < ${datefrom} | - (int(_.text_datefrom) = ${datefrom} & int(_.text_timefrom) <= ${timefrom}) - ) & - (int(_.text_dateto) > ${dateto} | - (int(_.text_dateto) = ${dateto} & int(_.text_timeto) >= ${timeto}) - ))]` + const startsSameDate = `(int(_.text_datefrom) = ${datefrom} & int(_.text_dateto) <= ${dateto})` + const timeInside = `(int(_.text_timefrom) >= ${timefrom} & int(_.text_timeto) <= ${timeto})` + const startsBefore = `(int(_.text_datefrom) < ${datefrom} | (int(_.text_datefrom) = ${datefrom} & int(_.text_timefrom) <= ${timefrom}))` + const endsAfter = `(int(_.text_dateto) > ${dateto} | (int(_.text_dateto) = ${dateto} & int(_.text_timeto) >= ${timeto}))` + timecqp = `[(${startsSameDate} & ${timeInside}) | (${startsBefore} & ${endsAfter})]` } - timecqp = [timecqp].concat(_.map(_.range(0, n_tokens), () => "[]")).join(" ") + timecqp = ` ${timecqp} []* ` return timecqp }