How to use the plywood.$ function in plywood

To help you get started, we’ve selected a few plywood examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github allegro / turnilo / src / client / components / legend / legend-content.tsx View on Github external
filter = filter.setExclusionForDimension(false, dimension);

    let filterExpression = filter.toExpression(dataCube);

    const shouldFoldRows = !unfolded && colors && colors.dimension === dimension.name && colors.values;

    if (shouldFoldRows) {
      filterExpression = filterExpression.and(dimension.expression.in(colors.toSet()));
    }

    if (searchText) {
      filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), "ignoreCase"));
    }

    let query: any = $("main")
      .filter(filterExpression);

    if (dimension.canBucketByDefault()) {
      query = query.split($(dimension.name).performAction(bucketToAction(this.bucketForDimension(essence, dimension))), dimension.name);
    } else {
      query = query.split(dimension.expression, dimension.name);

    }

    const sortSeries = essence.findConcreteSeries(sortOn.key);
    if (sortSeries) {
      query = query.performAction(sortSeries.plywoodExpression(0, { type: TimeShiftEnvType.CURRENT }));
    }

    const sortExpression = $(sortOn.key);
    query = query.sort(sortExpression, SortExpression.DESCENDING).limit(LegendContent.TOP_N + 1);
github geo-opensource / pivot / src / client / components / preview-string-filter-menu / preview-string-filter-menu.tsx View on Github external
fetchData(essence: Essence, timekeeper: Timekeeper, dimension: Dimension, searchText: string): void {
    var { dataCube } = essence;
    var nativeCount = dataCube.getMeasure('count');
    var measureExpression = nativeCount ? nativeCount.expression : $('main').count();

    var filterExpression = essence.getEffectiveFilter(timekeeper, null, dimension).toExpression();

    var query = $('main')
      .filter(filterExpression)
      .split(dimension.expression, dimension.name)
      .apply('MEASURE', measureExpression)
      .sort($('MEASURE'), SortAction.DESCENDING)
      .limit(TOP_N + 1);

    this.setState({
      loading: true,
      fetchQueued: false
    });
    QueryRunner.fetch(dataCube, query, essence.timezone)
      .then(
        (dataset: Dataset) => {
          if (!this.mounted) return;
          this.setState({
            loading: false,
            dataset,
            queryError: null
          });
        },
github allegro / turnilo / src / common / utils / plywood / some.mocha.ts View on Github external
it("should return true for top-level value satisfies predicate", () => {
    expect(some($("main"), isRefExp)).to.be.true;
  });
github allegro / turnilo / src / client / modals / raw-data-modal / raw-data-modal.tsx View on Github external
fetchData(essence: Essence, timekeeper: Timekeeper): void {
    const { dataCube } = essence;
    const $main = $("main");
    const query = $main.filter(essence.getEffectiveFilter(timekeeper).toExpression(dataCube)).limit(LIMIT);
    this.setState({ loading: true });
    dataCube.executor(query, { timezone: essence.timezone })
      .then(
        (dataset: Dataset) => {
          if (!this.mounted) return;
          this.setState({
            dataset,
            loading: false
          });
        },
        (error: Error) => {
          if (!this.mounted) return;
          this.setState({
            error,
            loading: false
github geo-opensource / pivot / src / client / components / selectable-string-filter-menu / selectable-string-filter-menu.tsx View on Github external
fetchData(essence: Essence, timekeeper: Timekeeper, dimension: Dimension, searchText: string): void {
    var { dataCube } = essence;
    var nativeCount = dataCube.getMeasure('count');
    var measureExpression = nativeCount ? nativeCount.expression : $('main').count();

    var filterExpression = essence.getEffectiveFilter(timekeeper, null, dimension).toExpression();

    if (searchText) {
      filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), 'ignoreCase'));
    }

    var query = $('main')
      .filter(filterExpression)
      .split(dimension.expression, dimension.name)
      .apply('MEASURE', measureExpression)
      .sort($('MEASURE'), SortAction.DESCENDING)
      .limit(TOP_N + 1);

    this.setState({
      loading: true,
      fetchQueued: false
    });
    QueryRunner.fetch(dataCube, query, essence.timezone)
      .then(
        (dataset: Dataset) => {
          if (!this.mounted) return;
          this.setState({
            loading: false,
github geo-opensource / pivot / src / client / components / number-range-picker / number-range-picker.tsx View on Github external
fetchData(essence: Essence, timekeeper: Timekeeper, dimension: Dimension, rightBound: number): void {
    var { dataCube } = essence;
    var filterExpression = essence.getEffectiveFilter(timekeeper, null, dimension).toExpression();
    var $main = $('main');
    var query = ply()
      .apply('main', $main.filter(filterExpression))
      .apply('Min', $main.min($(dimension.name)))
      .apply('Max', $main.max($(dimension.name)));

    this.setState({
      loading: true
    });

    QueryRunner.fetch(dataCube, query, Timezone.UTC)
      .then(
        (dataset: Dataset) => {
          if (!this.mounted) return;
          var min = (dataset.data[0]['Min'] as number);
          var max = (dataset.data[0]['Max'] as number);
github geo-opensource / pivot / src / client / components / dimension-tile / dimension-tile.tsx View on Github external
filter = filter.remove(dimension.expression);
    }

    filter = filter.setExclusionforDimension(false, dimension);

    var filterExpression = filter.toExpression();

    if (!unfolded && colors && colors.dimension === dimension.name && colors.values) {
      filterExpression = filterExpression.and(dimension.expression.in(colors.toSet()));
    }

    if (searchText) {
      filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), 'ignoreCase'));
    }

    var query: any = $('main')
      .filter(filterExpression);

    var sortExpression: Expression = null;

    if (dimension.canBucketByDefault()) {
      const dimensionExpression = dimension.expression as RefExpression;
      const attributeName = dimensionExpression.name;

      const filterSelection: FilterSelection = essence.filter.getSelection(dimensionExpression);

      if (!selectedGranularity) {
        if (filterSelection) {
          var range = dimension.kind === 'time' ? essence.evaluateSelection(filterSelection as Expression, timekeeper) : (filterSelection as Expression).getLiteralValue().extent();
          selectedGranularity = getBestGranularityForRange(range, true, dimension.bucketedBy, dimension.granularities);
        } else {
          selectedGranularity = getDefaultGranularityForKind(dimension.kind as ContinuousDimensionKind, dimension.bucketedBy, dimension.granularities);
github allegro / turnilo / src / client / components / filter-menu / time-filter-menu / presets.ts View on Github external
*     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { $, Expression } from "plywood";
import { TimeFilterPeriod } from "../../../../common/models/filter-clause/filter-clause";
import { TimeShift } from "../../../../common/models/time-shift/time-shift";
import { MAX_TIME_REF_NAME, NOW_REF_NAME } from "../../../../common/models/time/time";

const $MAX_TIME = $(MAX_TIME_REF_NAME);
const $NOW = $(NOW_REF_NAME);

export interface TimeFilterPreset {
  name: string;
  duration: string;
}

export const LATEST_PRESETS: TimeFilterPreset[] = [
  { name: "1H", duration: "PT1H" },
  { name: "6H", duration: "PT6H" },
  { name: "1D", duration: "P1D" },
  { name: "7D", duration: "P7D" },
  { name: "30D", duration: "P30D" }
];

export const CURRENT_PRESETS: TimeFilterPreset[] = [
  { name: "D", duration: "P1D" },