AntV Pie Chart Plot Click event referring to the initial state variable value , not accessing the updated state value - antv

import React, { useState } from 'react';
import 'antd/dist/antd.css';
import { Select, Button } from 'antd';
import { Pie } from '#ant-design/plots';
export default function App() {
const [selectedInputValue, setSelectValue] = useState('lucy');
const [pieChartData, setPieChartData] = useState([
{ type: 'lucy-1', value: 12 },
{ type: 'lucy-2', value: 13 },
{ type: 'lucy-4', value: 2 },
{ type: 'lucy-3', value: 6 },
]);
const config = {
appendPadding: 10,
data: pieChartData,
angleField: 'value',
colorField: 'type',
radius: 0.75,
label: {
type: 'spider',
labelHeight: 28,
content: '{name}\n{percentage}',
},
legend: {
display: true,
},
interactions: [
{
type: 'element-selected',
},
{
type: 'element-active',
},
],
onReady: (plot) => {
plot.on('element:click', (...args) => {
console.log(selectedInputValue);
updateChartValue();
});
},
};
const updateChartValue = () => {
if (selectedInputValue === 'lucy') {
const data = [
{ type: 'lucy-1', value: 12 },
{ type: 'lucy-2', value: 13 },
{ type: 'lucy-4', value: 2 },
{ type: 'lucy-3', value: 6 },
];
setPieChartData(data);
} else if (selectedInputValue === 'jack') {
const data = [
{ type: 'jack-1', value: 12 },
{ type: 'jack-2', value: 13 },
{ type: 'jack-4', value: 2 },
{ type: 'jack-3', value: 6 },
];
setPieChartData(data);
} else if (selectedInputValue === 'Yiminghe') {
const data = [
{ type: 'Yiminghe-1', value: 12 },
{ type: 'Yiminghe-2', value: 13 },
{ type: 'Yiminghe-4', value: 2 },
{ type: 'Yiminghe-3', value: 6 },
];
setPieChartData(data);
} else {
const data = [
{ type: 'dummy-1', value: 12 },
{ type: 'dummy-2', value: 13 },
{ type: 'dummy-4', value: 2 },
{ type: 'dummy-3', value: 6 },
];
setPieChartData(data);
}
};
const handleChange = (value) => {
setSelectValue(value);
sdddd = value;
};
return (
<div id="chart">
<Select
value={selectedInputValue}
style={{
width: 120,
marginLeft: '12px',
marginTop: '12px',
}}
onChange={handleChange}
>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
<Option value="Yiminghe">yiminghe</Option>
<Option value="Dummy">Dummy</Option>
</Select>
<Pie {...config} />
<Button onClick={updateChartValue}>Load Data </Button>
</div>
);
}
The variable pieChartData should get loaded based on selectedInputValue when performing the plot.on("element:click") event. But, On the pie chart element click, the state variable selectedInputValue holds the initialized value only.
Other places outside the events of the charts are all able to access the new updated value for selectedInputValue.
Any thoughts on this?

Related

Cubejs Access Other Cubes By Variable

Given the following Cube, I can use a function to create dynamic measures.
cube(`Creatives`, {
sql: `SELECT * FROM public.creatives`,
joins: {
Events: {
relationship: `hasMany`,
sql: `${Events}.creative_id = ${CUBE}.id`,
},
},
measures: {
...['impression'].reduce((all, event) => {
return {
...all,
[`Total_${event}_events`]: {
type: `count`,
title: `Total ${event} events`,
filters: [
{
sql: `${Events.type} = '${event}'`,
},
],
},
};
}, {}),
},
dimensions: {
...
},
});
But when I try to move the reducer to a function, similar to the examples I get
ReferenceEvents is not defined
Which obviously is because there's no variable within the scope of my function, where previously Cubes interpolation of the string was replacing it for me.
How can I get access to other Cubes in functions similar to the below? I.e. get (or pass in Events to createTotalEventsMeasure()
const createTotalEventsMeasure = (event) => ({
[`Total_${event}_events`]: {
type: `count`,
title: `Total ${event} events`,
filters: [
{
sql: (CUBE) => `${Events.type} = '${event}'`,
},
],
},
});
cube(`Creatives`, {
sql: `SELECT * FROM public.creatives`,
joins: {
Events: {
relationship: `hasMany`,
sql: `${Events}.creative_id = ${CUBE}.id`,
},
},
measures: {
...['impression'].reduce(
(all, event) => ({
...all,
...createTotalEventsMeasure(event),
}),
{}
),
},
dimensions: {
...
},
});

How to programmatically collapse raddataform "Groups" in Nativescript-vue

I'm trying to make use of the RadDataForm using NativeScript-Vue to develop a relatively long form.
My form elements are being defined and grouped programmatically via json. I would like to have the groups start in a minimized / collapsed state for the user experience.
The NativeScript-Vue docs for this feature are very sparse. Angular documentation is deeper so I went there for help, but clicking thru to the "collapsed" API reference results in a 404 from this page.
I'm running it from the Playground to test functionality using the following code:
<template>
<Page class="page">
<ActionBar title="Home" class="action-bar">
<ActionItem icon="font://" class="fa" />
<ActionItem icon="font://\uf07a" class="fa" />
</ActionBar>
<RadDataForm :source="person" :metadata="groupMetaData"
#groupUpdate="onGroupUpdate" />
</Page>
</template>
<script>
import Vue from "nativescript-vue";
import RadDataForm from "nativescript-ui-dataform/vue";
Vue.use(RadDataForm);
export default {
data() {
return {
person: {
name: "John",
age: 23,
email: "john#company.com",
city: "New York",
street: "5th Avenue",
streetNumber: 11
},
groupMetaData: {
// propertyGroup: [{
// "Address": {
// 'collapsed' = true,
// },
// // {
// // "Main Info": 'collapsed',
// }
// ],
propertyAnnotations: [{
name: "city",
index: 3,
groupName: "Address",
editor: "Picker",
valuesProvider: [
"New York",
"Washington",
"Los Angeles"
]
},
{
name: "street",
index: 4,
groupName: "Address"
},
{
name: "streetNumber",
index: 5,
editor: "Number",
groupName: "Address"
},
{
name: "age",
index: 1,
editor: "Number",
groupName: "Main Info"
},
{
name: "email",
index: 2,
editor: "Email",
groupName: "Main Info"
},
{
name: "name",
index: 0,
groupName: "Main Info"
}
]
}
};
},
methods: {
onGroupUpdate: function(args) {
let nativeGroup = args.group;
if (args.ios) {
nativeGroup.collapsible = true;
// nativeGroup.collapsed = true;
} else {
nativeGroup.setExpandable(true);
// nativeGroup.collapsed;
// nativeGroup.collapsed(true);
// nativeGroup.collapsed;
}
// console.log(JSON.stringify(nativeGroup));
}
}
};
</script>
<style scoped>
.home-panel {
vertical-align: center;
font-size: 20;
margin: 15;
}
.description-label {
margin-bottom: 15;
}
</style>
My assumption was to address this in the OnGroupUpdate method, but I'm not getting where I need to be (you can see a few attempts that are commented out).
The goal is to have this view load with minimized groups so that the user can expand the different form groups that s/he wishes to work on in sequence.
Playground link: https://play.nativescript.org/?id=XLKFoC&template=play-vue&v=14
Thanks for any help
I think what you actually need is nativeGroup.setIsExpanded(false);
exports.onGroupUpdate = (args) => {
if (app.ios) {
let nativeGroup = args.group;
nativeGroup.collapsible = true;
} else {
let nativeGroup = args.group;
nativeGroup.setExpandable(true);
//in this example i only expand one group.
if (args.groupName !== "SERVICE INFORMATION") {
nativeGroup.setIsExpanded(false)
}
}
}

Vue.js Change placeholder in template dynamically

I want change the placeholder in a template dynamically over the input of a textbox but it not work after change the value. Initial it work perfect.
Demo
https://jsfiddle.net/he4gx40g/
Update: Working example thanks #Roy J
https://jsfiddle.net/z3gbk0L2/
Example of the component (without the textbox logic)
<customValueComponent :item="config" :value="'ConfigValue1'" />
Code of the customValue component
customValueComponent: {
props: {
item: {
type: Object,
required: true
},
value: {
type: String,
required: true
}
},
watch: {
value: function (newVal, oldVal) { // watch it
console.log('Prop changed: ', newVal, ' | was: ', oldVal)
this.$options.template = '<div>{{ item.' + this.value + '}}</div>';
}
},
created: function () {
this.$options.template = '<div>{{ item.' + this.value + '}}</div>';
},
template: ''
}
Object
var config =
{
ConfigValue1: "Titanium",
ConfigValue2: "Gold",
ConfigValue3: "Silver",
ConfigValue4: "Bronze",
ConfigValue5: "Copper",
...
};
$options is read-only. This is not how you change values in a template. Vue updates values as they change. Your component definition should be
Vue.component('customvalue-component', {
props: {
item: {
type: Object,
required: true
},
value: {
type: String,
required: true,
}
},
template: '<div>{{value}}</div>'
});
And your binding on the component should be
<customvalue-component :item="config" :value="config[value1]" />

kendo pivot grid rowheadertemplate

I have a kendo pivot grid defined in this way:
<div kendo-pivot-grid
id="pivotGrid"
k-excel="{ fileName: reportCtrl.CurrentReport.DS_REPORT + '.xlsx' }"
k-height="'100%'"
k-sortable="true"
k-filterable="true"
k-row-header-template="'#= rowTemplate #'"
kx-data="resultCtrl.ReportResult"
kx-data-source-options="{
data: resultCtrl.ReportResult,
schema: {
fields: {
DT_MEASURE: { type: 'shortDate' }
},
cube: {
dimensions: {
ID_MEASURE_A: { caption: 'Measure A' },
ID_MEASURE_B: { caption: 'Measure B' },
},
measures: {
'AverageA': { field: 'ID_MEASURE_A', aggregate: 'average' },
'AverageB': { field: 'ID_MEASURE_B', aggregate: 'average' }
}
},
},
columns: [
{ name: 'ID_PRODUCT', expand: true }
],
rows: [
{ name: 'DT_MEASURE', expand: true },
],
measures: ['AverageA', 'AverageB']
}"
kx-vertical-stretch="true">
</div>
And here the script rowTemplate:
<script id="rowTemplate" type="text/x-kendo-template">
# if (member.name.indexOf("DT_MEASURE") === 0 && member.name !== "DT_MEASURE") { #
#: kendo.toString(kendo.parseDate(member.caption), "dd-MM-yyyy") #
# } else { #
#: member.caption.toString() #
# } #
</script>
I want to define my rowHeaderTemplate to show the correct format of a date but every attempt to do it doesn't work.
Any suggestion?

