@grafana/data#transformDataFrame TypeScript Examples

The following examples show how to use @grafana/data#transformDataFrame. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PanelQueryRunner.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/**
   * Returns an observable that subscribes to the shared multi-cast subject (that reply last result).
   */
  getData(transform = true): Observable<PanelData> {
    if (transform) {
      return this.subject.pipe(
        map((data: PanelData) => {
          if (this.hasTransformations()) {
            const newSeries = transformDataFrame(this.transformations, data.series);
            return { ...data, series: newSeries };
          }
          return data;
        })
      );
    }

    // Just pass it directly
    return this.subject.pipe();
  }
Example #2
Source File: TransformationsEditor.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
renderTransformationEditors = () => {
    const { transformations, dataFrames } = this.props;
    const hasTransformations = transformations.length > 0;
    const preTransformData = dataFrames;

    if (!hasTransformations) {
      return undefined;
    }

    const availableTransformers = transformersUIRegistry.list().map(t => {
      return {
        value: t.transformer.id,
        label: t.transformer.name,
      };
    });

    return (
      <>
        {transformations.map((t, i) => {
          let editor, input;
          if (t.id === DataTransformerID.noop) {
            return (
              <Select
                className={css`
                  margin-bottom: 10px;
                `}
                key={`${t.id}-${i}`}
                options={availableTransformers}
                placeholder="Select transformation"
                onChange={v => {
                  this.onTransformationChange(i, {
                    id: v.value as string,
                    options: {},
                  });
                }}
              />
            );
          }
          const transformationUI = transformersUIRegistry.getIfExists(t.id);
          input = transformDataFrame(transformations.slice(0, i), preTransformData);

          if (transformationUI) {
            editor = React.createElement(transformationUI.component, {
              options: { ...transformationUI.transformer.defaultOptions, ...t.options },
              input,
              onChange: (options: any) => {
                this.onTransformationChange(i, {
                  id: t.id,
                  options,
                });
              },
            });
          }

          return (
            <TransformationRow
              key={`${t.id}-${i}`}
              input={input || []}
              onRemove={() => this.onTransformationRemove(i)}
              editor={editor}
              name={transformationUI ? transformationUI.name : ''}
              description={transformationUI ? transformationUI.description : ''}
            />
          );
        })}
      </>
    );
  };