Ruler

5 min read

Ruler is the default set of visual rule definitions within ChartAdvisor. It does not provide any outward function or syntax.

In order to facilitate user customization of ChartAdvisor, we will introduce the relevant interfaces for rule customization in this API file.

RuleType

  • Interface *
type RuleType = 'HARD' | 'SOFT' | 'DESIGN';

BasicDataPropertyForAdvice

  • Interface *
interface BasicDataPropertyForAdvice {
  readonly name?: string;
  readonly levelOfMeasurements?: LOM[];
  readonly rawData: any[];
  readonly recommendation: analyzer.FieldInfo['recommendation'];
  readonly type: analyzer.FieldInfo['type'];
  readonly distinct?: number;
  readonly count?: number;
  readonly sum?: number;
  readonly maximum?: any;
  readonly minimum?: any;
  readonly missing?: number;
  [key: string]: any;
}
  • Parameters *
PropertiesTypeDescriptionDefault
namestringData name.None Optional
levelOfMeasurementsLOM[]Level of measurements.None Optional
rawDataany[]Source data.None Optional
recommendationanalyzer.FieldInfo['recommendation']Recommendation type.None
typeanalyzer.FieldInfo['type']Field type.None
distinctnumberDistinct value.None Optional
countnumberCount value.None Optional
sumnumberSum value.None Optional
maximumanyMax value.None Optional
minimumanyMin value.None Optional
missingnumberMissing value.None Optional
[key]anyCustomized features.None Optional
  • LOM Parameter configuration.
const LOM_OPTIONS: readonly ["Nominal", "Ordinal", 
"Interval", "Discrete", "Continuous", "Time"];
  • recommendation Parameter configuration.
type RecommendationTypes = 'null' | 'boolean' | 
'integer' | 'float' | 'date' | 'string' | 'mixed';
  • type Parameter configuration.
type TypeSpecifics = RecommendationTypes | 'mixed';

Info

  • Interface *
interface Info {
  chartType?: string;
  dataProps: BasicDataPropertyForAdvice[] | BasicDataPropertyForAdvice;
  purpose?: string;
  preferences?: Preferences;
  customWeight?: number;
  [key: string]: any;
}
  • Parameters *
PropertiesTypeDescriptionDefault
chartTypestringChart type.None Optional
dataPropsBasicDataPropertyForAdvice[] | BasicDataPropertyForAdviceBasic props.None
purposestringRecommend purpose.false
preferencesPreferencesRecommend preferences.None Optional
customWeightnumberCustomized weight.None Optional
[key]anyCustomized features.None Optional
  • purpose Parameter configuration.
type PURPOSE_OPTIONS = ["Comparison", "Trend", "Distribution", "Rank", "Proportion", 
  "Composition", "Relation", "Hierarchy", "Flow", "Spatial", "Anomaly", "Value"];
  • preferences Parameter configuration.
interface Preferences {
  canvasLayout: 'landscape' | 'portrait';
}

Validator

  • Interface *
type Validator = (args: Info) => number | boolean;

Trigger

  • Interface *
type Trigger = (args: Info) => boolean;

Optimizer

  • Interface *
type Optimizer = (
  dataProps: BasicDataPropertyForAdvice[] | BasicDataPropertyForAdvice | Partial<analyzer.GraphProps>,
  chartSpec: AntVSpec
) => object;

ChartRuleID

  • Interface *
const ChartRuleID = [
  'data-check',
  'data-field-qty',
  'no-redundant-field',
  'purpose-check',
  'series-qty-limit',
  'bar-series-qty',
  'line-field-time-ordinal',
  'landscape-or-portrait',
  'diff-pie-sector',
  'nominal-enum-combinatorial',
  'limit-series',
  'aggregation-single-row',
  'all-can-be-table',
];

ChartDesignRuleID

  • Interface *
const ChartDesignRuleID = ['x-axis-line-fading'];

ChartRuleConfig

  • Interface *
interface ChartRuleConfig {
  weight?: number;
  off?: boolean;
}
  • Parameters *
PropertiesTypeDescriptionDefault
weightnumberCustomized weight.None Optional
offbooleanWhether to ignore the rule by default.None Optional

ChartRuleConfigMap

  • Interface *
type ChartRuleConfigMap = Record<string, ChartRuleConfig>;

Docs

  • Interface *
type Docs = {
  lintText?: string;
  detailedText?: string;
  moreLink?: string;
  [key: string]: any;
};
  • Parameters *
PropertiesTypeDescriptionDefault
lintTextstringRule description.None Optional
detailedTextstringRule details.None Optional
moreLinkstringAdditional link.None Optional
[key]anyCustomized features.None Optional

DefaultRuleModule

  • Interface *
type DefaultRuleModule = {
  id: string;
  docs: Docs;
  trigger: Trigger;
  option?: ChartRuleConfig;
};
  • Parameters *
PropertiesTypeDescriptionDefault
idstringRule id.None
docsDocsRule description doc.None
triggerTriggerTrigger status.None
optionChartRuleConfigRule configurations.None Optional

ChartRuleModule

  • Interface *
type ChartRuleModule = DefaultRuleModule & {
  type: 'HARD' | 'SOFT';
  validator: Validator;
};

DesignRuleModule

  • Interface *
type DesignRuleModule = DefaultRuleModule & {
  type: 'DESIGN';
  optimizer: Optimizer;
};

RuleModule

  • Interface *
type RuleModule = ChartRuleModule | DesignRuleModule;

RuleConfig

  • Interface *
type RuleConfig = {
  include?: string[];
  exclude?: string[];
  custom?: Record<string, RuleModule>;
  options?: ChartRuleConfigMap;
};
  • Parameters *
PropertiesTypeDescriptionDefault
excludestring[]Rules to exclude.None Optional
includestring[]Rules to include, with lower property than exclude.None Optional
customRecord<string, RuleModule>Customized rules.None Optional
optionChartRuleConfigMapRule configurations group.None Optional