-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce EditorConfigProvider to customize vis editor #20519
Changes from 12 commits
c14cfe8
c8d2e30
a54e820
6b45b70
a3c4c8e
31bd9e3
5b3eeed
84a66eb
a44b1b5
7302f58
f235685
d8137b1
0bef613
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,55 +46,60 @@ export default function AggParamWriterHelper(Private) { | |
* @param {object} opts - describe the properties of this paramWriter | ||
* @param {string} opts.aggType - the name of the aggType we want to test. ('histogram', 'filter', etc.) | ||
*/ | ||
function AggParamWriter(opts) { | ||
const self = this; | ||
class AggParamWriter { | ||
|
||
self.aggType = opts.aggType; | ||
if (_.isString(self.aggType)) { | ||
self.aggType = aggTypes.byName[self.aggType]; | ||
} | ||
constructor(opts) { | ||
const self = this; | ||
|
||
// not configurable right now, but totally required | ||
self.indexPattern = stubbedLogstashIndexPattern; | ||
self.aggType = opts.aggType; | ||
if (_.isString(self.aggType)) { | ||
self.aggType = aggTypes.byName[self.aggType]; | ||
} | ||
|
||
// the schema that the aggType satisfies | ||
self.visAggSchema = null; | ||
// not configurable right now, but totally required | ||
self.indexPattern = stubbedLogstashIndexPattern; | ||
|
||
self.vis = new Vis(self.indexPattern, { | ||
type: 'histogram', | ||
aggs: [{ | ||
id: 1, | ||
type: self.aggType.name, | ||
params: {} | ||
}] | ||
}); | ||
} | ||
// the schema that the aggType satisfies | ||
self.visAggSchema = null; | ||
|
||
self.vis = new Vis(self.indexPattern, { | ||
type: 'histogram', | ||
aggs: [{ | ||
id: 1, | ||
type: self.aggType.name, | ||
params: {} | ||
}] | ||
}); | ||
} | ||
|
||
AggParamWriter.prototype.write = function (paramValues) { | ||
const self = this; | ||
paramValues = _.clone(paramValues); | ||
write(paramValues, modifyAggConfig = null) { | ||
const self = this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
paramValues = _.clone(paramValues); | ||
|
||
if (self.aggType.params.byName.field && !paramValues.field) { | ||
// pick a field rather than force a field to be specified everywhere | ||
if (self.aggType.type === 'metrics') { | ||
paramValues.field = _.sample(self.indexPattern.fields.byType.number); | ||
} else { | ||
const type = self.aggType.params.byName.field.filterFieldTypes || 'string'; | ||
let field; | ||
do { | ||
field = _.sample(self.indexPattern.fields.byType[type]); | ||
} while (!field.aggregatable); | ||
paramValues.field = field.name; | ||
if (self.aggType.params.byName.field && !paramValues.field) { | ||
// pick a field rather than force a field to be specified everywhere | ||
if (self.aggType.type === 'metrics') { | ||
paramValues.field = _.sample(self.indexPattern.fields.byType.number); | ||
} else { | ||
const type = self.aggType.params.byName.field.filterFieldTypes || 'string'; | ||
let field; | ||
do { | ||
field = _.sample(self.indexPattern.fields.byType[type]); | ||
} while (!field.aggregatable); | ||
paramValues.field = field.name; | ||
} | ||
} | ||
} | ||
|
||
const aggConfig = self.vis.aggs[0]; | ||
aggConfig.setParams(paramValues); | ||
|
||
const aggConfig = self.vis.aggs[0]; | ||
aggConfig.setParams(paramValues); | ||
if (modifyAggConfig) { | ||
modifyAggConfig(aggConfig); | ||
} | ||
|
||
return aggConfig.write(self.vis.aggs); | ||
}; | ||
return aggConfig.write(self.vis.aggs); | ||
} | ||
} | ||
|
||
return AggParamWriter; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,15 @@ export const histogramBucketAgg = new BucketAggType({ | |
name: 'field', | ||
filterFieldTypes: 'number' | ||
}, | ||
|
||
{ | ||
/* | ||
* This parameter can be set if you want the auto scaled interval to always | ||
* be a multiple of a specific base. | ||
*/ | ||
name: 'intervalBase', | ||
default: null, | ||
write: () => {}, | ||
This comment was marked as resolved.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an explicit test for that |
||
}, | ||
{ | ||
name: 'interval', | ||
editor: intervalTemplate, | ||
|
@@ -111,6 +119,17 @@ export const histogramBucketAgg = new BucketAggType({ | |
} | ||
} | ||
|
||
const base = aggConfig.params.intervalBase; | ||
if (base) { | ||
if (interval < base) { | ||
// In case the specified interval is below the base, just increase it to it's base | ||
interval = base; | ||
} else if (interval % base !== 0) { | ||
// In case the interval is not a multiple of the base round it to the next base | ||
interval = Math.round(interval / base) * base; | ||
} | ||
} | ||
|
||
output.params.interval = interval; | ||
} | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,15 @@ | |
position="'right'" | ||
content="'Interval will be automatically scaled in the event that the provided value creates more buckets than specified by Advanced Setting\'s histogram:maxBars'" | ||
></icon-tip> | ||
|
||
<icon-tip | ||
ng-if="editorConfig.interval.warning" | ||
position="'right'" | ||
content="editorConfig.interval.warning" | ||
type="'alert'" | ||
color="'warning'" | ||
style="float: right" | ||
></icon-tip> | ||
</label> | ||
<input | ||
id="visEditorInterval{{agg.id}}" | ||
|
@@ -14,7 +23,8 @@ | |
type="number" | ||
class="form-control" | ||
name="interval" | ||
min="0" | ||
min="{{editorConfig.interval.base || 0}}" | ||
step="{{editorConfig.interval.base}}" | ||
This comment was marked as resolved.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I have editor hints still on the list, but wanted to pull it into a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually still added it to this PR. |
||
input-number | ||
> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get rid of self