Unable to add radio buttons to Kendo UI grid

I'm trying to have a group of 3 radio buttons (each button in different column but the same row) in my Kendo grid but without success. I looked at the Kendo RowTemplate doc, but it's not directing me to any solution.
it works fine with checkboxes, but when i change the template to "radio" type, it changes to checkbox the second I click the edit button. any thoughts?
below is my kendoGrid properties, I put ** next to the 'template' line in the field property.
div.kendoGrid({
dataSource:
{ error: function (e) {
alert("An error occured: "+ e.xhr.responseText);
this.cancelChanges();
},
type:"json",
transport: {
read: {
url: "/users/read",
cache: false,
dataType: "json"
},
update: {
url: function(user){
var grid = $("#grid").data("kendoGrid");
var model = grid.dataItem(grid.select());
var roleIs;
if (user.Admin) {
roleIs="admin"
}
else if (user.Manager) {
roleIs="manager"
}
else if (user.User) {
roleIs="user"
};
return "users/update/"+model.id+"/"+roleIs+"/"+user.name
},
type: "PUT"
},
destroy: {
url: function(user){
return "/users/destroy/"+user.id+"/"+user.name
},
type: "DELETE"
},
create: {
url: function(user){
var roleIs;
if (user.Admin) {
roleIs="admin"
}
else if (user.Manager) {
roleIs="manager"
}
else if (user.User) {
roleIs="user"
};
return "users/create/"+user.login+"/"+user.name+"/"+roleIs+"/"
},
type: "POST"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
schema: {
model:
{ id: "id",
fields: {
id:{ type: "number",editable: false},
role:{ type: "string"},
login: { type: "string",editable: false},
name:{type: "string",editable: false},
Admin: { type: "boolean"},
Manager: { type: "boolean"},
User: { type: "boolean"}
}
}
},
pageSize: 30,
serverPaging: false,
serverFiltering: false,
serverSorting: false
},
selectable: "row",
navigatable: true,
pageable: true,
height: 400,
columns: [//{field: "id"},
{
field: "name",
title:"User Name",
filterable: true,
nullable: false,
editable: false
},{
field: "Admin",
**template: '<input type="checkbox" #= Admin ? "checked=checked" : "" # disabled="disabled"></input>'**,
width: 75
},{
field: "Manager",
**template: '<input type="checkbox" #= Manager ? "checked=checked" : "" # disabled="disabled"></input>'**,
width: 75
},{
field: "User",
**template: '<input type="checkbox" #= User ? "checked=checked" : "" # disabled="disabled"></input>',**
width: 75
},{
command: ["edit", "destroy"], title: "", width: "195px"
}],
editable:{mode: "inline"}
});
}
}
}
The formatting for edition is controlled by columns.editor
You need to write an editor function that defines the input as a radio button.