Skip to content

Instantly share code, notes, and snippets.

@carlosrusso
Created August 5, 2016 16:39
Show Gist options
  • Save carlosrusso/6ec1ac69585b32b4282f4bc75f1a1e78 to your computer and use it in GitHub Desktop.
Save carlosrusso/6ec1ac69585b32b4282f4bc75f1a1e78 to your computer and use it in GitHub Desktop.
Notes on visual roles
/*!
* Copyright 2010 - 2016 Pentaho Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* 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.
*/
define([
"module",
"../abstract/model",
"pentaho/i18n!../abstract/i18n/model",
"../abstract/types/labelsOption",
"../abstract/mixins/settingsMultiChartType"
], function(module, abstractModelFactory, bundle, labelsOptionFactory, settingsMultiChartType) {
"use strict";
return function(context) {
var Abstract = context.get(abstractModelFactory);
return Abstract.extend({
type: {
sourceId: module.id,
id: module.id.replace(/.\w+$/, ""),
v2Id: "ccc_pie",
category: "piechart",
defaultView: "./View",
props: [
{
name: "columns", //VISUAL_ROLE
type: "pentaho/visual/role/ordinal", //
ordinal: 6
},
{
/*
vizModel.measures === vizModel.getv("measures") -> instance of the visual role mapping
(in the complexes and lists, getv === get, but in simples, get returns the boxed valued)
*/
name: "measures", //VISUAL_ROLE
type: { // defines the type of the value of this property
base: "pentaho/visual/role/quantitative", // takes a "quantitative" (derived from complex)
dataType: "number", // enforces a "number" dataType, i.e. the dataTable column must be of type "number"
props: {attributes: {isRequired: true}} // this value is a complex, so I need to specify properties
// The "measures" visual role mapping contains a two properties: `level` and `attributes`
// We enforce that the property `attributes` is required.
// We could equally as well say
// props: {attributes: {countMin: 0, countMax: 3}} // not required, up to 3 fields
/*
vizModel.isRequired("measures"); // must this visual role mapping have a non-null value? It is always non-null (because it's a complex)
vizModel.measures.type.get("attributes").isRequired // this is how I obtain the definition of isRequired (can be a function or a static value)
vizModel.measures.isRequired("attributes"); //this is how I _evaluate_ the isRequired attribute of the "attributes" property of the "measures"
vizModel.get("measures").isRequired("attributes"); //robust variant of the previous case
vizModel.get("measures").countRange("attributes"); // {min:0, max: Infinity} isRequired -> return min > 0 // most general variant
vizModel.countRange("measures") == {min:0, max:1} -> we can set vizModel.measures = null, but we shouldn't do that
// vizModel.measures is a visual role mapping, a derivative of complex
To iterate over all possible attributes of the `attributes` property
vizModel.attributes.count -> number of properties defined
vizModel.attributes.at(k) -> property at the position k
vizModel.attributes.each(function(value, idx), context) -> iterate just like [].forEach
*/
},
ordinal: 7// an attribute of the "measures" property
// isBrowsable:
// isReadOnly:
// isApplicable:
// but not isRequired -> this is a calculated attribute
// Create a non-reusable attribute for this property
// get isXpto() { //we can access this from vizModel.type.get("measures").isXpto (there is no getter sugar on vizModel.type)
// return false;
// }
},
{
name: "labelsOption",
type: {
base: labelsOptionFactory,
domain: ["none", "outside", "inside"]
},
isRequired: true,
value: "outside"
}
]
}
})
.implement({type: settingsMultiChartType})
.implement({type: bundle.structured["settingsMultiChart"]})
.implement({type: bundle.structured["pie"]});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment