注: 以下の翻訳の正確性は検証されていません。AIPを利用して英語版の原文から機械的に翻訳されたものです。
インラインメトリクスを使うと、アプリケーションの作成者は主要なデータをチャート内に直接、簡単に表示できます。
このページのコード例は、TypeScript v1 と TypeScript v2 の両方の関数で利用可能です。関数のバージョンに合ったタブを選択します。TypeScript v1 では、エクスポートされたクラスのメソッドとして各関数を定義し、@foundry/functions-api の @Function() デコレーターを付け、Objects.search() を通じてオントロジーをクエリします。TypeScript v2 では、export default を使って関数を定義し、@osdk/functions からデータ型をインポートし、オントロジー SDK クライアント、またはパラメーターとして渡された ObjectSet を通じてオントロジーをクエリします。詳しい比較については、TypeScript v1 と TypeScript v2 の比較を参照してください。
インラインメトリクスには、次の形式に一致するカスタム型のリストを返す関数が必要です。
Copied!1 2 3 4interface InlineMetricsBucket { range: IRange<Timestamp>; value: Double }
Copied!1 2 3 4 5 6import { Double, Range, TimestampISOString } from "@osdk/functions"; interface InlineMetricsBucket { range: Range<TimestampISOString>; value: Double; }
インラインメトリクスは、ほかの戻り値の型もサポートできます。
Copied!1 2 3 4 5 6 7 8 9 10// 注:インターフェースの名前は重要ではなく、キーの名前のみが重要です interface InlineMetricsBucketInteger { range: IRange<Timestamp>; value: Integer } interface InlineMetricsBucketString { range: IRange<LocalDate>; value: string }
Copied!1 2 3 4 5 6 7 8 9 10 11 12import { DateISOString, Integer, Range, TimestampISOString } from "@osdk/functions"; // 注:インターフェースの名前は重要ではなく、キーの名前のみが重要です interface InlineMetricsBucketInteger { range: Range<TimestampISOString>; value: Integer; } interface InlineMetricsBucketString { range: Range<DateISOString>; value: string; }
range キーは、Timestamp、LocalDate、または Integer(数値はエポックからのミリ秒数を表します)の範囲型をサポートできます。TypeScript v1 は @foundry/functions-api の IRange 型を使用し、TypeScript v2 は @osdk/functions の対応する Range 型を使用します。後者の内部型は TimestampISOString、DateISOString、または Integer です。この2つのデータ型では端点の名前が異なり、IRange<T> は min と max を持ち、Range<T> は startValue と endValue を持ちます。
value キーは、string、Integer、または Double の値をサポートできます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35import { Double, Function, IRange, Timestamp } from "@foundry/functions-api"; import { Objects } from "@foundry/ontology-api"; interface InlineMetricBucketV1Double { range: IRange<Timestamp>; value: Double; } export class MyFunctions { // 指定された範囲を日単位のステップ幅でバケットに分け、各バケット内のタスクの件数を数えます @Function() public getInlineMetricsV1WithObjectCounts(startTime: Timestamp, endTime: Timestamp, step: Double): Array<InlineMetricBucketV1Double> { const tasks = Objects.search().schedulingMaintenanceTask().filter(x => x.startTime.range().gte(startTime).lte(endTime) ).all(); const buckets: InlineMetricBucketV1Double[] = []; let current = startTime; let count = 0 while (current < endTime) { const currentEnd: Timestamp = current.plusDays(step); const tasksInRange = tasks.filter(x => x.startTime! >= current && x.startTime! <= currentEnd); buckets.push({ range: { min: current, max: currentEnd }, value: tasksInRange.length }) current = currentEnd; count++; } return buckets } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44import { Client } from "@osdk/client"; import { Double, Range, TimestampISOString } from "@osdk/functions"; import { SchedulingMaintenanceTask } from "@ontology/sdk"; interface InlineMetricBucketDouble { range: Range<TimestampISOString>; value: Double; } // 指定された範囲を日単位のステップ幅でバケットに分け、各バケット内のタスクの件数を数えます export default async function getInlineMetricsWithObjectCounts( client: Client, startTime: TimestampISOString, endTime: TimestampISOString, step: Double ): Promise<Array<InlineMetricBucketDouble>> { const tasks = await Array.fromAsync( client(SchedulingMaintenanceTask) .where({ startTime: { $gte: startTime, $lte: endTime } }) .asyncIter() ); const buckets: InlineMetricBucketDouble[] = []; let current = new Date(startTime); const end = new Date(endTime); while (current < end) { const currentEnd = new Date(current); currentEnd.setUTCDate(currentEnd.getUTCDate() + step); const tasksInRange = tasks.filter(t => t.startTime != null && new Date(t.startTime) >= current && new Date(t.startTime) <= currentEnd ); buckets.push({ range: { startValue: current.toISOString(), endValue: currentEnd.toISOString(), }, value: tasksInRange.length, }); current = currentEnd; } return buckets; }
ヘッダーメトリクスは X 軸に沿ってヘッダーとして表示されるため、これらの関数は、入力として特定のオブジェクトに必ずしも紐付いているわけではありません。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32import { Double, Function, IRange, Timestamp } from "@foundry/functions-api"; import { ObjectSet, SchedulingTechnician_1 } from "@foundry/ontology-api"; interface InlineMetricBucketV1String { range: IRange<Timestamp>; value: string; } export class MyFunctions { // 行の名前を、その行が属するバケットの番号とともに返します @Function() public getInlineMetricsV1StringWithObject(techs: ObjectSet<SchedulingTechnician_1>, startTime: Timestamp, endTime: Timestamp, step: Double): Array<InlineMetricBucketV1String> { const techName = techs.all()[0].fullName; const buckets: Array<InlineMetricBucketV1String> = []; let current = startTime; let count = 0; while (current < endTime) { const currentEnd: Timestamp = current.plusDays(step); buckets.push({ range: { min: current, max: currentEnd }, value: `${techName}-${count}`, }) current = currentEnd; count++; } return buckets } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38import { ObjectSet } from "@osdk/client"; import { Double, Range, TimestampISOString } from "@osdk/functions"; import { SchedulingTechnician } from "@ontology/sdk"; interface InlineMetricBucketString { range: Range<TimestampISOString>; value: string; } // 行の名前を、その行が属するバケットの番号とともに返します export default async function getInlineMetricsStringWithObject( techs: ObjectSet<SchedulingTechnician>, startTime: TimestampISOString, endTime: TimestampISOString, step: Double ): Promise<Array<InlineMetricBucketString>> { const firstPage = await techs.fetchPage({ $pageSize: 1 }); const techName = firstPage.data[0].fullName; const buckets: Array<InlineMetricBucketString> = []; let current = new Date(startTime); const end = new Date(endTime); let count = 0; while (current < end) { const currentEnd = new Date(current); currentEnd.setUTCDate(currentEnd.getUTCDate() + step); buckets.push({ range: { startValue: current.toISOString(), endValue: currentEnd.toISOString(), }, value: `${techName}-${count}`, }); current = currentEnd; count++; } return buckets; }
行メトリクスは、対応する行のオブジェクトを実行時の入力として受け取ります。設定で関数を指定するときに、オブジェクトパラメーターを実行時の入力として指定できます。ウィジェットは、対応する行を自動的に関数に渡します。
Scheduling Gantt Chart ウィジェットの設定には、ヘッダーレベルと行レベルのメトリクスのオプションを含む Metrics セクションがあります。
メトリクスの設定では、表示タイトルの入力、アイコンの選択、条件付きの色分けの設定を行えます。
