Open rufuspollock opened 3 years ago
LineChart
component can fetch and load data from a provided URL.Default to Temporal Type for X Axis:
xAxisType
defaults to 'temporal'
when not explicitly provided.Use Table Schema Information if Present:
data
prop to configure the chart appropriately.Auto Display All Series:
fold
transform to convert multiple columns into a single column for visualization.xAxisType
was not explicitly set to a default value, potentially requiring users to specify it every time.xAxisType
now defaults to 'temporal'
, providing a sensible default for time-based data and simplifying the component’s usage.Code Example:
export function LineChart({
data,
title = '',
xAxis,
xAxisType = 'temporal', // Default to 'temporal'
xAxisTimeUnit = 'year',
yAxis,
yAxisType = 'quantitative',
}: LineChartProps) {
// Component logic...
}
Transform:
fold
transform to handle multiple data columns and enable automatic legend creation.Color Encoding:
key
field to distinguish between multiple series in the chart.const spec = {
$schema: 'https://vega.github.io/schema/vega-lite/v5.json',
title,
width: 'container',
height: 300,
transform: values && values[0] && Object.keys(values[0]).length > 2
? [{ fold: Object.keys(values[0]).filter(key => key !== xAxis && key !== yAxis) }]
: [], // Adding transform to handle multiple columns
mark: {
type: 'line',
color: 'black',
strokeWidth: 1,
tooltip: true,
},
data: specData,
selection: {
grid: {
type: 'interval',
bind: 'scales',
},
},
encoding: {
x: {
field: xAxis,
timeUnit: xAxisTimeUnit,
type: xAxisType,
},
y: {
field: yAxis,
type: yAxisType,
},
color: values && values[0] && Object.keys(values[0]).length > 2
? { field: 'key', type: 'nominal' } // Added color encoding for multiple series
: undefined,
},
} as any;
cc @olayway @rufuspollock
@gradedSystem
Original: The xAxisType was not explicitly set to a default value, potentially requiring users to specify it every time.
But it already defaults to temporal:
Action Required: Implement functionality to utilize schema information from the
data
prop to configure the chart appropriately.
data
prop serves different purpose in our portaljs components. Also, are you sure you understand this item provided in the description?
- Possible configuration of LineChart component of spec object for a Vega-Lite:
I think this is related to the 3rd point, not the second?
- Possible configuration of LineChart component of spec object for a Vega-Lite:
I think this is related to the 3rd point, not the second?
Yeah That's Right
@gradedSystem Can you please replace the full spec example with only the parts that you're changing? And use ...
for the parts that you're not changing/adding.
Using the fold transform to convert multiple columns into a single column for visualization.
Converting columns into a single column? What does it mean?
Can you please replace the full spec example with only the parts that you're changing? And use
...
for the parts that you're not changing/adding.
Here are the specs:
const spec = {
...,
transform: values && values[0] && Object.keys(values[0]).length > 2
? [{ fold: Object.keys(values[0]).filter(key => key !== xAxis && key !== yAxis) }]
: [], // Adding transform to handle multiple columns
...,
encoding: {
...,
color: values && values[0] && Object.keys(values[0]).length > 2
? { field: 'key', type: 'nominal' } // Added color encoding for multiple series
: undefined,
},
...
} as any;
Using the fold transform to convert multiple columns into a single column for visualization.
Converting columns into a single column? What does it mean?
Folding turns many columns into two: one for labels, one for values, making it easier to visualize
Yes, it supports loading from a URL. See the implementation here.
The X-axis defaults to the temporal type. You can see it here here
It uses the table schema if I understood it correctly here and it also says that the format: { type: 'csv' }
which matches the format here Vega supported format or also it could be the supported data types quantitative | temporal which Vega supports :
From Vega Official Website: If a field is specified, the channel definition must describe the encoded data’s type based on their level of measurement. The supported data types are: "quantitative", "temporal", "ordinal", "nominal", and "geojson".
Here I believe it mentions the legends to display all the series which uses this structure:
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "value", "type": "quantitative"},
"color": {"field": "key", "type": "nominal"}
}
which we do not currently support and it could be added to the spec like this:
const spec = {
...,
encoding: {
...,
color: values && values[0] && Object.keys(values[0]).length > 2
? { field: 'key', type: 'nominal' } // Added color encoding for multiple series
: undefined,
},
...
} as any;
cc @olayway
It uses the table schema if I understood it correctly here
I don't think this is the case. Look at what props does this component take in. There is no option to pass a full spec. The spec is generated within the component here, and only uses xAxis, yAxis and a bunch of other props passed to it. But I think allowing to pass a full spec is a no-go. If sb needs to pass a full spec, then he/she should just use VegaLite or Vega for this, as LineChart is just a simple wrapper around VegaLite, with easy to use but very basic interface.
Auto Display All Series â•
Cool, let's do this!
Currently testing LineChart
component locally it looks something like this:
Things to Note:
key
.For scenarios with multiple y-values, should a specific yAxis
value be included? Currently, my approach is to fold all y-values except the xAxis
. If no yAxis
is provided, if provided then I make that only that value to be displayed:
@olayway
@gradedSystem
When dealing with multiple y-values, is it necessary to specify a legend title? In the current implementation, I have used the default title key.
Yes.
For scenarios with multiple y-values, should a specific yAxis value be included? Currently, my approach is to fold all y-values except the xAxis. If no yAxis is provided, if provided then I make that only that value to be displayed:
I'm sorry, I don't understand the question.
@olayway What is meant here on the second question is that for example I can make it go like this:
<LineChart
data = {{url.csv}}
xAxis = "something"
yAxis // skip this one and it will pick up all the values instead of xAxis so it will show all the values
>
like here:
We already have a LineChart component.
LineChart supports
[ ] uses table schema info if present ...wontfix; if sb needs to pass a full spec then just use VegaLite component directly (LineChart is just a simple wrapper around it with easy to use but very basic interface)